UNPKG

@payloadcms/plugin-import-export

Version:

Import-Export plugin for Payload

43 lines (42 loc) 1.36 kB
import { createExport } from './createExport.js'; import { getFields } from './getFields.js'; export const getCreateCollectionExportTask = (config, pluginConfig)=>{ const inputSchema = getFields(config, pluginConfig).concat({ name: 'user', type: 'text' }, { name: 'userCollection', type: 'text' }, { name: 'exportsCollection', type: 'text' }); return { slug: 'createCollectionExport', handler: async ({ input, req })=>{ let user; if (input.userCollection && input.user) { user = await req.payload.findByID({ id: input.user, collection: input.userCollection }); req.user = user; } if (!user) { throw new Error('User not found'); } // Strip out user and userCollection from input - they're only needed for rehydration const { user: _userId, userCollection: _userCollection, ...exportInput } = input; await createExport({ input: exportInput, req, user }); return { output: {} }; }, inputSchema }; }; //# sourceMappingURL=getCreateExportCollectionTask.js.map