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

83 lines
1.8 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
2022-12-26 21:10:50 +01:00
2020-04-21 05:04:34 +05:00
module.exports = {
inputs: {
values: {
type: 'ref',
2020-04-21 05:04:34 +05:00
required: true,
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
list: {
type: 'ref',
required: true,
},
2020-04-23 05:56:02 +05:00
requestId: {
type: 'string',
},
2020-04-21 05:04:34 +05:00
request: {
type: 'ref',
},
},
async fn(inputs) {
const { values } = inputs;
2022-12-26 21:10:50 +01:00
const attachment = await Attachment.qm.createOne({
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
sails.sockets.broadcast(
`board:${inputs.board.id}`,
2020-04-21 05:04:34 +05:00
'attachmentCreate',
{
item: sails.helpers.attachments.presentOne(attachment),
2020-04-23 05:56:02 +05:00
requestId: inputs.requestId,
2020-04-21 05:04:34 +05:00
},
inputs.request,
);
sails.helpers.utils.sendWebhooks.with({
event: 'attachmentCreate',
buildData: () => ({
item: sails.helpers.attachments.presentOne(attachment),
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [values.card],
},
}),
user: values.creatorUser,
});
if (!values.card.coverAttachmentId) {
if (attachment.type === Attachment.Types.FILE && attachment.data.image) {
await sails.helpers.cards.updateOne.with({
record: values.card,
values: {
coverAttachmentId: attachment.id,
},
project: inputs.project,
board: inputs.board,
list: inputs.list,
actorUser: values.creatorUser,
});
}
2020-04-23 03:02:53 +05:00
}
return attachment;
2020-04-21 05:04:34 +05:00
},
};