Skip to content

Commit

Permalink
chore: clean frontend migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Nov 27, 2023
1 parent 0148825 commit 529ad1b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 85 deletions.
27 changes: 0 additions & 27 deletions api/src/controllers/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
58 changes: 0 additions & 58 deletions dashboard/src/components/DataMigrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
Expand Down

0 comments on commit 529ad1b

Please sign in to comment.