2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
|
|
|
const projectManagers = await ProjectManager.destroy({
|
2019-11-05 18:01:42 +05:00
|
|
|
projectId: inputs.record.id,
|
2019-08-31 04:07:25 +05:00
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
const project = await Project.archiveOne(inputs.record.id);
|
|
|
|
|
|
|
|
if (project) {
|
2021-06-24 01:05:22 +05:00
|
|
|
const managerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-04-28 14:15:36 +05:00
|
|
|
const boardIds = await sails.helpers.projects.getBoardIds(project.id);
|
|
|
|
const boardRooms = boardIds.map((boardId) => `board:${boardId}`);
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const memberUserIds = await sails.helpers.boards.getMemberUserIds(boardIds);
|
|
|
|
const userIds = _.union(managerUserIds, memberUserIds);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2020-04-03 00:35:25 +05:00
|
|
|
userIds.forEach((userId) => {
|
2022-10-03 12:11:19 +02:00
|
|
|
sails.sockets.removeRoomMembersFromRooms(`@user:${userId}`, boardRooms);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`user:${userId}`,
|
|
|
|
'projectDelete',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: project,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return project;
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|