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.76 kB
{"version":3,"file":"cleanup-failed-create.mjs","names":["documentWorkflowServices.deleteForDocuments"],"sources":["../../../../src/services/documents/helpers/cleanup-failed-create.ts"],"sourcesContent":["import type { LucidDocumentTableName } from \"../../../libs/db/types.js\";\nimport logger from \"../../../libs/logger/index.js\";\nimport { DocumentsRepository } from \"../../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\nimport { documentWorkflowServices } from \"../../index.js\";\n\nconst cleanupFailedCreate: ServiceFn<\n\t[\n\t\t{\n\t\t\tcollectionKey: string;\n\t\t\tdocumentId: number;\n\t\t\ttableName: LucidDocumentTableName;\n\t\t},\n\t],\n\tundefined\n> = async (context, data) => {\n\tif (context.db.client.isTransaction) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst Documents = new DocumentsRepository(\n\t\tcontext.db.client,\n\t\tcontext.config.db,\n\t);\n\tconst [deleteWorkflowRes, deleteDocumentRes] = await Promise.all([\n\t\tdocumentWorkflowServices.deleteForDocuments(context, {\n\t\t\tcollectionKey: data.collectionKey,\n\t\t\tdocumentIds: [data.documentId],\n\t\t}),\n\t\tDocuments.deleteSingle(\n\t\t\t{\n\t\t\t\twhere: [\n\t\t\t\t\t{\n\t\t\t\t\t\tkey: \"id\",\n\t\t\t\t\t\toperator: \"=\",\n\t\t\t\t\t\tvalue: data.documentId,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\ttableName: data.tableName,\n\t\t\t},\n\t\t),\n\t]);\n\n\tif (deleteWorkflowRes.error || deleteDocumentRes.error) {\n\t\tlogger.error({\n\t\t\tmessage: \"Failed to clean up document after creation error\",\n\t\t\tdata: {\n\t\t\t\tcollectionKey: data.collectionKey,\n\t\t\t\tdocumentId: data.documentId,\n\t\t\t\tworkflowCleanupFailed: deleteWorkflowRes.error !== undefined,\n\t\t\t\tdocumentCleanupFailed: deleteDocumentRes.error !== undefined,\n\t\t\t},\n\t\t});\n\t}\n\n\tif (deleteWorkflowRes.error) return deleteWorkflowRes;\n\tif (deleteDocumentRes.error) return deleteDocumentRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default cleanupFailedCreate;\n"],"mappings":"uKAMA,MAAM,EASF,MAAO,EAAS,IAAS,CAC5B,GAAI,EAAQ,GAAG,OAAO,cACrB,MAAO,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,EAGD,IAAM,EAAY,IAAI,EACrB,EAAQ,GAAG,OACX,EAAQ,OAAO,EAChB,EACM,CAAC,EAAmB,GAAqB,MAAM,QAAQ,IAAI,CAChEA,EAA4C,EAAS,CACpD,cAAe,EAAK,cACpB,YAAa,CAAC,EAAK,UAAU,CAC9B,CAAC,EACD,EAAU,aACT,CACC,MAAO,CACN,CACC,IAAK,KACL,SAAU,IACV,MAAO,EAAK,UACb,CACD,CACD,EACA,CACC,UAAW,EAAK,SACjB,CACD,CACD,CAAC,EAiBD,OAfI,EAAkB,OAAS,EAAkB,QAChD,EAAO,MAAM,CACZ,QAAS,mDACT,KAAM,CACL,cAAe,EAAK,cACpB,WAAY,EAAK,WACjB,sBAAuB,EAAkB,QAAU,IAAA,GACnD,sBAAuB,EAAkB,QAAU,IAAA,EACpD,CACD,CAAC,EAGE,EAAkB,MAAc,EAChC,EAAkB,MAAc,EAE7B,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,CACD"}