2020-04-21 05:04:34 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
card: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-23 03:02:53 +05:00
|
|
|
user: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-21 05:04:34 +05:00
|
|
|
values: {
|
|
|
|
type: 'json',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-23 05:56:02 +05:00
|
|
|
requestId: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
allowNull: true,
|
|
|
|
defaultsTo: null,
|
|
|
|
},
|
2020-04-21 05:04:34 +05:00
|
|
|
request: {
|
|
|
|
type: 'ref',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async fn(inputs, exits) {
|
|
|
|
const attachment = await Attachment.create({
|
|
|
|
...inputs.values,
|
|
|
|
cardId: inputs.card.id,
|
2020-04-23 03:02:53 +05:00
|
|
|
userId: inputs.user.id,
|
2020-04-21 05:04:34 +05:00
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${inputs.card.boardId}`,
|
|
|
|
'attachmentCreate',
|
|
|
|
{
|
|
|
|
item: attachment,
|
2020-04-23 05:56:02 +05:00
|
|
|
requestId: inputs.requestId,
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
inputs.request,
|
|
|
|
);
|
|
|
|
|
2020-04-23 03:02:53 +05:00
|
|
|
if (!inputs.card.coverAttachmentId && attachment.isImage) {
|
|
|
|
await sails.helpers.updateCard.with({
|
|
|
|
record: inputs.card,
|
|
|
|
values: {
|
|
|
|
coverAttachmentId: attachment.id,
|
|
|
|
},
|
|
|
|
request: inputs.request,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:04:34 +05:00
|
|
|
return exits.success(attachment);
|
|
|
|
},
|
|
|
|
};
|