mirror of
https://github.com/plankanban/planka.git
synced 2025-12-17 09:13:23 +03:00
ref: Remove board types, refactoring
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user