2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
LABEL_NOT_FOUND: {
|
2019-11-05 18:01:42 +05:00
|
|
|
notFound: 'Label is not found',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
id: {
|
2019-10-10 02:51:54 +05:00
|
|
|
type: 'string',
|
|
|
|
regex: /^[0-9]+$/,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2019-10-09 18:48:19 +05:00
|
|
|
isNotEmptyString: true,
|
2019-11-05 18:01:42 +05:00
|
|
|
allowNull: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
color: {
|
|
|
|
type: 'string',
|
|
|
|
isIn: Label.COLORS,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
|
|
|
notFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2019-08-31 04:07:25 +05:00
|
|
|
const { currentUser } = this.req;
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
const labelToProjectPath = await sails.helpers
|
2019-08-31 04:07:25 +05:00
|
|
|
.getLabelToProjectPath(inputs.id)
|
|
|
|
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
let { label } = labelToProjectPath;
|
|
|
|
const { project } = labelToProjectPath;
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
|
|
|
project.id,
|
2019-11-05 18:01:42 +05:00
|
|
|
currentUser.id,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!isUserMemberForProject) {
|
|
|
|
throw Errors.LABEL_NOT_FOUND; // Forbidden
|
|
|
|
}
|
|
|
|
|
|
|
|
const values = _.pick(inputs, ['name', 'color']);
|
|
|
|
|
|
|
|
label = await sails.helpers.updateLabel(label, values, this.req);
|
|
|
|
|
|
|
|
return exits.success({
|
2019-11-05 18:01:42 +05:00
|
|
|
item: label,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|