mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
ref: Remove board types, refactoring
This commit is contained in:
parent
d39da61295
commit
5cd025ffb7
182 changed files with 1573 additions and 1239 deletions
|
@ -1,92 +1,75 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listMustBePresent: {},
|
||||
listMustBelongToBoard: {},
|
||||
positionMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (inputs.board.type === Board.Types.KANBAN) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (inputs.list.boardId !== inputs.board.id) {
|
||||
throw 'listMustBelongToBoard';
|
||||
}
|
||||
const cards = await sails.helpers.lists.getCards(values.list.id);
|
||||
|
||||
values.listId = inputs.list.id;
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(inputs.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: inputs.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: values.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
values.position = position;
|
||||
} else if (inputs.board.type === Board.Types.COLLECTION) {
|
||||
delete values.position;
|
||||
}
|
||||
sails.sockets.broadcast(`board:${values.list.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const card = await Card.create({
|
||||
...values,
|
||||
boardId: inputs.board.id,
|
||||
creatorUserId: inputs.user.id,
|
||||
position,
|
||||
boardId: values.list.boardId,
|
||||
listId: values.list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
@ -98,13 +81,13 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
if (inputs.user.subscribeToOwnCards) {
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
|
||||
sails.sockets.broadcast(`user:${inputs.user.id}`, 'cardUpdate', {
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: card.id,
|
||||
isSubscribed: true,
|
||||
|
@ -112,16 +95,16 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
await sails.helpers.actions.createOne(
|
||||
{
|
||||
await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.CREATE_CARD,
|
||||
data: {
|
||||
list: _.pick(inputs.list, ['id', 'name']),
|
||||
list: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
inputs.user,
|
||||
card,
|
||||
);
|
||||
});
|
||||
|
||||
return card;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue