From 529ad1bd250db31399824673276ddaea1bab6939 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Mon, 27 Nov 2023 15:06:25 +0100 Subject: [PATCH] chore: clean frontend migration --- api/src/controllers/migration.js | 27 ----------- dashboard/src/components/DataMigrator.js | 58 ------------------------ 2 files changed, 85 deletions(-) diff --git a/api/src/controllers/migration.js b/api/src/controllers/migration.js index 34c12568a..c1cee14d6 100644 --- a/api/src/controllers/migration.js +++ b/api/src/controllers/migration.js @@ -65,33 +65,6 @@ router.put( // End of example of migration. */ - if (req.params.migrationName === "integrate-comments-in-actions-history") { - try { - z.array(z.string().regex(looseUuidRegex)).parse(req.body.commentIdsToDelete); - z.array( - z.object({ - _id: z.string().regex(looseUuidRegex), - encrypted: z.string(), - encryptedEntityKey: z.string(), - }) - ).parse(req.body.actionsToUpdate); - } catch (e) { - const error = new Error(`Invalid request in integrate-comments-in-actions-history migration: ${e}`); - error.status = 400; - throw error; - } - for (const _id of req.body.commentIdsToDelete) { - await Comment.destroy({ where: { _id, organisation: req.user.organisation }, transaction: tx }); - } - for (const { _id, encrypted, encryptedEntityKey } of req.body.actionsToUpdate) { - await Action.update({ encrypted, encryptedEntityKey }, { where: { _id }, transaction: tx, paranoid: false }); - } - organisation.set({ - migrations: [...(organisation.migrations || []), req.params.migrationName], - migrationLastUpdateAt: new Date(), - }); - } - organisation.set({ migrating: false }); await organisation.save({ transaction: tx }); }); diff --git a/dashboard/src/components/DataMigrator.js b/dashboard/src/components/DataMigrator.js index 3027ce8d0..c5363a504 100644 --- a/dashboard/src/components/DataMigrator.js +++ b/dashboard/src/components/DataMigrator.js @@ -56,64 +56,6 @@ export default function useDataMigrator() { // End of example of migration. */ - if (!organisation.migrations?.includes('integrate-comments-in-actions-history')) { - setLoadingText(LOADING_TEXT); - const comments = await API.get({ - path: '/comment', - query: { organisation: organisationId, after: 0, withDeleted: false }, - }).then((res) => res.decryptedData || []); - const actions = await API.get({ - path: '/action', - query: { organisation: organisationId, after: 0, withDeleted: false }, - }).then((res) => res.decryptedData || []); - - const actionsPerId = {}; - for (const action of actions) { - actionsPerId[action._id] = action; - } - const actionsToUpdate = {}; - const commentIdsToDelete = []; - - for (const comment of comments) { - if (!comment.action) continue; - if (!comment.comment.includes("a changé le status de l'action: ")) continue; - const action = actionsToUpdate[comment.action] ?? actionsPerId[comment.action]; - if (!action) { - commentIdsToDelete.push(comment._id); - continue; - } - if (!action.history) action.history = []; - const statusName = comment.comment.split("a changé le status de l'action: ")[1]; - const statusId = mappedIdsToLabels.find((e) => e.name === statusName)?._id; - action.history.push({ - user: comment.user, - date: comment.createdAt, - data: { - status: { oldValue: '', newValue: statusId }, - }, - }); - actionsToUpdate[comment.action] = action; - commentIdsToDelete.push(comment._id); - } - - const encryptedActionsToUpdate = await Promise.all( - Object.values(actionsToUpdate) - .map((action) => prepareActionForEncryption(action, { checkRequiredFields: false })) - .map(encryptItem) - ); - - const response = await API.put({ - path: `/migration/integrate-comments-in-actions-history`, - body: { commentIdsToDelete, actionsToUpdate: encryptedActionsToUpdate }, - query: { migrationLastUpdateAt }, - }); - if (response.ok) { - setOrganisation(response.organisation); - migrationLastUpdateAt = response.organisation.migrationLastUpdateAt; - } else { - return false; - } - } return true; }, };