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/attachments/create-one.js

50 lines
927 B
JavaScript
Raw Normal View History

2020-04-21 05:04:34 +05:00
module.exports = {
inputs: {
values: {
type: 'json',
2020-04-21 05:04:34 +05:00
required: true,
},
2020-04-23 03:02:53 +05:00
user: {
type: 'ref',
required: true,
},
card: {
type: 'ref',
2020-04-21 05:04:34 +05:00
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',
},
},
async fn(inputs) {
2020-04-21 05:04:34 +05:00
const attachment = await Attachment.create({
...inputs.values,
cardId: inputs.card.id,
creatorUserId: 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,
);
if (!inputs.card.coverAttachmentId && attachment.image) {
await sails.helpers.cards.updateOne(inputs.card, {
coverAttachmentId: attachment.id,
2020-04-23 03:02:53 +05:00
});
}
return attachment;
2020-04-21 05:04:34 +05:00
},
};