Replace type assertions with CollectionSlug for better type safety

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-11 15:14:09 +02:00
parent ada13d27cb
commit 0fa10164bf

View File

@@ -1,4 +1,4 @@
import {EmailAdapter, Payload, SendEmailOptions} from 'payload' import {CollectionSlug, EmailAdapter, Payload, SendEmailOptions} from 'payload'
import { Liquid } from 'liquidjs' import { Liquid } from 'liquidjs'
import { import {
MailingPluginConfig, MailingPluginConfig,
@@ -151,7 +151,7 @@ export class MailingService implements IMailingService {
const currentTime = new Date().toISOString() const currentTime = new Date().toISOString()
const { docs: pendingEmails } = await this.payload.find({ const { docs: pendingEmails } = await this.payload.find({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
where: { where: {
and: [ and: [
{ {
@@ -191,7 +191,7 @@ export class MailingService implements IMailingService {
const retryTime = new Date(Date.now() - retryDelay).toISOString() const retryTime = new Date(Date.now() - retryDelay).toISOString()
const { docs: failedEmails } = await this.payload.find({ const { docs: failedEmails } = await this.payload.find({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
where: { where: {
and: [ and: [
{ {
@@ -231,7 +231,7 @@ export class MailingService implements IMailingService {
async processEmailItem(emailId: string): Promise<void> { async processEmailItem(emailId: string): Promise<void> {
try { try {
await this.payload.update({ await this.payload.update({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
data: { data: {
status: 'processing', status: 'processing',
@@ -240,7 +240,7 @@ export class MailingService implements IMailingService {
}) })
const email = await this.payload.findByID({ const email = await this.payload.findByID({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
depth: 1, depth: 1,
}) as BaseEmailDocument }) as BaseEmailDocument
@@ -305,7 +305,7 @@ export class MailingService implements IMailingService {
await this.payload.email.sendEmail(mailOptions) await this.payload.email.sendEmail(mailOptions)
await this.payload.update({ await this.payload.update({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
data: { data: {
status: 'sent', status: 'sent',
@@ -319,7 +319,7 @@ export class MailingService implements IMailingService {
const maxAttempts = this.config.retryAttempts || 3 const maxAttempts = this.config.retryAttempts || 3
await this.payload.update({ await this.payload.update({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
data: { data: {
status: attempts >= maxAttempts ? 'failed' : 'pending', status: attempts >= maxAttempts ? 'failed' : 'pending',
@@ -336,14 +336,14 @@ export class MailingService implements IMailingService {
private async incrementAttempts(emailId: string): Promise<number> { private async incrementAttempts(emailId: string): Promise<number> {
const email = await this.payload.findByID({ const email = await this.payload.findByID({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
}) })
const newAttempts = ((email as any).attempts || 0) + 1 const newAttempts = ((email as any).attempts || 0) + 1
await this.payload.update({ await this.payload.update({
collection: this.emailsCollection as any, collection: this.emailsCollection as CollectionSlug,
id: emailId, id: emailId,
data: { data: {
attempts: newAttempts, attempts: newAttempts,