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

60 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
module.exports = {
inputs: {
record: {
type: 'ref',
required: true
},
request: {
type: 'ref'
}
},
fn: async function(inputs, exits) {
await ProjectMembership.destroy({
userId: inputs.record.id
});
await CardSubscription.destroy({
userId: inputs.record.id
});
await CardMembership.destroy({
userId: inputs.record.id
});
const user = await User.updateOne({
id: inputs.record.id,
deletedAt: null
}).set({
deletedAt: new Date().toUTCString()
});
if (user) {
const adminUserIds = await sails.helpers.getAdminUserIds();
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
user.id
);
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(
projectIds
);
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
sails.sockets.broadcast(
`user:${userId}`,
'userDelete',
{
item: user
},
inputs.request
);
});
}
return exits.success(user);
}
};