2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* 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: {
|
2021-06-24 01:05:22 +05:00
|
|
|
values: {
|
|
|
|
type: 'ref',
|
2020-04-21 05:04:34 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-06 20:22:14 +02:00
|
|
|
board: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2024-06-12 00:51:36 +02:00
|
|
|
const { values } = inputs;
|
2022-12-26 21:10:50 +01:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
const attachment = await Attachment.qm.createOne({
|
2022-12-26 21:10:50 +01:00
|
|
|
...values,
|
|
|
|
cardId: values.card.id,
|
|
|
|
creatorUserId: values.creatorUser.id,
|
2025-05-10 02:09:06 +02:00
|
|
|
});
|
2020-04-21 05:04:34 +05:00
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
2025-05-10 02:09:06 +02:00
|
|
|
`board:${inputs.board.id}`,
|
2020-04-21 05:04:34 +05:00
|
|
|
'attachmentCreate',
|
|
|
|
{
|
2025-05-10 02:09:06 +02:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
|
|
|
event: 'attachmentCreate',
|
2025-05-10 02:09:06 +02:00
|
|
|
buildData: () => ({
|
|
|
|
item: sails.helpers.attachments.presentOne(attachment),
|
2024-06-12 00:51:36 +02:00
|
|
|
included: {
|
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
lists: [inputs.list],
|
|
|
|
cards: [values.card],
|
|
|
|
},
|
2025-05-10 02:09:06 +02:00
|
|
|
}),
|
2024-06-12 00:51:36 +02:00
|
|
|
user: values.creatorUser,
|
|
|
|
});
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return attachment;
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
};
|