You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
planka_custom/server/api/helpers/project-managers/create-one.js

61 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;
},
};