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

64 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-12-26 21:10:50 +01:00
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isPlainObject(value.card)) {
return false;
}
if (!_.isPlainObject(value.creatorUser)) {
return false;
}
return true;
};
2020-04-21 05:04:34 +05:00
module.exports = {
inputs: {
values: {
type: 'ref',
2022-12-26 21:10:50 +01:00
custom: valuesValidator,
2020-04-21 05:04:34 +05:00
required: true,
},
2020-04-23 05:56:02 +05:00
requestId: {
type: 'string',
isNotEmptyString: true,
},
2020-04-21 05:04:34 +05:00
request: {
type: 'ref',
},
},
async fn(inputs) {
2022-12-26 21:10:50 +01:00
const { values } = inputs;
2020-04-21 05:04:34 +05:00
const attachment = await Attachment.create({
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
}).fetch();
sails.sockets.broadcast(
2022-12-26 21:10:50 +01:00
`board:${values.card.boardId}`,
2020-04-21 05:04:34 +05:00
'attachmentCreate',
{
item: attachment,
2020-04-23 05:56:02 +05:00
requestId: inputs.requestId,
2020-04-21 05:04:34 +05:00
},
inputs.request,
);
2022-12-26 21:10:50 +01:00
if (!values.card.coverAttachmentId && attachment.image) {
await sails.helpers.cards.updateOne.with({
record: values.card,
values: {
coverAttachmentId: attachment.id,
},
2020-04-23 03:02:53 +05:00
});
}
return attachment;
2020-04-21 05:04:34 +05:00
},
};