Skip to content

Commit

Permalink
fix: Fix application crash after deleting project
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Apr 27, 2022
1 parent 36e4bef commit 2e04521
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/api/helpers/projects/delete-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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}`,
Expand Down

0 comments on commit 2e04521

Please sign in to comment.