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,12 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -15,22 +27,24 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const lists = await sails.helpers.boards.getLists(inputs.board.id);
|
||||
const { values } = inputs;
|
||||
|
||||
const lists = await sails.helpers.boards.getLists(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await List.update({
|
||||
id,
|
||||
boardId: inputs.board.id,
|
||||
boardId: values.board.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'listUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
|
@ -39,9 +53,9 @@ module.exports = {
|
|||
});
|
||||
|
||||
const list = await List.create({
|
||||
...inputs.values,
|
||||
...values,
|
||||
position,
|
||||
boardId: inputs.board.id,
|
||||
boardId: values.board.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue