mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
147
server/api/helpers/update-card.js
Normal file
147
server/api/helpers/update-card.js
Normal file
|
@ -0,0 +1,147 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
(_.isUndefined(value.position) || _.isFinite(value.position)),
|
||||
required: true
|
||||
},
|
||||
toList: {
|
||||
type: 'ref'
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
let listId;
|
||||
if (inputs.toList) {
|
||||
listId = inputs.toList.id;
|
||||
|
||||
if (listId !== inputs.list.id) {
|
||||
values.listId = listId;
|
||||
} else {
|
||||
delete inputs.toList;
|
||||
}
|
||||
} else {
|
||||
listId = inputs.list.id;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const cards = await sails.helpers.getCardsForList(
|
||||
listId,
|
||||
inputs.record.id
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
values.position,
|
||||
cards
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.record.boardId}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
let card;
|
||||
if (!_.isEmpty(values)) {
|
||||
card = await Card.updateOne(inputs.record.id).set(values);
|
||||
|
||||
if (!card) {
|
||||
return exits.success(card);
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: card
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
if (inputs.toList) {
|
||||
const values = {
|
||||
type: 'moveCard',
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'name']),
|
||||
toList: _.pick(inputs.toList, ['id', 'name'])
|
||||
}
|
||||
};
|
||||
|
||||
await sails.helpers.createAction(card, inputs.user, values);
|
||||
}
|
||||
} else {
|
||||
card = inputs.record;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const cardSubscription = await CardSubscription.findOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id
|
||||
});
|
||||
|
||||
if (isSubscribed !== !!cardSubscription) {
|
||||
if (isSubscribed) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id
|
||||
}).tolerate('E_UNIQUE');
|
||||
} else {
|
||||
await CardSubscription.destroyOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id
|
||||
});
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${inputs.user.id}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: {
|
||||
isSubscribed,
|
||||
id: card.id
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return exits.success(card);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue