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.creatorUser)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2020-04-21 05:04:34 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
2021-06-24 01:05:22 +05:00
|
|
|
values: {
|
|
|
|
type: 'ref',
|
2022-12-26 21:10:50 +01:00
|
|
|
custom: valuesValidator,
|
2020-04-21 05:04:34 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-06 20:22:14 +02:00
|
|
|
board: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
list: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-23 05:56:02 +05:00
|
|
|
requestId: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
},
|
2020-04-21 05:04:34 +05:00
|
|
|
request: {
|
|
|
|
type: 'ref',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2024-06-12 00:51:36 +02:00
|
|
|
const { values } = inputs;
|
2022-12-26 21:10:50 +01:00
|
|
|
|
2020-04-21 05:04:34 +05:00
|
|
|
const attachment = await Attachment.create({
|
2022-12-26 21:10:50 +01:00
|
|
|
...values,
|
|
|
|
cardId: values.card.id,
|
|
|
|
creatorUserId: values.creatorUser.id,
|
2020-04-21 05:04:34 +05:00
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
2022-12-26 21:10:50 +01:00
|
|
|
`board:${values.card.boardId}`,
|
2020-04-21 05:04:34 +05:00
|
|
|
'attachmentCreate',
|
|
|
|
{
|
|
|
|
item: attachment,
|
2020-04-23 05:56:02 +05:00
|
|
|
requestId: inputs.requestId,
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
inputs.request,
|
|
|
|
);
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
|
|
|
event: 'attachmentCreate',
|
|
|
|
data: {
|
|
|
|
item: attachment,
|
|
|
|
included: {
|
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
lists: [inputs.list],
|
|
|
|
cards: [values.card],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: values.creatorUser,
|
|
|
|
});
|
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
if (!values.card.coverAttachmentId && attachment.image) {
|
|
|
|
await sails.helpers.cards.updateOne.with({
|
|
|
|
record: values.card,
|
|
|
|
values: {
|
|
|
|
coverAttachmentId: attachment.id,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: inputs.project,
|
|
|
|
board: inputs.board,
|
|
|
|
list: inputs.list,
|
|
|
|
actorUser: values.creatorUser,
|
2020-04-23 03:02:53 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return attachment;
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
};
|