1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-25 08:09:44 +02:00

ref: Remove board types, refactoring

This commit is contained in:
Maksim Eltyshev 2022-12-26 21:10:50 +01:00
parent 2b131f76c1
commit 6ffa817b53
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',