{"version":3,"file":"handle-deleted-ct-in-workflows.mjs","sources":["../../../server/src/migrations/handle-deleted-ct-in-workflows.ts"],"sourcesContent":["import { difference, keys } from 'lodash/fp';\nimport { async } from '@strapi/utils';\nimport { WORKFLOW_MODEL_UID } from '../constants/workflows';\nimport { getWorkflowContentTypeFilter } from '../utils/review-workflows';\n\n/**\n * Remove CT references from workflows if the CT is deleted\n */\nasync function migrateDeletedCTInWorkflows({ oldContentTypes, contentTypes }: any) {\n const deletedContentTypes = difference(keys(oldContentTypes), keys(contentTypes)) ?? [];\n\n if (deletedContentTypes.length) {\n await async.map(deletedContentTypes, async (deletedContentTypeUID: unknown) => {\n const workflow = await strapi.db.query(WORKFLOW_MODEL_UID).findOne({\n select: ['id', 'contentTypes'],\n where: {\n contentTypes: getWorkflowContentTypeFilter({ strapi }, deletedContentTypeUID),\n },\n });\n\n if (workflow) {\n await strapi.db.query(WORKFLOW_MODEL_UID).update({\n where: { id: workflow.id },\n data: {\n contentTypes: workflow.contentTypes.filter(\n (contentTypeUID: unknown) => contentTypeUID !== deletedContentTypeUID\n ),\n },\n });\n }\n });\n }\n}\n\nexport default migrateDeletedCTInWorkflows;\n"],"names":["migrateDeletedCTInWorkflows","oldContentTypes","contentTypes","deletedContentTypes","difference","keys","length","async","map","deletedContentTypeUID","workflow","strapi","db","query","WORKFLOW_MODEL_UID","findOne","select","where","getWorkflowContentTypeFilter","update","id","data","filter","contentTypeUID"],"mappings":";;;;;AAKA;;AAEC,IACD,eAAeA,2BAA4B,CAAA,EAAEC,eAAe,EAAEC,YAAY,EAAO,EAAA;AAC/E,IAAA,MAAMC,sBAAsBC,UAAWC,CAAAA,IAAAA,CAAKJ,eAAkBI,CAAAA,EAAAA,IAAAA,CAAKH,kBAAkB,EAAE;IAEvF,IAAIC,mBAAAA,CAAoBG,MAAM,EAAE;AAC9B,QAAA,MAAMC,KAAMC,CAAAA,GAAG,CAACL,mBAAAA,EAAqB,OAAOM,qBAAAA,GAAAA;YAC1C,MAAMC,QAAAA,GAAW,MAAMC,MAAOC,CAAAA,EAAE,CAACC,KAAK,CAACC,kBAAoBC,CAAAA,CAAAA,OAAO,CAAC;gBACjEC,MAAQ,EAAA;AAAC,oBAAA,IAAA;AAAM,oBAAA;AAAe,iBAAA;gBAC9BC,KAAO,EAAA;AACLf,oBAAAA,YAAAA,EAAcgB,4BAA6B,CAAA;AAAEP,wBAAAA;qBAAUF,EAAAA,qBAAAA;AACzD;AACF,aAAA,CAAA;AAEA,YAAA,IAAIC,QAAU,EAAA;AACZ,gBAAA,MAAMC,OAAOC,EAAE,CAACC,KAAK,CAACC,kBAAAA,CAAAA,CAAoBK,MAAM,CAAC;oBAC/CF,KAAO,EAAA;AAAEG,wBAAAA,EAAAA,EAAIV,SAASU;AAAG,qBAAA;oBACzBC,IAAM,EAAA;AACJnB,wBAAAA,YAAAA,EAAcQ,SAASR,YAAY,CAACoB,MAAM,CACxC,CAACC,iBAA4BA,cAAmBd,KAAAA,qBAAAA;AAEpD;AACF,iBAAA,CAAA;AACF;AACF,SAAA,CAAA;AACF;AACF;;;;"}