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

54 lines
1 KiB
JavaScript

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