mirror of
https://github.com/plankanban/planka.git
synced 2025-12-17 17:23:25 +03:00
@@ -1,24 +1,12 @@
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
@@ -35,7 +23,6 @@ module.exports = {
|
||||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
@@ -45,17 +32,17 @@ module.exports = {
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const attachment = await Attachment.create({
|
||||
const attachment = await Attachment.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${values.card.boardId}`,
|
||||
`board:${inputs.board.id}`,
|
||||
'attachmentCreate',
|
||||
{
|
||||
item: attachment,
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
@@ -63,29 +50,31 @@ module.exports = {
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentCreate',
|
||||
data: {
|
||||
item: attachment,
|
||||
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 && attachment.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,
|
||||
});
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return attachment;
|
||||
|
||||
Reference in New Issue
Block a user