mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
ref: Remove board types, refactoring
This commit is contained in:
parent
d39da61295
commit
5cd025ffb7
182 changed files with 1573 additions and 1239 deletions
|
@ -12,16 +12,16 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const emailOrUsernameValidator = (value) =>
|
||||
value.includes('@')
|
||||
? validator.isEmail(value)
|
||||
: value.length >= 3 && value.length <= 16 && /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/.test(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
emailOrUsername: {
|
||||
type: 'string',
|
||||
custom: (value) =>
|
||||
value.includes('@')
|
||||
? validator.isEmail(value)
|
||||
: value.length >= 3 &&
|
||||
value.length <= 16 &&
|
||||
/^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/.test(value),
|
||||
custom: emailOrUsernameValidator,
|
||||
required: true,
|
||||
},
|
||||
password: {
|
||||
|
|
|
@ -82,13 +82,15 @@ module.exports = {
|
|||
const file = _.last(files);
|
||||
const fileData = await sails.helpers.attachments.processUploadedFile(file);
|
||||
|
||||
const attachment = await sails.helpers.attachments.createOne(
|
||||
fileData,
|
||||
currentUser,
|
||||
card,
|
||||
inputs.requestId,
|
||||
this.req,
|
||||
);
|
||||
const attachment = await sails.helpers.attachments.createOne.with({
|
||||
values: {
|
||||
...fileData,
|
||||
card,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
requestId: inputs.requestId,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return exits.success({
|
||||
item: attachment,
|
||||
|
|
|
@ -48,7 +48,12 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
attachment = await sails.helpers.attachments.deleteOne(attachment, board, card, this.req);
|
||||
attachment = await sails.helpers.attachments.deleteOne.with({
|
||||
board,
|
||||
card,
|
||||
record: attachment,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!attachment) {
|
||||
throw Errors.ATTACHMENT_NOT_FOUND;
|
||||
|
|
|
@ -53,7 +53,13 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['name']);
|
||||
attachment = await sails.helpers.attachments.updateOne(attachment, values, board, this.req);
|
||||
|
||||
attachment = await sails.helpers.attachments.updateOne.with({
|
||||
values,
|
||||
board,
|
||||
record: attachment,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!attachment) {
|
||||
throw Errors.ATTACHMENT_NOT_FOUND;
|
||||
|
|
|
@ -68,8 +68,15 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['role', 'canComment']);
|
||||
|
||||
const boardMembership = await sails.helpers.boardMemberships
|
||||
.createOne(values, user, board, this.req)
|
||||
const boardMembership = await sails.helpers.boardMemberships.createOne
|
||||
.with({
|
||||
values: {
|
||||
...values,
|
||||
board,
|
||||
user,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('userAlreadyBoardMember', () => Errors.USER_ALREADY_BOARD_MEMBER);
|
||||
|
||||
return {
|
||||
|
|
|
@ -36,15 +36,15 @@ module.exports = {
|
|||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.BOARD_MEMBERSHIP_NOT_FOUND;
|
||||
throw Errors.BOARD_MEMBERSHIP_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
boardMembership = await sails.helpers.boardMemberships.deleteOne(
|
||||
boardMembership,
|
||||
boardMembership = await sails.helpers.boardMemberships.deleteOne.with({
|
||||
project,
|
||||
this.req,
|
||||
);
|
||||
record: boardMembership,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_MEMBERSHIP_NOT_FOUND;
|
||||
|
|
|
@ -44,11 +44,11 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['role', 'canComment']);
|
||||
|
||||
boardMembership = await sails.helpers.boardMemberships.updateOne(
|
||||
boardMembership,
|
||||
boardMembership = await sails.helpers.boardMemberships.updateOne.with({
|
||||
values,
|
||||
this.req,
|
||||
);
|
||||
record: boardMembership,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: boardMembership,
|
||||
|
|
|
@ -20,11 +20,6 @@ module.exports = {
|
|||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
type: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Board.Types),
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
|
@ -70,7 +65,7 @@ module.exports = {
|
|||
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['type', 'position', 'name']);
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
let boardImport;
|
||||
if (inputs.importType && Object.values(Board.ImportTypes).includes(inputs.importType)) {
|
||||
|
@ -102,14 +97,16 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
const { board, boardMembership } = await sails.helpers.boards.createOne(
|
||||
values,
|
||||
boardImport,
|
||||
currentUser,
|
||||
project,
|
||||
inputs.requestId,
|
||||
this.req,
|
||||
);
|
||||
const { board, boardMembership } = await sails.helpers.boards.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
project,
|
||||
},
|
||||
import: boardImport,
|
||||
user: currentUser,
|
||||
requestId: inputs.requestId,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (this.req.isSocket) {
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
|
|
|
@ -39,7 +39,10 @@ module.exports = {
|
|||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
board = await sails.helpers.boards.deleteOne(board, this.req);
|
||||
board = await sails.helpers.boards.deleteOne.with({
|
||||
record: board,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
|
|
|
@ -47,7 +47,7 @@ module.exports = {
|
|||
const labels = await sails.helpers.boards.getLabels(board.id);
|
||||
const lists = await sails.helpers.boards.getLists(board.id);
|
||||
|
||||
const cards = await sails.helpers.boards.getCards(board);
|
||||
const cards = await sails.helpers.boards.getCards(board.id);
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const cardSubscriptions = await sails.helpers.cardSubscriptions.getMany({
|
||||
|
@ -69,7 +69,8 @@ module.exports = {
|
|||
);
|
||||
|
||||
cards.forEach((card) => {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false; // eslint-disable-line no-param-reassign
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||
});
|
||||
|
||||
if (this.req.isSocket) {
|
||||
|
|
|
@ -47,7 +47,12 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
board = await sails.helpers.boards.updateOne(board, values, this.req);
|
||||
|
||||
board = await sails.helpers.boards.updateOne.with({
|
||||
values,
|
||||
record: board,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
|
|
|
@ -71,8 +71,14 @@ module.exports = {
|
|||
throw Errors.LABEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardLabel = await sails.helpers.cardLabels
|
||||
.createOne(label, card, this.req)
|
||||
const cardLabel = await sails.helpers.cardLabels.createOne
|
||||
.with({
|
||||
values: {
|
||||
card,
|
||||
label,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('labelAlreadyInCard', () => Errors.LABEL_ALREADY_IN_CARD);
|
||||
|
||||
return {
|
||||
|
|
|
@ -65,7 +65,11 @@ module.exports = {
|
|||
throw Errors.LABEL_NOT_IN_CARD;
|
||||
}
|
||||
|
||||
cardLabel = await sails.helpers.cardLabels.deleteOne(cardLabel, board, this.req);
|
||||
cardLabel = await sails.helpers.cardLabels.deleteOne.with({
|
||||
board,
|
||||
record: cardLabel,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!cardLabel) {
|
||||
throw Errors.LABEL_NOT_IN_CARD;
|
||||
|
|
|
@ -68,8 +68,14 @@ module.exports = {
|
|||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardMembership = await sails.helpers.cardMemberships
|
||||
.createOne(inputs.userId, card, this.req)
|
||||
const cardMembership = await sails.helpers.cardMemberships.createOne
|
||||
.with({
|
||||
values: {
|
||||
card,
|
||||
userId: inputs.userId,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('userAlreadyCardMember', () => Errors.USER_ALREADY_CARD_MEMBER);
|
||||
|
||||
return {
|
||||
|
|
|
@ -65,7 +65,11 @@ module.exports = {
|
|||
throw Errors.USER_NOT_CARD_MEMBER;
|
||||
}
|
||||
|
||||
cardMembership = await sails.helpers.cardMemberships.deleteOne(cardMembership, board, this.req);
|
||||
cardMembership = await sails.helpers.cardMemberships.deleteOne.with({
|
||||
board,
|
||||
record: cardMembership,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!cardMembership) {
|
||||
throw Errors.USER_NOT_CARD_MEMBER;
|
||||
|
|
|
@ -4,30 +4,42 @@ const Errors = {
|
|||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
LIST_MUST_BE_PRESENT: {
|
||||
listMustBePresent: 'List must be present',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
const dueDateValidator = (value) => moment(value, moment.ISO_8601, true).isValid();
|
||||
|
||||
const timerValidator = (value) => {
|
||||
if (!_.isPlainObject(value) || _.size(value) !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!_.isNull(value.startedAt) &&
|
||||
_.isString(value.startedAt) &&
|
||||
!moment(value.startedAt, moment.ISO_8601, true).isValid()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.total)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
boardId: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
listId: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
|
@ -43,29 +55,11 @@ module.exports = {
|
|||
},
|
||||
dueDate: {
|
||||
type: 'string',
|
||||
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
|
||||
custom: dueDateValidator,
|
||||
},
|
||||
timer: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value) || _.size(value) !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!_.isNull(value.startedAt) &&
|
||||
_.isString(value.startedAt) &&
|
||||
!moment(value.startedAt, moment.ISO_8601, true).isValid()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.total)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: timerValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -73,15 +67,9 @@ module.exports = {
|
|||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
|
@ -90,40 +78,34 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board } = await sails.helpers.boards
|
||||
.getProjectPath(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
const { list } = await sails.helpers.lists
|
||||
.getProjectPath(inputs.listId)
|
||||
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.findOne({
|
||||
boardId: board.id,
|
||||
boardId: list.boardId,
|
||||
userId: currentUser.id,
|
||||
});
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let list;
|
||||
if (!_.isUndefined(inputs.listId)) {
|
||||
list = await List.findOne({
|
||||
id: inputs.listId,
|
||||
boardId: board.id,
|
||||
});
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name', 'description', 'dueDate', 'timer']);
|
||||
|
||||
const card = await sails.helpers.cards
|
||||
.createOne(values, currentUser, board, list, this.req)
|
||||
.intercept('listMustBePresent', () => Errors.LIST_MUST_BE_PRESENT)
|
||||
const card = await sails.helpers.cards.createOne
|
||||
.with({
|
||||
values: {
|
||||
...values,
|
||||
list,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT);
|
||||
|
||||
return {
|
||||
|
|
|
@ -45,7 +45,10 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
card = await sails.helpers.cards.deleteOne(card, this.req);
|
||||
card = await sails.helpers.cards.deleteOne.with({
|
||||
record: card,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
boardId: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
beforeId: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board } = await sails.helpers.boards
|
||||
.getProjectPath(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
|
||||
|
||||
if (!isBoardMember) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.boards.getCards(board, inputs.beforeId);
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const cardSubscriptions = await sails.helpers.cardSubscriptions.getMany({
|
||||
cardId: cardIds,
|
||||
userId: currentUser.id,
|
||||
});
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
...result,
|
||||
[cardSubscription.cardId]: true,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
cards.forEach((card) => {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false; // eslint-disable-line no-param-reassign
|
||||
});
|
||||
|
||||
const cardMemberships = await sails.helpers.cards.getCardMemberships(cardIds);
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(cardIds);
|
||||
const tasks = await sails.helpers.cards.getTasks(cardIds);
|
||||
const attachments = await sails.helpers.cards.getAttachments(cardIds);
|
||||
|
||||
return {
|
||||
items: cards,
|
||||
included: {
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
tasks,
|
||||
attachments,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
|
@ -21,6 +21,28 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const dueDateValidator = (value) => moment(value, moment.ISO_8601, true).isValid();
|
||||
|
||||
const timerValidator = (value) => {
|
||||
if (!_.isPlainObject(value) || _.size(value) !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!_.isNull(value.startedAt) &&
|
||||
_.isString(value.startedAt) &&
|
||||
!moment(value.startedAt, moment.ISO_8601, true).isValid()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.total)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
|
@ -55,30 +77,12 @@ module.exports = {
|
|||
},
|
||||
dueDate: {
|
||||
type: 'string',
|
||||
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
|
||||
custom: dueDateValidator,
|
||||
allowNull: true,
|
||||
},
|
||||
timer: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (!_.isPlainObject(value) || _.size(value) !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!_.isNull(value.startedAt) &&
|
||||
_.isString(value.startedAt) &&
|
||||
!moment(value.startedAt, moment.ISO_8601, true).isValid()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.total)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
custom: timerValidator,
|
||||
},
|
||||
isSubscribed: {
|
||||
type: 'boolean',
|
||||
|
@ -171,10 +175,21 @@ module.exports = {
|
|||
'isSubscribed',
|
||||
]);
|
||||
|
||||
card = await sails.helpers.cards
|
||||
.updateOne(card, values, nextBoard, nextList, currentUser, board, list, this.req)
|
||||
.intercept('nextListMustBePresent', () => Errors.LIST_MUST_BE_PRESENT)
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT);
|
||||
card = await sails.helpers.cards.updateOne
|
||||
.with({
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
board: nextBoard,
|
||||
list: nextList,
|
||||
},
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)
|
||||
.intercept('listMustBeInValues', () => Errors.LIST_MUST_BE_PRESENT);
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
|
|
|
@ -54,7 +54,14 @@ module.exports = {
|
|||
data: _.pick(inputs, ['text']),
|
||||
};
|
||||
|
||||
const action = await sails.helpers.actions.createOne(values, currentUser, card, this.req);
|
||||
const action = await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
card,
|
||||
user: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: action,
|
||||
|
|
|
@ -59,7 +59,11 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
action = await sails.helpers.actions.deleteOne(action, board, this.req);
|
||||
action = await sails.helpers.actions.deleteOne.with({
|
||||
board,
|
||||
record: action,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!action) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND;
|
||||
|
|
|
@ -67,7 +67,12 @@ module.exports = {
|
|||
data: _.pick(inputs, ['text']),
|
||||
};
|
||||
|
||||
action = await sails.helpers.actions.updateOne(action, values, board, this.req);
|
||||
action = await sails.helpers.actions.updateOne.with({
|
||||
values,
|
||||
board,
|
||||
record: action,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!action) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND;
|
||||
|
|
|
@ -56,7 +56,14 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
const label = await sails.helpers.labels.createOne(values, board, this.req);
|
||||
|
||||
const label = await sails.helpers.labels.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
board,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: label,
|
||||
|
|
|
@ -45,7 +45,10 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
label = await sails.helpers.labels.deleteOne(label, this.req);
|
||||
label = await sails.helpers.labels.deleteOne.with({
|
||||
record: label,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!label) {
|
||||
throw Errors.LABEL_NOT_FOUND;
|
||||
|
|
|
@ -56,7 +56,12 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
label = await sails.helpers.labels.updateOne(label, values, this.req);
|
||||
|
||||
label = await sails.helpers.labels.updateOne.with({
|
||||
values,
|
||||
record: label,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: label,
|
||||
|
|
|
@ -54,7 +54,14 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
const list = await sails.helpers.lists.createOne(values, board, this.req);
|
||||
|
||||
const list = await sails.helpers.lists.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
board,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: list,
|
||||
|
|
|
@ -45,7 +45,10 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
list = await sails.helpers.lists.deleteOne(list, this.req);
|
||||
list = await sails.helpers.lists.deleteOne.with({
|
||||
record: list,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
|
|
|
@ -53,7 +53,12 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
list = await sails.helpers.lists.updateOne(list, values, this.req);
|
||||
|
||||
list = await sails.helpers.lists.updateOne.with({
|
||||
values,
|
||||
record: list,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
|
|
|
@ -15,12 +15,12 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['isRead']);
|
||||
|
||||
const notifications = await sails.helpers.notifications.updateMany(
|
||||
inputs.ids.split(','),
|
||||
const notifications = await sails.helpers.notifications.updateMany.with({
|
||||
values,
|
||||
currentUser,
|
||||
this.req,
|
||||
);
|
||||
recordsOrIds: inputs.ids.split(','),
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
items: notifications,
|
||||
|
|
|
@ -57,8 +57,14 @@ module.exports = {
|
|||
throw Error.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const projectManager = await sails.helpers.projectManagers
|
||||
.createOne(user, project, this.req)
|
||||
const projectManager = await sails.helpers.projectManagers.createOne
|
||||
.with({
|
||||
values: {
|
||||
project,
|
||||
user,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('userAlreadyProjectManager', () => Errors.USER_ALREADY_PROJECT_MANAGER);
|
||||
|
||||
return {
|
||||
|
|
|
@ -38,7 +38,10 @@ module.exports = {
|
|||
}
|
||||
|
||||
// TODO: check if the last one
|
||||
projectManager = await sails.helpers.projectManagers.deleteOne(projectManager, this.req);
|
||||
projectManager = await sails.helpers.projectManagers.deleteOne.with({
|
||||
record: projectManager,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!projectManager) {
|
||||
throw Errors.PROJECT_MANAGER_NOT_FOUND;
|
||||
|
|
|
@ -11,11 +11,11 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['name']);
|
||||
|
||||
const { project, projectManager } = await sails.helpers.projects.createOne(
|
||||
const { project, projectManager } = await sails.helpers.projects.createOne.with({
|
||||
values,
|
||||
currentUser,
|
||||
this.req,
|
||||
);
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: project,
|
||||
|
|
|
@ -34,7 +34,10 @@ module.exports = {
|
|||
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
project = await sails.helpers.projects.deleteOne(project, this.req);
|
||||
project = await sails.helpers.projects.deleteOne.with({
|
||||
record: project,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
|
|
|
@ -6,7 +6,6 @@ module.exports = {
|
|||
const managerProjects = await sails.helpers.projects.getMany(managerProjectIds);
|
||||
|
||||
let boardMemberships = await sails.helpers.users.getBoardMemberships(currentUser.id);
|
||||
|
||||
const membershipBoardIds = sails.helpers.utils.mapRecords(boardMemberships, 'boardId');
|
||||
|
||||
let membershipBoards = await sails.helpers.boards.getMany({
|
||||
|
|
|
@ -85,13 +85,13 @@ module.exports = {
|
|||
return Errors.FILE_IS_NOT_IMAGE;
|
||||
});
|
||||
|
||||
project = await sails.helpers.projects.updateOne(
|
||||
project,
|
||||
{
|
||||
project = await sails.helpers.projects.updateOne.with({
|
||||
record: project,
|
||||
values: {
|
||||
backgroundImage: fileData,
|
||||
},
|
||||
this.req,
|
||||
);
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
|
|
|
@ -4,6 +4,36 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const backgroundValidator = (value) => {
|
||||
if (_.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Object.values(Project.BackgroundTypes).includes(value.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
value.type === Project.BackgroundTypes.GRADIENT &&
|
||||
_.size(value) === 2 &&
|
||||
Project.BACKGROUND_GRADIENTS.includes(value.name)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value.type === Project.BackgroundTypes.IMAGE && _.size(value) === 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const backgroundImageValidator = (value) => _.isNull(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
|
@ -17,37 +47,11 @@ module.exports = {
|
|||
},
|
||||
background: {
|
||||
type: 'json',
|
||||
custom: (value) => {
|
||||
if (_.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Object.values(Project.BackgroundTypes).includes(value.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
value.type === Project.BackgroundTypes.GRADIENT &&
|
||||
_.size(value) === 2 &&
|
||||
Project.BACKGROUND_GRADIENTS.includes(value.name)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value.type === Project.BackgroundTypes.IMAGE && _.size(value) === 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
custom: backgroundValidator,
|
||||
},
|
||||
backgroundImage: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isNull(value),
|
||||
custom: backgroundImageValidator,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -73,7 +77,12 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'background', 'backgroundImage']);
|
||||
project = await sails.helpers.projects.updateOne(project, values, this.req);
|
||||
|
||||
project = await sails.helpers.projects.updateOne.with({
|
||||
values,
|
||||
record: project,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
|
|
|
@ -57,7 +57,14 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
const task = await sails.helpers.tasks.createOne(values, card, this.req);
|
||||
|
||||
const task = await sails.helpers.tasks.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
card,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return {
|
||||
item: task,
|
||||
|
|
|
@ -48,7 +48,11 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
task = await sails.helpers.tasks.deleteOne(task, board, this.req);
|
||||
task = await sails.helpers.tasks.deleteOne.with({
|
||||
board,
|
||||
record: task,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!task) {
|
||||
throw Errors.TASK_NOT_FOUND;
|
||||
|
|
|
@ -59,7 +59,13 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
task = await sails.helpers.tasks.updateOne(task, values, board, this.req);
|
||||
|
||||
task = await sails.helpers.tasks.updateOne.with({
|
||||
values,
|
||||
board,
|
||||
record: task,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!task) {
|
||||
throw Errors.TASK_NOT_FOUND;
|
||||
|
|
|
@ -9,6 +9,8 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const passwordValidator = (value) => zxcvbn(value).score >= 2; // TODO: move to config
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
email: {
|
||||
|
@ -18,7 +20,7 @@ module.exports = {
|
|||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
custom: (value) => zxcvbn(value).score >= 2, // TODO: move to config
|
||||
custom: passwordValidator,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
|
@ -74,8 +76,11 @@ module.exports = {
|
|||
'subscribeToOwnCards',
|
||||
]);
|
||||
|
||||
const user = await sails.helpers.users
|
||||
.createOne(values, this.req)
|
||||
const user = await sails.helpers.users.createOne
|
||||
.with({
|
||||
values,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
|
||||
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
|
||||
|
||||
|
|
|
@ -26,7 +26,10 @@ module.exports = {
|
|||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
user = await sails.helpers.users.deleteOne(user, this.req);
|
||||
user = await sails.helpers.users.deleteOne.with({
|
||||
record: user,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
|
|
|
@ -86,14 +86,14 @@ module.exports = {
|
|||
return Errors.FILE_IS_NOT_IMAGE;
|
||||
});
|
||||
|
||||
user = await sails.helpers.users.updateOne(
|
||||
user,
|
||||
{
|
||||
user = await sails.helpers.users.updateOne.with({
|
||||
record: user,
|
||||
values: {
|
||||
avatar: fileData,
|
||||
},
|
||||
currentUser,
|
||||
this.req,
|
||||
);
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
|
|
|
@ -68,8 +68,13 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['email']);
|
||||
|
||||
user = await sails.helpers.users
|
||||
.updateOne(user, values, currentUser, this.req)
|
||||
user = await sails.helpers.users.updateOne
|
||||
.with({
|
||||
values,
|
||||
record: user,
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE);
|
||||
|
||||
if (!user) {
|
||||
|
|
|
@ -12,6 +12,8 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const passwordValidator = (value) => zxcvbn(value).score >= 2; // TODO: move to config
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
|
@ -21,7 +23,7 @@ module.exports = {
|
|||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
custom: (value) => zxcvbn(value).score >= 2, // TODO: move to config
|
||||
custom: passwordValidator,
|
||||
required: true,
|
||||
},
|
||||
currentPassword: {
|
||||
|
@ -64,7 +66,13 @@ module.exports = {
|
|||
}
|
||||
|
||||
const values = _.pick(inputs, ['password']);
|
||||
user = await sails.helpers.users.updateOne(user, values, currentUser, this.req);
|
||||
|
||||
user = await sails.helpers.users.updateOne.with({
|
||||
values,
|
||||
record: user,
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
|
|
|
@ -70,8 +70,13 @@ module.exports = {
|
|||
|
||||
const values = _.pick(inputs, ['username']);
|
||||
|
||||
user = await sails.helpers.users
|
||||
.updateOne(user, values, currentUser, this.req)
|
||||
user = await sails.helpers.users.updateOne
|
||||
.with({
|
||||
values,
|
||||
record: user,
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
|
||||
|
||||
if (!user) {
|
||||
|
|
|
@ -4,6 +4,8 @@ const Errors = {
|
|||
},
|
||||
};
|
||||
|
||||
const avatarUrlValidator = (value) => _.isNull(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
|
@ -20,7 +22,7 @@ module.exports = {
|
|||
},
|
||||
avatarUrl: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isNull(value),
|
||||
custom: avatarUrlValidator,
|
||||
},
|
||||
phone: {
|
||||
type: 'string',
|
||||
|
@ -77,7 +79,12 @@ module.exports = {
|
|||
avatar: inputs.avatarUrl,
|
||||
};
|
||||
|
||||
user = await sails.helpers.users.updateOne(user, values, currentUser, this.req);
|
||||
user = await sails.helpers.users.updateOne.with({
|
||||
values,
|
||||
record: user,
|
||||
user: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue