1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

ref: Remove board types, refactoring

This commit is contained in:
Maksim Eltyshev 2022-12-26 21:10:50 +01:00
parent d39da61295
commit 5cd025ffb7
182 changed files with 1573 additions and 1239 deletions

View file

@ -1,25 +1,46 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isFinite(value.position)) {
return false;
}
if (!_.isPlainObject(value.project)) {
return false;
}
return true;
};
const importValidator = (value) => {
if (!value.type || !Object.values(Board.ImportTypes).includes(value.type)) {
return false;
}
if (!_.isPlainObject(value.board)) {
return false;
}
return true;
};
module.exports = {
inputs: {
values: {
type: 'json',
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
type: 'ref',
custom: valuesValidator,
required: true,
},
import: {
type: 'json',
custom: (value) =>
value.type &&
Object.values(Board.ImportTypes).includes(value.type) &&
_.isPlainObject(value.board),
custom: importValidator,
},
user: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
requestId: {
type: 'string',
isNotEmptyString: true,
@ -30,26 +51,29 @@ module.exports = {
},
async fn(inputs) {
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.project.id);
const boards = await sails.helpers.projects.getBoards(inputs.project.id);
const { values } = inputs;
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(values.project.id);
const boards = await sails.helpers.projects.getBoards(values.project.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
values.position,
boards,
);
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
projectId: inputs.project.id,
projectId: values.project.id,
}).set({
position: nextPosition,
});
const memberUserIds = await sails.helpers.boards.getMemberUserIds(id);
const userIds = _.union(managerUserIds, memberUserIds);
// TODO: move out of loop
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(id);
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
userIds.forEach((userId) => {
boardRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
@ -60,9 +84,9 @@ module.exports = {
});
const board = await Board.create({
...inputs.values,
...values,
position,
projectId: inputs.project.id,
projectId: values.project.id,
}).fetch();
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
@ -75,7 +99,7 @@ module.exports = {
role: BoardMembership.Roles.EDITOR,
}).fetch();
managerUserIds.forEach((userId) => {
projectManagerUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',

View file

@ -10,7 +10,7 @@ module.exports = {
},
async fn(inputs) {
await BoardMembership.destroy({
const boardMemberships = await BoardMembership.destroy({
boardId: inputs.record.id,
}).fetch();
@ -19,12 +19,11 @@ module.exports = {
if (board) {
sails.sockets.removeRoomMembersFromRooms(`board:${board.id}`, `board:${board.id}`);
const managerUserIds = await sails.helpers.projects.getManagerUserIds(board.projectId);
const memberUserIds = await sails.helpers.boards.getMemberUserIds(board.id);
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(board.projectId);
const boardMemberUserIds = sails.helpers.utils.mapRecords(boardMemberships, 'userId');
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
const userIds = _.union(managerUserIds, memberUserIds);
userIds.forEach((userId) => {
boardRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardDelete',

View file

@ -1,8 +1,10 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
required: true,
},
},

View file

@ -1,8 +1,10 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
required: true,
},
},

View file

@ -1,41 +1,17 @@
const LIMIT = 10;
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
recordOrIdOrIds: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value) || _.every(value, _.isString),
idOrIds: {
type: 'json',
custom: idOrIdsValidator,
required: true,
},
beforeId: {
type: 'string',
},
},
async fn(inputs) {
const criteria = {};
let sort;
let limit;
if (_.isObjectLike(inputs.recordOrIdOrIds)) {
criteria.boardId = inputs.recordOrIdOrIds.id;
if (inputs.recordOrIdOrIds.type === Board.Types.KANBAN) {
sort = 'position';
} else if (inputs.recordOrIdOrIds.type === Board.Types.COLLECTION) {
if (inputs.beforeId) {
criteria.id = {
'<': inputs.beforeId,
};
}
limit = LIMIT;
}
} else {
criteria.boardId = inputs.recordOrIdOrIds;
}
return sails.helpers.cards.getMany(criteria, sort, limit);
return sails.helpers.cards.getMany({
boardId: inputs.idOrIds,
});
},
};

View file

@ -1,8 +1,10 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
required: true,
},
},

View file

@ -1,13 +1,15 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
required: true,
},
exceptListIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
},
},

View file

@ -1,8 +1,10 @@
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
custom: criteriaValidator,
},
},

View file

@ -1,8 +1,10 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
custom: idOrIdsValidator,
required: true,
},
},

View file

@ -1,3 +1,15 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
};
module.exports = {
inputs: {
record: {
@ -6,17 +18,7 @@ module.exports = {
},
values: {
type: 'json',
custom: (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
},
custom: valuesValidator,
required: true,
},
request: {
@ -25,23 +27,27 @@ module.exports = {
},
async fn(inputs) {
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.record.projectId);
const memberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.record.id);
const { values } = inputs;
const userIds = _.union(managerUserIds, memberUserIds);
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(
inputs.record.projectId,
);
if (!_.isUndefined(inputs.values.position)) {
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.record.id);
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
if (!_.isUndefined(values.position)) {
const boards = await sails.helpers.projects.getBoards(
inputs.record.projectId,
inputs.record.id,
);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
values.position,
boards,
);
inputs.values.position = position; // eslint-disable-line no-param-reassign
values.position = position;
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
@ -51,7 +57,7 @@ module.exports = {
position: nextPosition,
});
userIds.forEach((userId) => {
boardRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
@ -62,10 +68,10 @@ module.exports = {
});
}
const board = await Board.updateOne(inputs.record.id).set(inputs.values);
const board = await Board.updateOne(inputs.record.id).set({ ...values });
if (board) {
userIds.forEach((userId) => {
boardRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardUpdate',