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

87 lines
1.5 KiB
JavaScript
Raw Normal View History

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,
required: true,
2019-08-31 04:07:25 +05: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: {
type: 'ref',
},
2019-08-31 04:07:25 +05:00
},
2020-04-03 00:35:25 +05:00
exits: {
labelAlreadyInCard: {},
},
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',
{
item: cardLabel,
2019-08-31 04:07:25 +05:00
},
inputs.request,
2019-08-31 04:07:25 +05: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,
});
return cardLabel;
},
2019-08-31 04:07:25 +05:00
};