2022-12-26 21:10:50 +01:00
|
|
|
const valuesValidator = (value) => {
|
|
|
|
if (!_.isPlainObject(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_.isPlainObject(value.card)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_.isPlainObject(value.label)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
2022-12-26 21:10:50 +01:00
|
|
|
values: {
|
2019-08-31 04:07:25 +05:00
|
|
|
type: 'ref',
|
2022-12-26 21:10:50 +01:00
|
|
|
custom: valuesValidator,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
board: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
actorUser: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
request: {
|
2019-11-05 18:01:42 +05:00
|
|
|
type: 'ref',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2020-04-03 00:35:25 +05:00
|
|
|
exits: {
|
|
|
|
labelAlreadyInCard: {},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2022-12-26 21:10:50 +01:00
|
|
|
const { values } = inputs;
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const cardLabel = await CardLabel.create({
|
2022-12-26 21:10:50 +01:00
|
|
|
...values,
|
|
|
|
cardId: values.card.id,
|
|
|
|
labelId: values.label.id,
|
2019-08-31 04:07:25 +05:00
|
|
|
})
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('E_UNIQUE', 'labelAlreadyInCard')
|
2019-08-31 04:07:25 +05:00
|
|
|
.fetch();
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
2022-12-26 21:10:50 +01:00
|
|
|
`board:${values.card.boardId}`,
|
2019-08-31 04:07:25 +05:00
|
|
|
'cardLabelCreate',
|
|
|
|
{
|
2019-11-05 18:01:42 +05:00
|
|
|
item: cardLabel,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
2019-11-05 18:01:42 +05:00
|
|
|
inputs.request,
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
|
|
|
event: 'cardLabelCreate',
|
|
|
|
data: {
|
|
|
|
item: cardLabel,
|
|
|
|
included: {
|
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
labels: [values.label],
|
|
|
|
lists: [inputs.list],
|
|
|
|
cards: [values.card],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: inputs.actorUser,
|
|
|
|
});
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return cardLabel;
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|