1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/actions/create-one.js

66 lines
1.1 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.user)) {
return false;
}
return true;
};
module.exports = {
inputs: {
values: {
type: 'ref',
2022-12-26 21:10:50 +01:00
custom: valuesValidator,
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
2022-12-26 21:10:50 +01:00
const { values } = inputs;
const action = await Action.create({
2022-12-26 21:10:50 +01:00
...values,
cardId: values.card.id,
userId: values.user.id,
}).fetch();
sails.sockets.broadcast(
2022-12-26 21:10:50 +01:00
`board:${values.card.boardId}`,
'actionCreate',
{
item: action,
},
inputs.request,
);
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
2022-12-26 21:10:50 +01:00
await Promise.all(
subscriptionUserIds.map(async (userId) =>
sails.helpers.notifications.createOne.with({
values: {
userId,
action,
},
}),
),
);
return action;
},
};