Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
4.6 KiB
Plaintext
1 line
4.6 KiB
Plaintext
{"version":3,"sources":["../../../src/versions/schedule/job.ts"],"sourcesContent":["import type { Field } from '../../fields/config/types.js'\nimport type { TypedUser } from '../../index.js'\nimport type { TaskConfig } from '../../queues/config/types/taskTypes.js'\nimport type { SchedulePublishTaskInput } from './types.js'\n\ntype Args = {\n adminUserSlug: string\n collections: string[]\n globals: string[]\n}\n\nexport const getSchedulePublishTask = ({\n adminUserSlug,\n collections,\n globals,\n}: Args): TaskConfig<{ input: SchedulePublishTaskInput; output: object }> => {\n return {\n slug: 'schedulePublish',\n handler: async ({ input, req }) => {\n const _status = input?.type === 'publish' || !input?.type ? 'published' : 'draft'\n\n const userID = input.user\n\n let user: null | TypedUser = null\n\n if (userID) {\n user = (await req.payload.findByID({\n id: userID,\n collection: adminUserSlug,\n depth: 0,\n })) as TypedUser\n\n user.collection = adminUserSlug\n }\n\n let publishSpecificLocale: string\n\n if (input?.type === 'publish' && input.locale && req.payload.config.localization) {\n const matchedLocale = req.payload.config.localization.locales.find(\n ({ code }) => code === input.locale,\n )\n\n if (matchedLocale) {\n publishSpecificLocale = input.locale\n }\n }\n\n if (input.doc) {\n await req.payload.update({\n id: input.doc.value,\n collection: input.doc.relationTo,\n data: {\n _status,\n },\n depth: 0,\n overrideAccess: user === null,\n publishSpecificLocale: publishSpecificLocale!,\n user,\n })\n }\n\n if (input.global) {\n await req.payload.updateGlobal({\n slug: input.global,\n data: {\n _status,\n },\n depth: 0,\n overrideAccess: user === null,\n publishSpecificLocale: publishSpecificLocale!,\n user,\n })\n }\n\n return {\n output: {},\n }\n },\n inputSchema: [\n {\n name: 'type',\n type: 'radio',\n defaultValue: 'publish',\n options: ['publish', 'unpublish'],\n },\n {\n name: 'locale',\n type: 'text',\n },\n ...(collections.length > 0\n ? [\n {\n name: 'doc',\n type: 'relationship',\n relationTo: collections,\n } satisfies Field,\n ]\n : []),\n {\n name: 'global',\n type: 'select',\n options: globals,\n },\n {\n name: 'user',\n type: 'relationship',\n relationTo: adminUserSlug,\n },\n ],\n }\n}\n"],"names":["getSchedulePublishTask","adminUserSlug","collections","globals","slug","handler","input","req","_status","type","userID","user","payload","findByID","id","collection","depth","publishSpecificLocale","locale","config","localization","matchedLocale","locales","find","code","doc","update","value","relationTo","data","overrideAccess","global","updateGlobal","output","inputSchema","name","defaultValue","options","length"],"mappings":"AAWA,OAAO,MAAMA,yBAAyB,CAAC,EACrCC,aAAa,EACbC,WAAW,EACXC,OAAO,EACF;IACL,OAAO;QACLC,MAAM;QACNC,SAAS,OAAO,EAAEC,KAAK,EAAEC,GAAG,EAAE;YAC5B,MAAMC,UAAUF,OAAOG,SAAS,aAAa,CAACH,OAAOG,OAAO,cAAc;YAE1E,MAAMC,SAASJ,MAAMK,IAAI;YAEzB,IAAIA,OAAyB;YAE7B,IAAID,QAAQ;gBACVC,OAAQ,MAAMJ,IAAIK,OAAO,CAACC,QAAQ,CAAC;oBACjCC,IAAIJ;oBACJK,YAAYd;oBACZe,OAAO;gBACT;gBAEAL,KAAKI,UAAU,GAAGd;YACpB;YAEA,IAAIgB;YAEJ,IAAIX,OAAOG,SAAS,aAAaH,MAAMY,MAAM,IAAIX,IAAIK,OAAO,CAACO,MAAM,CAACC,YAAY,EAAE;gBAChF,MAAMC,gBAAgBd,IAAIK,OAAO,CAACO,MAAM,CAACC,YAAY,CAACE,OAAO,CAACC,IAAI,CAChE,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASlB,MAAMY,MAAM;gBAGrC,IAAIG,eAAe;oBACjBJ,wBAAwBX,MAAMY,MAAM;gBACtC;YACF;YA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