1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 21:29:43 +02:00
planka/server/api/helpers/users/delete-one.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
2019-08-31 04:07:25 +05:00
},
request: {
type: 'ref',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
await ProjectManager.destroy({
userId: inputs.record.id,
});
await BoardMembership.destroy({
userId: inputs.record.id,
2019-08-31 04:07:25 +05:00
});
await CardSubscription.destroy({
userId: inputs.record.id,
2019-08-31 04:07:25 +05:00
});
await CardMembership.destroy({
userId: inputs.record.id,
2019-08-31 04:07:25 +05:00
});
const user = await User.updateOne({
id: inputs.record.id,
deletedAt: null,
2019-08-31 04:07:25 +05:00
}).set({
deletedAt: new Date().toUTCString(),
2019-08-31 04:07:25 +05:00
});
if (user) {
/* const projectIds = await sails.helpers.users.getManagerProjectIds(user.id);
const userIds = _.union(
[user.id],
await sails.helpers.users.getAdminIds(),
await sails.helpers.projects.getManagerAndBoardMemberUserIds(projectIds),
); */
const users = await sails.helpers.users.getMany();
const userIds = [inputs.record.id, ...sails.helpers.utils.mapRecords(users)];
2019-08-31 04:07:25 +05:00
2020-04-03 00:35:25 +05:00
userIds.forEach((userId) => {
2019-08-31 04:07:25 +05:00
sails.sockets.broadcast(
`user:${userId}`,
'userDelete',
{
item: user,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05:00
);
});
}
return user;
},
2019-08-31 04:07:25 +05:00
};