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;
|
|
|
|
};
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
values: {
|
|
|
|
type: 'ref',
|
2022-12-26 21:10:50 +01:00
|
|
|
custom: valuesValidator,
|
2021-06-24 01:05:22 +05:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
request: {
|
|
|
|
type: 'ref',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async fn(inputs) {
|
2022-12-26 21:10:50 +01:00
|
|
|
const { values } = inputs;
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
const action = await Action.create({
|
2022-12-26 21:10:50 +01:00
|
|
|
...values,
|
|
|
|
cardId: values.card.id,
|
|
|
|
userId: values.user.id,
|
2021-06-24 01:05:22 +05:00
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
2022-12-26 21:10:50 +01:00
|
|
|
`board:${values.card.boardId}`,
|
2021-06-24 01:05:22 +05:00
|
|
|
'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,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
return action;
|
|
|
|
},
|
|
|
|
};
|