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/projects/create-one.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
values: {
type: 'json',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
2022-12-26 21:10:50 +01:00
const { values } = inputs;
const { project, projectManager } = await Project.qm.createOne(values, {
user: inputs.actorUser,
});
const scoper = sails.helpers.projects.makeScoper.with({
record: project,
});
scoper.projectManagerUserIds = [projectManager.userId];
const userIdsWithFullProjectVisibility = await scoper.getUserIdsWithFullProjectVisibility();
userIdsWithFullProjectVisibility.forEach((userId) => {
// TODO: send projectManager in included
sails.sockets.broadcast(
`user:${userId}`,
'projectCreate',
{
item: project,
},
inputs.request,
);
});
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.PROJECT_CREATE,
buildData: () => ({
item: project,
}),
user: inputs.actorUser,
});
return {
project,
projectManager,
};
},
};