1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 21:29:43 +02:00
planka/server/api/helpers/attachments/delete-one.js

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-04-21 05:04:34 +05:00
const path = require('path');
const rimraf = require('rimraf');
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
board: {
2020-04-23 03:02:53 +05:00
type: 'ref',
required: true,
},
card: {
2020-04-21 05:04:34 +05:00
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
2020-04-23 03:02:53 +05:00
if (inputs.record.id === inputs.card.coverAttachmentId) {
await sails.helpers.cards.updateOne.with({
2020-04-23 03:02:53 +05:00
record: inputs.card,
values: {
coverAttachmentId: null,
},
request: inputs.request,
});
}
2020-04-21 05:04:34 +05:00
const attachment = await Attachment.archiveOne(inputs.record.id);
if (attachment) {
try {
rimraf.sync(path.join(sails.config.custom.attachmentsPath, attachment.dirname));
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console
}
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'attachmentDelete',
{
item: attachment,
},
inputs.request,
);
}
return attachment;
2020-04-21 05:04:34 +05:00
},
};