1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/server/api/helpers/create-attachment.js

55 lines
1 KiB
JavaScript
Raw Normal View History

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,
},
});
}
2020-04-21 05:04:34 +05:00
return exits.success(attachment);
},
};