From 2e045217ec82d593b445da65b02b8751c10dbd1f Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Thu, 28 Apr 2022 00:17:15 +0500 Subject: [PATCH] fix: Fix application crash after deleting project --- server/api/helpers/projects/delete-one.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/api/helpers/projects/delete-one.js b/server/api/helpers/projects/delete-one.js index 39c832dfd..76a453c49 100644 --- a/server/api/helpers/projects/delete-one.js +++ b/server/api/helpers/projects/delete-one.js @@ -10,6 +10,12 @@ module.exports = { }, async fn(inputs) { + const boardIds = await sails.helpers.projects.getBoardIds(inputs.record.id); + + await BoardMembership.destroy({ + boardId: boardIds, + }).fetch(); + const projectManagers = await ProjectManager.destroy({ projectId: inputs.record.id, }).fetch(); @@ -19,14 +25,14 @@ module.exports = { if (project) { const managerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId'); - const boardIds = await sails.helpers.projects.getBoardIds(project.id); - const boardRooms = boardIds.map((boardId) => `board:${boardId}`); - const memberUserIds = await sails.helpers.boards.getMemberUserIds(boardIds); const userIds = _.union(managerUserIds, memberUserIds); userIds.forEach((userId) => { - sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms); + sails.sockets.removeRoomMembersFromRooms( + `user:${userId}`, + boardIds.map((boardId) => `board:${boardId}`), + ); sails.sockets.broadcast( `user:${userId}`,