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

56 lines
899 B
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
},
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
);
return cardLabel;
},
2019-08-31 04:07:25 +05:00
};