2024-06-14 16:38:06 +02:00
|
|
|
const Errors = {
|
|
|
|
NOT_ENOUGH_RIGHTS: {
|
|
|
|
notEnoughRights: 'Not enough rights',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2024-06-14 16:38:06 +02:00
|
|
|
exits: {
|
|
|
|
notEnoughRights: {
|
|
|
|
responseType: 'forbidden',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2019-08-31 04:07:25 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
2024-06-14 16:38:06 +02:00
|
|
|
if (!currentUser.isAdmin && !sails.config.custom.allowAllToCreateProjects) {
|
|
|
|
throw Errors.NOT_ENOUGH_RIGHTS;
|
|
|
|
}
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const values = _.pick(inputs, ['name']);
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
const { project, projectManager } = await sails.helpers.projects.createOne.with({
|
2020-08-04 01:32:46 +05:00
|
|
|
values,
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: currentUser,
|
2022-12-26 21:10:50 +01:00
|
|
|
request: this.req,
|
|
|
|
});
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
2019-08-31 04:07:25 +05:00
|
|
|
item: project,
|
|
|
|
included: {
|
2021-06-24 01:05:22 +05:00
|
|
|
projectManagers: [projectManager],
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|