1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/server/api/helpers/project-managers/create-one.js
2022-12-26 21:10:50 +01:00

60 lines
1.1 KiB
JavaScript

const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isPlainObject(value.project)) {
return false;
}
if (!_.isPlainObject(value.user)) {
return false;
}
return true;
};
module.exports = {
inputs: {
values: {
type: 'ref',
custom: valuesValidator,
required: true,
},
request: {
type: 'ref',
},
},
exits: {
userAlreadyProjectManager: {},
},
async fn(inputs) {
const { values } = inputs;
const projectManager = await ProjectManager.create({
projectId: values.project.id,
userId: values.user.id,
})
.intercept('E_UNIQUE', 'userAlreadyProjectManager')
.fetch();
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
projectManager.projectId,
);
projectRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectManagerCreate',
{
item: projectManager,
},
inputs.request,
);
});
return projectManager;
},
};