2020-04-21 05:04:34 +05:00
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
record: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
board: {
|
2020-04-23 03:02:53 +05:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
list: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
card: {
|
2020-04-21 05:04:34 +05:00
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
actorUser: {
|
|
|
|
type: 'ref',
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-21 05:04:34 +05:00
|
|
|
request: {
|
|
|
|
type: 'ref',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
2020-04-23 03:02:53 +05:00
|
|
|
if (inputs.record.id === inputs.card.coverAttachmentId) {
|
2021-06-24 01:05:22 +05:00
|
|
|
await sails.helpers.cards.updateOne.with({
|
2020-04-23 03:02:53 +05:00
|
|
|
record: inputs.card,
|
|
|
|
values: {
|
|
|
|
coverAttachmentId: null,
|
|
|
|
},
|
2024-06-12 00:51:36 +02:00
|
|
|
project: inputs.project,
|
|
|
|
board: inputs.board,
|
|
|
|
list: inputs.list,
|
|
|
|
actorUser: inputs.actorUser,
|
2020-04-23 03:02:53 +05:00
|
|
|
request: inputs.request,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:04:34 +05:00
|
|
|
const attachment = await Attachment.archiveOne(inputs.record.id);
|
|
|
|
|
|
|
|
if (attachment) {
|
2024-11-12 15:58:22 +01:00
|
|
|
const fileManager = sails.hooks['file-manager'].getInstance();
|
|
|
|
|
2024-11-11 20:59:18 +07:00
|
|
|
try {
|
2024-11-12 15:58:22 +01:00
|
|
|
await fileManager.deleteFolder(
|
|
|
|
`${sails.config.custom.attachmentsPathSegment}/${attachment.dirname}`,
|
|
|
|
);
|
2020-04-21 05:04:34 +05:00
|
|
|
} catch (error) {
|
|
|
|
console.warn(error.stack); // eslint-disable-line no-console
|
|
|
|
}
|
|
|
|
|
|
|
|
sails.sockets.broadcast(
|
|
|
|
`board:${inputs.board.id}`,
|
|
|
|
'attachmentDelete',
|
|
|
|
{
|
|
|
|
item: attachment,
|
|
|
|
},
|
|
|
|
inputs.request,
|
|
|
|
);
|
2024-06-06 20:22:14 +02:00
|
|
|
|
2024-06-12 00:51:36 +02:00
|
|
|
sails.helpers.utils.sendWebhooks.with({
|
|
|
|
event: 'attachmentDelete',
|
|
|
|
data: {
|
|
|
|
item: attachment,
|
|
|
|
included: {
|
|
|
|
projects: [inputs.project],
|
|
|
|
boards: [inputs.board],
|
|
|
|
lists: [inputs.list],
|
|
|
|
cards: [inputs.card],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
user: inputs.actorUser,
|
2024-06-06 20:22:14 +02:00
|
|
|
});
|
2020-04-21 05:04:34 +05:00
|
|
|
}
|
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return attachment;
|
2020-04-21 05:04:34 +05:00
|
|
|
},
|
|
|
|
};
|