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:
parent
2b131f76c1
commit
6ffa817b53
182 changed files with 1573 additions and 1239 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue