UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.24 kB
{"version":3,"file":"clear-expired-locales.mjs","names":[],"sources":["../../../src/services/crons/clear-expired-locales.ts"],"sourcesContent":["import { LocalesRepository } from \"../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\nimport getRetentionDays from \"./helpers/get-retention-days.js\";\n\n/**\n * Finds all expired locales and queues them for deletion\n */\nconst clearExpiredLocales: ServiceFn<[], undefined> = async (context) => {\n\tconst Locales = new LocalesRepository(context.db.client, context.config.db);\n\n\tconst compDate = getRetentionDays(context.config.retention, \"removedLocales\");\n\n\tconst expiredLocalesRes = await Locales.selectMultiple({\n\t\tselect: [\"code\"],\n\t\twhere: [\n\t\t\t{\n\t\t\t\tkey: \"is_deleted_at\",\n\t\t\t\toperator: \"<\",\n\t\t\t\tvalue: compDate,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"is_deleted\",\n\t\t\t\toperator: \"=\",\n\t\t\t\tvalue: context.config.db.getDefault(\"boolean\", \"true\"),\n\t\t\t},\n\t\t],\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t},\n\t});\n\tif (expiredLocalesRes.error) return expiredLocalesRes;\n\n\tif (expiredLocalesRes.data.length === 0) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst queueRes = await context.queue.addBatch(context, {\n\t\tevent: \"locales:delete\",\n\t\tpayloads: expiredLocalesRes.data.map((locale) => ({\n\t\t\tlocaleCode: locale.code,\n\t\t})),\n\t});\n\tif (queueRes.error) return queueRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default clearExpiredLocales;\n"],"mappings":"mGAOA,MAAM,EAAgD,KAAO,IAAY,CACxE,IAAM,EAAU,IAAI,EAAkB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAAE,EAEpE,EAAW,EAAiB,EAAQ,OAAO,UAAW,gBAAgB,EAEtE,EAAoB,MAAM,EAAQ,eAAe,CACtD,OAAQ,CAAC,MAAM,EACf,MAAO,CACN,CACC,IAAK,gBACL,SAAU,IACV,MAAO,CACR,EACA,CACC,IAAK,aACL,SAAU,IACV,MAAO,EAAQ,OAAO,GAAG,WAAW,UAAW,MAAM,CACtD,CACD,EACA,WAAY,CACX,QAAS,EACV,CACD,CAAC,EACD,GAAI,EAAkB,MAAO,OAAO,EAEpC,GAAI,EAAkB,KAAK,SAAW,EACrC,MAAO,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,EAGD,IAAM,EAAW,MAAM,EAAQ,MAAM,SAAS,EAAS,CACtD,MAAO,iBACP,SAAU,EAAkB,KAAK,IAAK,IAAY,CACjD,WAAY,EAAO,IACpB,EAAE,CACH,CAAC,EAGD,OAFI,EAAS,MAAc,EAEpB,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,CACD"}