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,15 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -18,14 +27,16 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const action = await Action.create({
|
||||
...inputs.values,
|
||||
cardId: inputs.card.id,
|
||||
userId: inputs.user.id,
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
userId: values.user.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
`board:${values.card.boardId}`,
|
||||
'actionCreate',
|
||||
{
|
||||
item: action,
|
||||
|
@ -38,9 +49,16 @@ module.exports = {
|
|||
action.userId,
|
||||
);
|
||||
|
||||
subscriptionUserIds.forEach(async (userId) => {
|
||||
await sails.helpers.notifications.createOne(userId, action);
|
||||
});
|
||||
await Promise.all(
|
||||
subscriptionUserIds.map(async (userId) =>
|
||||
sails.helpers.notifications.createOne.with({
|
||||
values: {
|
||||
userId,
|
||||
action,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return action;
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
|
|
|
@ -18,7 +18,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const action = await Action.updateOne(inputs.record.id).set(inputs.values);
|
||||
const { values } = inputs;
|
||||
|
||||
const action = await Action.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (action) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
requestId: {
|
||||
|
@ -22,14 +31,16 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const attachment = await Attachment.create({
|
||||
...inputs.values,
|
||||
cardId: inputs.card.id,
|
||||
creatorUserId: inputs.user.id,
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
`board:${values.card.boardId}`,
|
||||
'attachmentCreate',
|
||||
{
|
||||
item: attachment,
|
||||
|
@ -38,9 +49,12 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
if (!inputs.card.coverAttachmentId && attachment.image) {
|
||||
await sails.helpers.cards.updateOne(inputs.card, {
|
||||
coverAttachmentId: attachment.id,
|
||||
if (!values.card.coverAttachmentId && attachment.image) {
|
||||
await sails.helpers.cards.updateOne.with({
|
||||
record: values.card,
|
||||
values: {
|
||||
coverAttachmentId: attachment.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const attachment = await Attachment.updateOne(inputs.record.id).set(inputs.values);
|
||||
const { values } = inputs;
|
||||
|
||||
const attachment = await Attachment.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (attachment) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -22,18 +31,20 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (inputs.values.role === BoardMembership.Roles.EDITOR) {
|
||||
delete inputs.values.canComment; // eslint-disable-line no-param-reassign
|
||||
} else if (inputs.values.role === BoardMembership.Roles.VIEWER) {
|
||||
if (_.isNil(inputs.values.canComment)) {
|
||||
inputs.values.canComment = false; // eslint-disable-line no-param-reassign
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.role === BoardMembership.Roles.EDITOR) {
|
||||
delete values.canComment;
|
||||
} else if (values.role === BoardMembership.Roles.VIEWER) {
|
||||
if (_.isNil(values.canComment)) {
|
||||
values.canComment = false;
|
||||
}
|
||||
}
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
...inputs.values,
|
||||
boardId: inputs.board.id,
|
||||
userId: inputs.user.id,
|
||||
...values,
|
||||
boardId: values.board.id,
|
||||
userId: values.user.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyBoardMember')
|
||||
.fetch();
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -14,21 +14,22 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const role = inputs.values.role || inputs.record.role;
|
||||
const { values } = inputs;
|
||||
const role = values.role || inputs.record.role;
|
||||
|
||||
if (role === BoardMembership.Roles.EDITOR) {
|
||||
inputs.values.canComment = null; // eslint-disable-line no-param-reassign
|
||||
values.canComment = null;
|
||||
} else if (role === BoardMembership.Roles.VIEWER) {
|
||||
const canComment = _.isUndefined(inputs.values.canComment)
|
||||
const canComment = _.isUndefined(values.canComment)
|
||||
? inputs.record.canComment
|
||||
: inputs.values.canComment;
|
||||
: values.canComment;
|
||||
|
||||
if (_.isNull(canComment)) {
|
||||
inputs.values.canComment = false; // eslint-disable-line no-param-reassign
|
||||
values.canComment = false;
|
||||
}
|
||||
}
|
||||
|
||||
const boardMembership = await BoardMembership.updateOne(inputs.record.id).set(inputs.values);
|
||||
const boardMembership = await BoardMembership.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (boardMembership) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.label)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
label: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -18,15 +31,18 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const cardLabel = await CardLabel.create({
|
||||
cardId: inputs.card.id,
|
||||
labelId: inputs.label.id,
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
labelId: values.label.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'labelAlreadyInCard')
|
||||
.fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
`board:${values.card.boardId}`,
|
||||
'cardLabelCreate',
|
||||
{
|
||||
item: cardLabel,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user) && !_.isString(value.userId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
userOrId: {
|
||||
type: 'ref',
|
||||
custom: (value) => _.isObjectLike(value) || _.isString(value),
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -19,17 +31,21 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { userId = inputs.userOrId } = inputs.userOrId;
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.user) {
|
||||
values.userId = values.user.id;
|
||||
}
|
||||
|
||||
const cardMembership = await CardMembership.create({
|
||||
userId,
|
||||
cardId: inputs.card.id,
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyCardMember')
|
||||
.fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
`board:${values.card.boardId}`,
|
||||
'cardMembershipCreate',
|
||||
{
|
||||
item: cardMembership,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -1,92 +1,75 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listMustBePresent: {},
|
||||
listMustBelongToBoard: {},
|
||||
positionMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (inputs.board.type === Board.Types.KANBAN) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (inputs.list.boardId !== inputs.board.id) {
|
||||
throw 'listMustBelongToBoard';
|
||||
}
|
||||
const cards = await sails.helpers.lists.getCards(values.list.id);
|
||||
|
||||
values.listId = inputs.list.id;
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(inputs.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: inputs.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: values.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
values.position = position;
|
||||
} else if (inputs.board.type === Board.Types.COLLECTION) {
|
||||
delete values.position;
|
||||
}
|
||||
sails.sockets.broadcast(`board:${values.list.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const card = await Card.create({
|
||||
...values,
|
||||
boardId: inputs.board.id,
|
||||
creatorUserId: inputs.user.id,
|
||||
position,
|
||||
boardId: values.list.boardId,
|
||||
listId: values.list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
@ -98,13 +81,13 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
if (inputs.user.subscribeToOwnCards) {
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
|
||||
sails.sockets.broadcast(`user:${inputs.user.id}`, 'cardUpdate', {
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: card.id,
|
||||
isSubscribed: true,
|
||||
|
@ -112,16 +95,16 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
await sails.helpers.actions.createOne(
|
||||
{
|
||||
await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.CREATE_CARD,
|
||||
data: {
|
||||
list: _.pick(inputs.list, ['id', 'name']),
|
||||
list: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
inputs.user,
|
||||
card,
|
||||
);
|
||||
});
|
||||
|
||||
return card;
|
||||
},
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
const LIMIT = 50;
|
||||
|
||||
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,
|
||||
},
|
||||
beforeId: {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isArray(value) || _.isPlainObject(value),
|
||||
},
|
||||
sort: {
|
||||
type: 'json',
|
||||
defaultsTo: 'id DESC',
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Card.find(inputs.criteria).sort(inputs.sort).limit(inputs.limit);
|
||||
return Card.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
||||
|
|
|
@ -17,26 +17,14 @@ module.exports = {
|
|||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
let path;
|
||||
if (card.listId) {
|
||||
path = await sails.helpers.lists
|
||||
.getProjectPath(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
} else {
|
||||
path = await sails.helpers.boards
|
||||
.getProjectPath(card.boardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
}
|
||||
const path = await sails.helpers.lists
|
||||
.getProjectPath(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
card,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
exceptTaskIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.board) && !_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.list) && !_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -5,25 +25,9 @@ module.exports = {
|
|||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
defaultsTo: {},
|
||||
},
|
||||
nextBoard: {
|
||||
type: 'ref',
|
||||
},
|
||||
nextList: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
|
@ -40,68 +44,58 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
positionMustBeInValues: {},
|
||||
listMustBeInValues: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
userMustBePresent: {},
|
||||
boardMustBePresent: {},
|
||||
listMustBePresent: {},
|
||||
nextListMustBelongToBoard: {},
|
||||
nextListMustBePresent: {},
|
||||
positionMustBeInValues: {},
|
||||
userMustBePresent: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
if (inputs.nextBoard || inputs.nextList || !_.isUndefined(values.position)) {
|
||||
if (values.board || values.list || !_.isUndefined(values.position)) {
|
||||
if (!inputs.board) {
|
||||
throw 'boardMustBePresent';
|
||||
}
|
||||
|
||||
if (inputs.nextBoard) {
|
||||
if (inputs.nextBoard.id === inputs.board.id) {
|
||||
delete inputs.nextBoard; // eslint-disable-line no-param-reassign
|
||||
if (values.board) {
|
||||
if (values.board.id === inputs.board.id) {
|
||||
delete values.board;
|
||||
} else {
|
||||
values.boardId = inputs.nextBoard.id;
|
||||
values.boardId = values.board.id;
|
||||
}
|
||||
}
|
||||
|
||||
const board = inputs.nextBoard || inputs.board;
|
||||
const board = values.board || inputs.board;
|
||||
|
||||
if (inputs.nextList) {
|
||||
if (inputs.board.type === Board.Types.KANBAN && !inputs.list) {
|
||||
if (values.list) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
|
||||
if (inputs.nextList.boardId !== board.id) {
|
||||
throw 'nextListMustBelongToBoard';
|
||||
if (values.list.boardId !== board.id) {
|
||||
throw 'listInValuesMustBelongToBoard';
|
||||
}
|
||||
|
||||
if (
|
||||
board.type === Board.Types.COLLECTION ||
|
||||
(inputs.board.type === Board.Types.KANBAN && inputs.nextList.id === inputs.list.id)
|
||||
) {
|
||||
delete inputs.nextList; // eslint-disable-line no-param-reassign
|
||||
if (values.list.id === inputs.list.id) {
|
||||
delete values.list;
|
||||
} else {
|
||||
values.listId = inputs.nextList.id;
|
||||
values.listId = values.list.id;
|
||||
}
|
||||
}
|
||||
|
||||
if (inputs.nextList) {
|
||||
if (values.list) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
} else if (inputs.nextBoard) {
|
||||
if (inputs.nextBoard.type === Board.Types.KANBAN) {
|
||||
throw 'nextListMustBePresent';
|
||||
}
|
||||
|
||||
if (inputs.board.type === Board.Types.KANBAN) {
|
||||
values.listId = null;
|
||||
values.position = null;
|
||||
}
|
||||
} else if (values.board) {
|
||||
throw 'listMustBeInValues';
|
||||
}
|
||||
}
|
||||
|
||||
if ((!_.isUndefined(isSubscribed) || inputs.nextBoard || inputs.nextList) && !inputs.user) {
|
||||
if ((!_.isUndefined(isSubscribed) || values.board || values.list) && !inputs.user) {
|
||||
throw 'userMustBePresent';
|
||||
}
|
||||
|
||||
|
@ -116,6 +110,8 @@ module.exports = {
|
|||
cards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
|
@ -131,31 +127,29 @@ module.exports = {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
values.position = position;
|
||||
}
|
||||
|
||||
let card;
|
||||
if (!_.isEmpty(values)) {
|
||||
if (_.isEmpty(values)) {
|
||||
card = inputs.record;
|
||||
} else {
|
||||
let prevLabels;
|
||||
if (inputs.nextBoard) {
|
||||
if (inputs.nextBoard.projectId !== inputs.board.projectId) {
|
||||
const memberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.nextBoard.id);
|
||||
if (values.board) {
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': memberUserIds,
|
||||
},
|
||||
});
|
||||
await CardSubscription.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': memberUserIds,
|
||||
},
|
||||
});
|
||||
}
|
||||
await CardMembership.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
|
||||
|
@ -164,26 +158,28 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
card = await Card.updateOne(inputs.record.id).set(values);
|
||||
card = await Card.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (!card) {
|
||||
return card;
|
||||
}
|
||||
|
||||
if (inputs.nextBoard) {
|
||||
if (values.board) {
|
||||
const labels = await sails.helpers.boards.getLabels(card.boardId);
|
||||
const labelByNameMap = _.keyBy(labels, 'name');
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
const labelIds = await Promise.all(
|
||||
prevLabels.map(async (prevLabel) => {
|
||||
if (labelByNameMap[prevLabel.name]) {
|
||||
return labelByNameMap[prevLabel.name].id;
|
||||
prevLabels.map(async (label) => {
|
||||
if (labelByName[label.name]) {
|
||||
return labelByName[label.name].id;
|
||||
}
|
||||
|
||||
const { id } = await sails.helpers.labels.createOne(
|
||||
_.omit(prevLabel, ['id', 'boardId']),
|
||||
inputs.nextBoard,
|
||||
);
|
||||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId']),
|
||||
board: values.board,
|
||||
},
|
||||
});
|
||||
|
||||
return id;
|
||||
}),
|
||||
|
@ -225,31 +221,27 @@ module.exports = {
|
|||
);
|
||||
}
|
||||
|
||||
if (!inputs.nextBoard && inputs.nextList) {
|
||||
// TODO: add transfer action
|
||||
await sails.helpers.actions.createOne(
|
||||
{
|
||||
if (!values.board && values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
card,
|
||||
user: inputs.user,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'name']),
|
||||
toList: _.pick(inputs.nextList, ['id', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
},
|
||||
inputs.user,
|
||||
card,
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
card = inputs.record;
|
||||
|
||||
// TODO: add transfer action
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const cardSubscription = await CardSubscription.findOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.user.id,
|
||||
});
|
||||
const prevIsSubscribed = await sails.helpers.users.isCardSubscriber(inputs.user.id, card.id);
|
||||
|
||||
if (isSubscribed !== !!cardSubscription) {
|
||||
if (isSubscribed !== prevIsSubscribed) {
|
||||
if (isSubscribed) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -14,9 +23,11 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const label = await Label.create({
|
||||
...inputs.values,
|
||||
boardId: inputs.board.id,
|
||||
...values,
|
||||
boardId: values.board.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const label = await Label.updateOne(inputs.record.id).set(inputs.values);
|
||||
const { values } = inputs;
|
||||
|
||||
const label = await Label.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (label) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
exceptCardIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -22,6 +24,6 @@ module.exports = {
|
|||
};
|
||||
}
|
||||
|
||||
return sails.helpers.cards.getMany(criteria, 'position');
|
||||
return sails.helpers.cards.getMany(criteria);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,15 +27,17 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (!_.isUndefined(inputs.values.position)) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const lists = await sails.helpers.boards.getLists(inputs.record.boardId, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await List.update({
|
||||
|
@ -52,7 +56,7 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
const list = await List.updateOne(inputs.record.id).set(inputs.values);
|
||||
const list = await List.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (list) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,26 +1,42 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user) && !_.isString(value.userId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
userOrId: {
|
||||
type: 'ref',
|
||||
custom: (value) => _.isObjectLike(value) || _.isString(value),
|
||||
required: true,
|
||||
},
|
||||
action: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { userId = inputs.userOrId } = inputs.userOrId;
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.user) {
|
||||
values.userId = values.user.id;
|
||||
}
|
||||
|
||||
const notification = await Notification.create({
|
||||
userId,
|
||||
actionId: inputs.action.id,
|
||||
cardId: inputs.action.cardId,
|
||||
...values,
|
||||
actionId: values.action.id,
|
||||
cardId: values.action.cardId,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
|
||||
sails.sockets.broadcast(`user:${notification.userId}`, 'notificationCreate', {
|
||||
item: notification,
|
||||
});
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
const recordsOrIdsValidator = (value) =>
|
||||
_.every(value, _.isPlainObject) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordsOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.every(value, _.isObjectLike) || _.every(value, _.isString),
|
||||
custom: recordsOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
values: {
|
||||
|
@ -18,9 +21,11 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const criteria = {};
|
||||
|
||||
if (_.every(inputs.recordsOrIds, _.isObjectLike)) {
|
||||
if (_.every(inputs.recordsOrIds, _.isPlainObject)) {
|
||||
criteria.id = sails.helpers.utils.mapRecords(inputs.recordsOrIds);
|
||||
} else if (_.every(inputs.recordsOrIds, _.isString)) {
|
||||
criteria.id = inputs.recordsOrIds;
|
||||
|
@ -30,7 +35,9 @@ module.exports = {
|
|||
criteria.userId = inputs.user.id;
|
||||
}
|
||||
|
||||
const notifications = await Notification.update(criteria).set(inputs.values).fetch();
|
||||
const notifications = await Notification.update(criteria)
|
||||
.set({ ...values })
|
||||
.fetch();
|
||||
|
||||
notifications.forEach((notification) => {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -18,18 +31,20 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const projectManager = await ProjectManager.create({
|
||||
projectId: inputs.project.id,
|
||||
userId: inputs.user.id,
|
||||
projectId: values.project.id,
|
||||
userId: values.user.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyProjectManager')
|
||||
.fetch();
|
||||
|
||||
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
projectManager.projectId,
|
||||
);
|
||||
|
||||
userIds.forEach((userId) => {
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectManagerCreate',
|
||||
|
|
|
@ -10,14 +10,14 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
inputs.record.projectId,
|
||||
);
|
||||
|
||||
const projectManager = await ProjectManager.destroyOne(inputs.record.id);
|
||||
|
||||
if (projectManager) {
|
||||
userIds.forEach((userId) => {
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectManagerDelete',
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const project = await Project.create(inputs.values).fetch();
|
||||
const { values } = inputs;
|
||||
|
||||
const project = await Project.create({ ...values }).fetch();
|
||||
|
||||
const projectManager = await ProjectManager.create({
|
||||
projectId: project.id,
|
||||
|
|
|
@ -17,15 +17,15 @@ module.exports = {
|
|||
const project = await Project.archiveOne(inputs.record.id);
|
||||
|
||||
if (project) {
|
||||
const managerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
|
||||
const projectManagerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
|
||||
|
||||
const boardIds = await sails.helpers.projects.getBoardIds(project.id);
|
||||
const boardRooms = boardIds.map((boardId) => `board:${boardId}`);
|
||||
|
||||
const memberUserIds = await sails.helpers.boards.getMemberUserIds(boardIds);
|
||||
const userIds = _.union(managerUserIds, memberUserIds);
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(boardIds);
|
||||
const projectRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
|
||||
userIds.forEach((userId) => {
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.removeRoomMembersFromRooms(`@user:${userId}`, boardRooms);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
exceptBoardIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
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,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.idOrIds);
|
||||
const memberUserIds = await sails.helpers.projects.getBoardMemberUserIds(inputs.idOrIds);
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.idOrIds);
|
||||
const boardMemberUserIds = await sails.helpers.projects.getBoardMemberUserIds(inputs.idOrIds);
|
||||
|
||||
return _.union(managerUserIds, memberUserIds);
|
||||
return _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
const path = require('path');
|
||||
const rimraf = require('rimraf');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.background && !_.isPlainObject(value.background)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.backgroundImage && !_.isPlainObject(value.backgroundImage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -9,21 +25,7 @@ module.exports = {
|
|||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.background && !_.isPlainObject(value.background)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.backgroundImage && !_.isPlainObject(value.backgroundImage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -32,45 +34,46 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
backgroundImageMustBeNotNullInValues: {},
|
||||
backgroundImageInValuesMustNotBeNull: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (inputs.values.backgroundImage) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputs.values.background = {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.backgroundImage) {
|
||||
values.background = {
|
||||
type: 'image',
|
||||
};
|
||||
} else if (
|
||||
_.isNull(inputs.values.backgroundImage) &&
|
||||
_.isNull(values.backgroundImage) &&
|
||||
inputs.record.background &&
|
||||
inputs.record.background.type === 'image'
|
||||
) {
|
||||
inputs.values.background = null; // eslint-disable-line no-param-reassign
|
||||
values.background = null;
|
||||
}
|
||||
|
||||
let project;
|
||||
if (inputs.values.background && inputs.values.background.type === 'image') {
|
||||
if (_.isNull(inputs.values.backgroundImage)) {
|
||||
throw 'backgroundImageMustBeNotNullInValues';
|
||||
if (values.background && values.background.type === 'image') {
|
||||
if (_.isNull(values.backgroundImage)) {
|
||||
throw 'backgroundImageInValuesMustNotBeNull';
|
||||
}
|
||||
|
||||
if (_.isUndefined(inputs.values.backgroundImage)) {
|
||||
if (_.isUndefined(values.backgroundImage)) {
|
||||
project = await Project.updateOne({
|
||||
id: inputs.record.id,
|
||||
backgroundImage: {
|
||||
'!=': null,
|
||||
},
|
||||
}).set(inputs.values);
|
||||
}).set({ ...values });
|
||||
|
||||
if (!project) {
|
||||
delete inputs.values.background; // eslint-disable-line no-param-reassign
|
||||
delete values.background;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
project = await Project.updateOne(inputs.record.id).set(inputs.values);
|
||||
project = await Project.updateOne(inputs.record.id).set({ ...values });
|
||||
}
|
||||
|
||||
if (project) {
|
||||
|
@ -91,9 +94,11 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(project.id);
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
project.id,
|
||||
);
|
||||
|
||||
userIds.forEach((userId) => {
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectUpdate',
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -15,22 +27,24 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.card.id);
|
||||
const { values } = inputs;
|
||||
|
||||
const tasks = await sails.helpers.cards.getTasks(values.card.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
values.position,
|
||||
tasks,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Task.update({
|
||||
id,
|
||||
cardId: inputs.card.id,
|
||||
cardId: values.card.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.card.boardId}`, 'taskUpdate', {
|
||||
sails.sockets.broadcast(`board:${values.card.boardId}`, 'taskUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
|
@ -39,13 +53,13 @@ module.exports = {
|
|||
});
|
||||
|
||||
const task = await Task.create({
|
||||
...inputs.values,
|
||||
...values,
|
||||
position,
|
||||
cardId: inputs.card.id,
|
||||
cardId: values.card.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
`board:${values.card.boardId}`,
|
||||
'taskCreate',
|
||||
{
|
||||
item: task,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
board: {
|
||||
|
@ -29,15 +31,17 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (!_.isUndefined(inputs.values.position)) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.record.cardId, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
values.position,
|
||||
tasks,
|
||||
);
|
||||
|
||||
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Task.update({
|
||||
|
@ -56,7 +60,7 @@ module.exports = {
|
|||
});
|
||||
}
|
||||
|
||||
const task = await Task.updateOne(inputs.record.id).set(inputs.values);
|
||||
const task = await Task.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (task) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
const bcrypt = require('bcrypt');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isString(value.email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isString(value.password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.username && !_.isString(value.username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isString(value.email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isString(value.password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.username && !_.isString(value.username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -36,15 +38,16 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (inputs.values.username) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputs.values.username = inputs.values.username.toLowerCase();
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.username) {
|
||||
values.username = values.username.toLowerCase();
|
||||
}
|
||||
|
||||
const user = await User.create({
|
||||
...inputs.values,
|
||||
email: inputs.values.email.toLowerCase(),
|
||||
password: bcrypt.hashSync(inputs.values.password, 10),
|
||||
...values,
|
||||
email: values.email.toLowerCase(),
|
||||
password: bcrypt.hashSync(values.password, 10),
|
||||
})
|
||||
.intercept(
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
withDeleted: {
|
||||
type: 'boolean',
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const criteriaValidator = (value) => _.isString(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.isPlainObject(value),
|
||||
custom: criteriaValidator,
|
||||
required: true,
|
||||
},
|
||||
withDeleted: {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -3,6 +3,30 @@ const bcrypt = require('bcrypt');
|
|||
const rimraf = require('rimraf');
|
||||
const { v4: uuid } = require('uuid');
|
||||
|
||||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.email) && !_.isString(value.email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.password) && !_.isString(value.password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.username && !_.isString(value.username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.avatar && !_.isPlainObject(value.avatar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -11,29 +35,7 @@ module.exports = {
|
|||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.email) && !_.isString(value.email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.password) && !_.isString(value.password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.username && !_.isString(value.username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.avatar && !_.isPlainObject(value.avatar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
|
@ -51,34 +53,34 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (!_.isUndefined(inputs.values.email)) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputs.values.email = inputs.values.email.toLowerCase();
|
||||
const { values } = inputs;
|
||||
|
||||
if (!_.isUndefined(values.email)) {
|
||||
values.email = values.email.toLowerCase();
|
||||
}
|
||||
|
||||
let isOnlyPasswordChange = false;
|
||||
|
||||
if (!_.isUndefined(inputs.values.password)) {
|
||||
Object.assign(inputs.values, {
|
||||
password: bcrypt.hashSync(inputs.values.password, 10),
|
||||
if (!_.isUndefined(values.password)) {
|
||||
Object.assign(values, {
|
||||
password: bcrypt.hashSync(values.password, 10),
|
||||
passwordChangedAt: new Date().toUTCString(),
|
||||
});
|
||||
|
||||
if (Object.keys(inputs.values).length === 1) {
|
||||
if (Object.keys(values).length === 1) {
|
||||
isOnlyPasswordChange = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (inputs.values.username) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
inputs.values.username = inputs.values.username.toLowerCase();
|
||||
if (values.username) {
|
||||
values.username = values.username.toLowerCase();
|
||||
}
|
||||
|
||||
const user = await User.updateOne({
|
||||
id: inputs.record.id,
|
||||
deletedAt: null,
|
||||
})
|
||||
.set(inputs.values)
|
||||
.set({ ...values })
|
||||
.intercept(
|
||||
{
|
||||
message:
|
||||
|
@ -106,7 +108,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(inputs.values.password)) {
|
||||
if (!_.isUndefined(values.password)) {
|
||||
sails.sockets.broadcast(
|
||||
`user:${user.id}`,
|
||||
'userDelete', // TODO: introduce separate event
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
const recordsValidator = (value) => _.isArray(value);
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
records: {
|
||||
type: 'ref',
|
||||
custom: (value) => _.isArray(value),
|
||||
custom: recordsValidator,
|
||||
required: true,
|
||||
},
|
||||
attribute: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue