mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 00:03:23 +00:00
Refactor Mailing plugin to improve type safety and ensure CollectionConfig compliance
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { Config } from 'payload'
|
import type {CollectionConfig, Config, Field} from 'payload'
|
||||||
import { MailingPluginConfig, MailingContext } from './types/index.js'
|
import { MailingPluginConfig, MailingContext } from './types/index.js'
|
||||||
import { MailingService } from './services/MailingService.js'
|
import { MailingService } from './services/MailingService.js'
|
||||||
import { createEmailTemplatesCollection } from './collections/EmailTemplates.js'
|
import { createEmailTemplatesCollection } from './collections/EmailTemplates.js'
|
||||||
@@ -29,7 +29,7 @@ export const mailingPlugin = (pluginConfig: MailingPluginConfig) => (config: Con
|
|||||||
...baseTemplatesCollection.access,
|
...baseTemplatesCollection.access,
|
||||||
...templatesOverrides.access,
|
...templatesOverrides.access,
|
||||||
},
|
},
|
||||||
}
|
} satisfies CollectionConfig
|
||||||
|
|
||||||
// Handle emails collection configuration
|
// Handle emails collection configuration
|
||||||
const emailsConfig = pluginConfig.collections?.emails
|
const emailsConfig = pluginConfig.collections?.emails
|
||||||
@@ -51,19 +51,20 @@ export const mailingPlugin = (pluginConfig: MailingPluginConfig) => (config: Con
|
|||||||
...emailsOverrides.access,
|
...emailsOverrides.access,
|
||||||
},
|
},
|
||||||
// Update relationship fields to point to correct templates collection
|
// Update relationship fields to point to correct templates collection
|
||||||
fields: (emailsOverrides.fields || Emails.fields).map((field: any) => {
|
fields: (emailsOverrides.fields || Emails.fields).map((field: Field) => {
|
||||||
if (field &&
|
if (field &&
|
||||||
typeof field === 'object' &&
|
typeof field === 'object' &&
|
||||||
|
'name' in field &&
|
||||||
field.name === 'template' &&
|
field.name === 'template' &&
|
||||||
field.type === 'relationship') {
|
field.type === 'relationship') {
|
||||||
return {
|
return {
|
||||||
...field,
|
...field,
|
||||||
relationTo: templatesSlug,
|
relationTo: templatesSlug,
|
||||||
}
|
} as typeof field
|
||||||
}
|
}
|
||||||
return field
|
return field
|
||||||
}),
|
}),
|
||||||
}
|
} satisfies CollectionConfig
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...config,
|
...config,
|
||||||
|
|||||||
Reference in New Issue
Block a user