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

Project managers, board members, auto-update after reconnection, refactoring

This commit is contained in:
Maksim Eltyshev 2021-06-24 01:05:22 +05:00
parent d6cb1f6683
commit b39119ace4
478 changed files with 21226 additions and 19495 deletions

View file

@ -0,0 +1,47 @@
module.exports = {
inputs: {
values: {
type: 'json',
required: true,
},
user: {
type: 'ref',
required: true,
},
card: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const action = await Action.create({
...inputs.values,
cardId: inputs.card.id,
userId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`board:${inputs.card.boardId}`,
'actionCreate',
{
item: action,
},
inputs.request,
);
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
action.cardId,
action.userId,
);
subscriptionUserIds.forEach(async (userId) => {
await sails.helpers.notifications.createOne(userId, action);
});
return action;
},
};

View file

@ -13,7 +13,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const action = await Action.archiveOne(inputs.record.id);
if (action) {
@ -27,6 +27,6 @@ module.exports = {
);
}
return exits.success(action);
return action;
},
};

View file

@ -9,9 +9,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const actions = await Action.find(inputs.criteria).sort('id DESC').limit(inputs.limit);
return exits.success(actions);
async fn(inputs) {
return Action.find(inputs.criteria).sort('id DESC').limit(inputs.limit);
},
};

View file

@ -10,15 +10,15 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const action = await Action.findOne(inputs.criteria);
if (!action) {
throw 'pathNotFound';
}
const path = await sails.helpers
.getCardToProjectPath(action.cardId)
const path = await sails.helpers.cards
.getProjectPath(action.cardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
action,
@ -26,9 +26,9 @@ module.exports = {
},
}));
return exits.success({
return {
action,
...path,
});
};
},
};

View file

@ -17,7 +17,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const action = await Action.updateOne(inputs.record.id).set(inputs.values);
if (action) {
@ -31,6 +31,6 @@ module.exports = {
);
}
return exits.success(action);
return action;
},
};

View file

@ -1,33 +1,31 @@
module.exports = {
inputs: {
card: {
type: 'ref',
values: {
type: 'json',
required: true,
},
user: {
type: 'ref',
required: true,
},
values: {
type: 'json',
card: {
type: 'ref',
required: true,
},
requestId: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
defaultsTo: null,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
async fn(inputs) {
const attachment = await Attachment.create({
...inputs.values,
cardId: inputs.card.id,
userId: inputs.user.id,
creatorUserId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
@ -41,14 +39,11 @@ module.exports = {
);
if (!inputs.card.coverAttachmentId && attachment.isImage) {
await sails.helpers.updateCard.with({
record: inputs.card,
values: {
coverAttachmentId: attachment.id,
},
await sails.helpers.cards.updateOne(inputs.card, {
coverAttachmentId: attachment.id,
});
}
return exits.success(attachment);
return attachment;
},
};

View file

@ -7,11 +7,11 @@ module.exports = {
type: 'ref',
required: true,
},
card: {
board: {
type: 'ref',
required: true,
},
board: {
card: {
type: 'ref',
required: true,
},
@ -20,9 +20,9 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
if (inputs.record.id === inputs.card.coverAttachmentId) {
await sails.helpers.updateCard.with({
await sails.helpers.cards.updateOne.with({
record: inputs.card,
values: {
coverAttachmentId: null,
@ -50,6 +50,6 @@ module.exports = {
);
}
return exits.success(attachment);
return attachment;
},
};

View file

@ -6,9 +6,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const tasks = await Task.find(inputs.criteria).sort('id');
return exits.success(tasks);
async fn(inputs) {
return Attachment.find(inputs.criteria).sort('id');
},
};

View file

@ -10,15 +10,15 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const attachment = await Attachment.findOne(inputs.criteria);
if (!attachment) {
throw 'pathNotFound';
}
const path = await sails.helpers
.getCardToProjectPath(attachment.cardId)
const path = await sails.helpers.cards
.getProjectPath(attachment.cardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
attachment,
@ -26,9 +26,9 @@ module.exports = {
},
}));
return exits.success({
return {
attachment,
...path,
});
};
},
};

View file

@ -17,7 +17,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const attachment = await Attachment.updateOne(inputs.record.id).set(inputs.values);
if (attachment) {
@ -31,6 +31,6 @@ module.exports = {
);
}
return exits.success(attachment);
return attachment;
},
};

View file

@ -0,0 +1,48 @@
module.exports = {
inputs: {
user: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
exits: {
userAlreadyBoardMember: {},
},
async fn(inputs) {
const boardMembership = await BoardMembership.create({
boardId: inputs.board.id,
userId: inputs.user.id,
})
.intercept('E_UNIQUE', 'userAlreadyBoardMember')
.fetch();
sails.sockets.broadcast(
`user:${boardMembership.userId}`,
'boardMembershipCreate',
{
item: boardMembership,
},
inputs.request,
);
sails.sockets.broadcast(
`board:${boardMembership.boardId}`,
'boardMembershipCreate',
{
item: boardMembership,
},
inputs.request,
);
return boardMembership;
},
};

View file

@ -0,0 +1,71 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const cardIds = await sails.helpers.boards.getCardIds(inputs.record.boardId);
await CardSubscription.destroy({
cardId: cardIds,
userId: inputs.record.userId,
});
await CardMembership.destroy({
cardId: cardIds,
userId: inputs.record.userId,
});
const boardMembership = await BoardMembership.destroyOne(inputs.record.id);
if (boardMembership) {
sails.sockets.broadcast(
`user:${boardMembership.userId}`,
'boardMembershipDelete',
{
item: boardMembership,
},
inputs.request,
);
const notifyBoard = () => {
sails.sockets.broadcast(
`board:${boardMembership.boardId}`,
'boardMembershipDelete',
{
item: boardMembership,
},
inputs.request,
);
};
const isProjectManager = await sails.helpers.users.isProjectManager(
inputs.record.userId,
inputs.project.id,
);
if (isProjectManager) {
notifyBoard();
} else {
// TODO: also remove if unsubscribed to user
sails.sockets.removeRoomMembersFromRooms(
`user:${boardMembership.userId}`,
`board:${boardMembership.boardId}`,
notifyBoard,
);
}
}
return boardMembership;
},
};

View file

@ -6,9 +6,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const labels = await Label.find(inputs.criteria).sort('id');
return exits.success(labels);
async fn(inputs) {
return BoardMembership.find(inputs.criteria).sort('id');
},
};

View file

@ -0,0 +1,34 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
required: true,
},
},
exits: {
pathNotFound: {},
},
async fn(inputs) {
const boardMembership = await BoardMembership.findOne(inputs.criteria);
if (!boardMembership) {
throw 'pathNotFound';
}
const path = await sails.helpers.boards
.getProjectPath(boardMembership.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
boardMembership,
...nodes,
},
}));
return {
boardMembership,
...path,
};
},
};

View file

@ -1,29 +1,32 @@
module.exports = {
inputs: {
project: {
type: 'ref',
required: true,
},
values: {
type: 'json',
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
user: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const boards = await sails.helpers.getBoardsForProject(inputs.project.id);
async fn(inputs) {
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.project.id);
const boards = await sails.helpers.projects.getBoards(inputs.project.id);
const { position, repositions } = sails.helpers.insertToPositionables(
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
boards,
);
const userIds = await sails.helpers.getMembershipUserIdsForProject(inputs.project.id);
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
@ -32,6 +35,9 @@ module.exports = {
position: nextPosition,
});
const memberUserIds = await sails.helpers.boards.getMemberUserIds(id);
const userIds = _.union(managerUserIds, memberUserIds);
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
@ -48,21 +54,25 @@ module.exports = {
projectId: inputs.project.id,
}).fetch();
userIds.forEach((userId) => {
const boardMembership = await BoardMembership.create({
boardId: board.id,
userId: inputs.user.id,
}).fetch();
managerUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',
{
item: board,
included: {
lists: [],
labels: [],
},
},
inputs.request,
);
});
return exits.success(board);
return {
board,
boardMembership,
};
},
};

View file

@ -0,0 +1,30 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const board = await Board.archiveOne(inputs.record.id);
if (board) {
sails.sockets.leaveAll(`board:${board.id}`);
sails.sockets.broadcast(
`project:${board.projectId}`,
'boardDelete',
{
item: board,
},
inputs.request,
);
}
return board;
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.boardMemberships.getMany({
boardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const cards = await sails.helpers.boards.getCards(inputs.idOrIds);
return sails.helpers.utils.mapRecords(cards);
},
};

View file

@ -2,7 +2,7 @@ const LIMIT = 10;
module.exports = {
inputs: {
recordOrId: {
recordOrIdOrIds: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value) || _.every(value, _.isString),
required: true,
@ -12,18 +12,18 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const criteria = {};
let sort;
let limit;
if (_.isObjectLike(inputs.recordOrId)) {
criteria.boardId = inputs.recordOrId.id;
if (_.isObjectLike(inputs.recordOrIdOrIds)) {
criteria.boardId = inputs.recordOrIdOrIds.id;
if (inputs.recordOrId.type === 'kanban') {
if (inputs.recordOrIdOrIds.type === Board.Types.KANBAN) {
sort = 'position';
} else if (inputs.recordOrId.type === 'collection') {
} else if (inputs.recordOrIdOrIds.type === Board.Types.COLLECTION) {
if (inputs.beforeId) {
criteria.id = {
'<': inputs.beforeId,
@ -33,11 +33,9 @@ module.exports = {
limit = LIMIT;
}
} else {
criteria.boardId = inputs.recordOrId;
criteria.boardId = inputs.recordOrIdOrIds;
}
const cards = await sails.helpers.getCards(criteria, sort, limit);
return exits.success(cards);
return sails.helpers.cards.getMany(criteria, sort, limit);
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.labels.getMany({
boardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,27 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
exceptListIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
},
},
async fn(inputs) {
const criteria = {
boardId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.exceptListIdOrIds)) {
criteria.id = {
'!=': inputs.exceptListIdOrIds,
};
}
return sails.helpers.lists.getMany(criteria);
},
};

View file

@ -6,9 +6,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const boards = await Board.find(inputs.criteria).sort('position');
return exits.success(boards);
async fn(inputs) {
return Board.find(inputs.criteria).sort('position');
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const boardMemberships = await sails.helpers.boards.getBoardMemberships(inputs.idOrIds);
return sails.helpers.utils.mapRecords(boardMemberships, 'userId', _.isArray(inputs.idOrIds));
},
};

View file

@ -10,7 +10,7 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const board = await Board.findOne(inputs.criteria);
if (!board) {
@ -27,9 +27,9 @@ module.exports = {
};
}
return exits.success({
return {
board,
project,
});
};
},
};

View file

@ -24,16 +24,18 @@ module.exports = {
},
},
async fn(inputs, exits) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(inputs.record.projectId);
async fn(inputs) {
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
inputs.record.projectId,
);
if (!_.isUndefined(inputs.values.position)) {
const boards = await sails.helpers.getBoardsForProject(
const boards = await sails.helpers.projects.getBoards(
inputs.record.projectId,
inputs.record.id,
);
const { position, repositions } = sails.helpers.insertToPositionables(
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
boards,
);
@ -74,6 +76,6 @@ module.exports = {
});
}
return exits.success(board);
return board;
},
};

View file

@ -1,10 +1,10 @@
module.exports = {
inputs: {
card: {
label: {
type: 'ref',
required: true,
},
label: {
card: {
type: 'ref',
required: true,
},
@ -17,7 +17,7 @@ module.exports = {
labelAlreadyInCard: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const cardLabel = await CardLabel.create({
cardId: inputs.card.id,
labelId: inputs.label.id,
@ -34,6 +34,6 @@ module.exports = {
inputs.request,
);
return exits.success(cardLabel);
return cardLabel;
},
};

View file

@ -13,7 +13,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const cardLabel = await CardLabel.destroyOne(inputs.record.id);
if (cardLabel) {
@ -27,6 +27,6 @@ module.exports = {
);
}
return exits.success(cardLabel);
return cardLabel;
},
};

View file

@ -6,9 +6,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const projects = await Project.find(inputs.criteria).sort('id');
return exits.success(projects);
async fn(inputs) {
return CardLabel.find(inputs.criteria).sort('id');
},
};

View file

@ -1,14 +1,14 @@
module.exports = {
inputs: {
card: {
type: 'ref',
required: true,
},
userOrUserId: {
userOrId: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value),
required: true,
},
card: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
@ -18,8 +18,8 @@ module.exports = {
userAlreadyCardMember: {},
},
async fn(inputs, exits) {
const { userId = inputs.userOrUserId } = inputs.userOrUserId;
async fn(inputs) {
const { userId = inputs.userOrId } = inputs.userOrId;
const cardMembership = await CardMembership.create({
userId,
@ -59,6 +59,6 @@ module.exports = {
);
}
return exits.success(cardMembership);
return cardMembership;
},
};

View file

@ -13,7 +13,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const cardMembership = await CardMembership.destroyOne(inputs.record.id);
if (cardMembership) {
@ -42,6 +42,6 @@ module.exports = {
}
}
return exits.success(cardMembership);
return cardMembership;
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return CardMembership.find(inputs.criteria).sort('id');
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return CardSubscription.find(inputs.criteria).sort('id');
},
};

View file

@ -1,12 +1,5 @@
module.exports = {
inputs: {
board: {
type: 'ref',
required: true,
},
list: {
type: 'ref',
},
values: {
type: 'json',
custom: (value) => {
@ -26,6 +19,13 @@ module.exports = {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
list: {
type: 'ref',
},
request: {
type: 'ref',
},
@ -37,12 +37,10 @@ module.exports = {
positionMustBeInValues: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const { values } = inputs;
values.boardId = inputs.board.id;
if (inputs.board.type === 'kanban') {
if (inputs.board.type === Board.Types.KANBAN) {
if (!inputs.list) {
throw 'listMustBePresent';
}
@ -57,9 +55,9 @@ module.exports = {
throw 'positionMustBeInValues';
}
const cards = await sails.helpers.getCardsForList(inputs.list.id);
const cards = await sails.helpers.lists.getCards(inputs.list.id);
const { position, repositions } = sails.helpers.insertToPositionables(
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
cards,
);
@ -81,11 +79,24 @@ module.exports = {
});
values.position = position;
} else if (inputs.board.type === 'collection') {
} else if (inputs.board.type === Board.Types.COLLECTION) {
delete values.position;
}
const card = await Card.create(values).fetch();
const card = await Card.create({
...values,
boardId: inputs.board.id,
creatorUserId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`board:${card.boardId}`,
'cardCreate',
{
item: card,
},
inputs.request,
);
if (inputs.user.subscribeToOwnCards) {
await CardSubscription.create({
@ -93,34 +104,25 @@ module.exports = {
userId: inputs.user.id,
}).tolerate('E_UNIQUE');
card.isSubscribed = true;
} else {
card.isSubscribed = false;
sails.sockets.broadcast(`user:${inputs.user.id}`, 'cardUpdate', {
item: {
id: card.id,
isSubscribed: true,
},
});
}
// FIXME: broadcast subscription separately
sails.sockets.broadcast(
`board:${card.boardId}`,
'cardCreate',
await sails.helpers.actions.createOne(
{
item: card,
included: {
cardMemberships: [],
cardLabels: [],
tasks: [],
attachments: [],
type: Action.Types.CREATE_CARD,
data: {
list: _.pick(inputs.list, ['id', 'name']),
},
},
inputs.request,
inputs.user,
card,
);
await sails.helpers.createAction(card, inputs.user, {
type: 'createCard',
data: {
list: _.pick(inputs.list, ['id', 'name']),
},
});
return exits.success(card);
return card;
},
};

View file

@ -9,7 +9,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const card = await Card.archiveOne(inputs.record.id);
if (card) {
@ -23,6 +23,6 @@ module.exports = {
);
}
return exits.success(card);
return card;
},
};

View file

@ -2,9 +2,9 @@ const LIMIT = 10;
module.exports = {
inputs: {
id: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
beforeId: {
@ -12,9 +12,9 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const criteria = {
cardId: inputs.id,
cardId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.beforeId)) {
@ -23,8 +23,6 @@ module.exports = {
};
}
const actions = await sails.helpers.getActions(criteria, LIMIT);
return exits.success(actions);
return sails.helpers.actions.getMany(criteria, LIMIT);
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.attachments.getMany({
cardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.cardLabels.getMany({
cardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.cardMemberships.getMany({
cardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,27 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
exceptUserIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
},
},
async fn(inputs) {
const criteria = {
cardId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.exceptUserIdOrIds)) {
criteria.userId = {
'!=': inputs.exceptUserIdOrIds,
};
}
return sails.helpers.cardSubscriptions.getMany(criteria);
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const cardLabels = await sails.helpers.cards.getCardLabels(inputs.idOrIds);
return sails.helpers.utils.mapRecords(cardLabels, 'labelId', _.isArray(inputs.idOrIds));
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const labelIds = await sails.helpers.cards.getLabelIds(inputs.idOrIds);
return sails.helpers.labels.getMany(labelIds);
},
};

View file

@ -13,9 +13,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
const cards = await Card.find(inputs.criteria).sort(inputs.sort).limit(inputs.limit);
return exits.success(cards);
async fn(inputs) {
return Card.find(inputs.criteria).sort(inputs.sort).limit(inputs.limit);
},
};

View file

@ -10,7 +10,7 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const card = await Card.findOne(inputs.criteria);
if (!card) {
@ -19,8 +19,8 @@ module.exports = {
let path;
if (card.listId) {
path = await sails.helpers
.getListToProjectPath(card.listId)
path = await sails.helpers.lists
.getProjectPath(card.listId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
card,
@ -28,8 +28,8 @@ module.exports = {
},
}));
} else {
path = await sails.helpers
.getBoardToProjectPath(card.boardId)
path = await sails.helpers.boards
.getProjectPath(card.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
card,
@ -38,9 +38,9 @@ module.exports = {
}));
}
return exits.success({
return {
card,
...path,
});
};
},
};

View file

@ -0,0 +1,22 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
exceptUserIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
},
},
async fn(inputs) {
const cardSubscriptions = await sails.helpers.cards.getCardSubscriptions(
inputs.idOrIds,
inputs.exceptUserIdOrIds,
);
return sails.helpers.utils.mapRecords(cardSubscriptions, 'userId', _.isArray(inputs.idOrIds));
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.tasks.getMany({
cardId: inputs.idOrIds,
});
},
};

View file

@ -4,12 +4,6 @@ module.exports = {
type: 'ref',
required: true,
},
toBoard: {
type: 'ref',
},
toList: {
type: 'ref',
},
values: {
type: 'json',
custom: (value) => {
@ -23,7 +17,16 @@ module.exports = {
return true;
},
required: true,
defaultsTo: {},
},
nextBoard: {
type: 'ref',
},
nextList: {
type: 'ref',
},
user: {
type: 'ref',
},
board: {
type: 'ref',
@ -31,9 +34,6 @@ module.exports = {
list: {
type: 'ref',
},
user: {
type: 'ref',
},
request: {
type: 'ref',
},
@ -42,66 +42,66 @@ module.exports = {
exits: {
boardMustBePresent: {},
listMustBePresent: {},
toListMustBelongToBoard: {},
toListMustBePresent: {},
nextListMustBelongToBoard: {},
nextListMustBePresent: {},
positionMustBeInValues: {},
userMustBePresent: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const { isSubscribed, ...values } = inputs.values;
if (inputs.toBoard || inputs.toList || !_.isUndefined(values.position)) {
if (inputs.nextBoard || inputs.nextList || !_.isUndefined(values.position)) {
if (!inputs.board) {
throw 'boardMustBePresent';
}
if (inputs.toBoard) {
if (inputs.toBoard.id === inputs.board.id) {
delete inputs.toBoard; // eslint-disable-line no-param-reassign
if (inputs.nextBoard) {
if (inputs.nextBoard.id === inputs.board.id) {
delete inputs.nextBoard; // eslint-disable-line no-param-reassign
} else {
values.boardId = inputs.toBoard.id;
values.boardId = inputs.nextBoard.id;
}
}
const board = inputs.toBoard || inputs.board;
const board = inputs.nextBoard || inputs.board;
if (inputs.toList) {
if (inputs.board.type === 'kanban' && !inputs.list) {
if (inputs.nextList) {
if (inputs.board.type === Board.Types.KANBAN && !inputs.list) {
throw 'listMustBePresent';
}
if (inputs.toList.boardId !== board.id) {
throw 'toListMustBelongToBoard';
if (inputs.nextList.boardId !== board.id) {
throw 'nextListMustBelongToBoard';
}
if (
board.type === 'collection' ||
(inputs.board.type === 'kanban' && inputs.toList.id === inputs.list.id)
board.type === Board.Types.COLLECTION ||
(inputs.board.type === Board.Types.KANBAN && inputs.nextList.id === inputs.list.id)
) {
delete inputs.toList; // eslint-disable-line no-param-reassign
delete inputs.nextList; // eslint-disable-line no-param-reassign
} else {
values.listId = inputs.toList.id;
values.listId = inputs.nextList.id;
}
}
if (inputs.toList) {
if (inputs.nextList) {
if (_.isUndefined(values.position)) {
throw 'positionMustBeInValues';
}
} else if (inputs.toBoard) {
if (inputs.toBoard.type === 'kanban') {
throw 'toListMustBePresent';
} else if (inputs.nextBoard) {
if (inputs.nextBoard.type === Board.Types.KANBAN) {
throw 'nextListMustBePresent';
}
if (inputs.board.type === 'kanban') {
if (inputs.board.type === Board.Types.KANBAN) {
values.listId = null;
values.position = null;
}
}
}
if ((!_.isUndefined(isSubscribed) || inputs.toBoard || inputs.toList) && !inputs.user) {
if ((!_.isUndefined(isSubscribed) || inputs.nextBoard || inputs.nextList) && !inputs.user) {
throw 'userMustBePresent';
}
@ -109,8 +109,12 @@ module.exports = {
const boardId = values.boardId || inputs.record.boardId;
const listId = values.listId || inputs.record.listId;
const cards = await sails.helpers.getCardsForList(listId, inputs.record.id);
const { position, repositions } = sails.helpers.insertToPositionables(values.position, cards);
const cards = await sails.helpers.lists.getCards(listId, inputs.record.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
cards,
);
repositions.forEach(async ({ id, position: nextPosition }) => {
await Card.update({
@ -134,28 +138,26 @@ module.exports = {
let card;
if (!_.isEmpty(values)) {
let prevLabels;
if (inputs.toBoard) {
if (inputs.toBoard.projectId !== inputs.board.projectId) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(
inputs.toBoard.projectId,
);
if (inputs.nextBoard) {
if (inputs.nextBoard.projectId !== inputs.board.projectId) {
const memberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.nextBoard.id);
await CardSubscription.destroy({
cardId: inputs.record.id,
userId: {
'!=': userIds,
'!=': memberUserIds,
},
});
await CardMembership.destroy({
cardId: inputs.record.id,
userId: {
'!=': userIds,
'!=': memberUserIds,
},
});
}
prevLabels = await sails.helpers.getLabelsForCard(inputs.record.id);
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
await CardLabel.destroy({
cardId: inputs.record.id,
@ -165,20 +167,11 @@ module.exports = {
card = await Card.updateOne(inputs.record.id).set(values);
if (!card) {
return exits.success(card);
return card;
}
if (inputs.toBoard) {
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'cardDelete',
{
item: inputs.record,
},
inputs.request,
);
const labels = await sails.helpers.getLabelsForBoard(card.boardId);
if (inputs.nextBoard) {
const labels = await sails.helpers.boards.getLabels(card.boardId);
const labelByNameMap = _.keyBy(labels, 'name');
const labelIds = await Promise.all(
@ -187,9 +180,9 @@ module.exports = {
return labelByNameMap[prevLabel.name].id;
}
const { id } = await sails.helpers.createLabel(
inputs.toBoard,
const { id } = await sails.helpers.labels.createOne(
_.omit(prevLabel, ['id', 'boardId']),
inputs.nextBoard,
);
return id;
@ -197,34 +190,23 @@ module.exports = {
);
await Promise.all(
labelIds.map(async (labelId) => {
await CardLabel.create({
labelIds.map(async (labelId) =>
CardLabel.create({
labelId,
cardId: card.id,
})
.tolerate('E_UNIQUE')
.fetch();
}),
.fetch(),
),
);
const cardMemberships = await sails.helpers.getMembershipsForCard(card.id);
const cardLabels = await sails.helpers.getCardLabelsForCard(card.id);
const tasks = await sails.helpers.getTasksForCard(card.id);
const attachments = await sails.helpers.getAttachmentsForCard(card.id);
sails.sockets.broadcast(`board:${card.boardId}`, 'cardCreate', {
sails.sockets.broadcast(`board:${card.boardId}`, 'cardUpdate', {
item: card,
included: {
cardMemberships,
cardLabels,
tasks,
attachments,
},
});
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(card.id);
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(card.id);
userIds.forEach((userId) => {
subscriptionUserIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'cardUpdate', {
item: {
id: card.id,
@ -243,15 +225,19 @@ module.exports = {
);
}
if (!inputs.toBoard && inputs.toList) {
if (!inputs.nextBoard && inputs.nextList) {
// TODO: add transfer action
await sails.helpers.createAction(card, inputs.user, {
type: 'moveCard',
data: {
fromList: _.pick(inputs.list, ['id', 'name']),
toList: _.pick(inputs.toList, ['id', 'name']),
await sails.helpers.actions.createOne(
{
type: Action.Types.MOVE_CARD,
data: {
fromList: _.pick(inputs.list, ['id', 'name']),
toList: _.pick(inputs.nextList, ['id', 'name']),
},
},
});
inputs.user,
card,
);
}
} else {
card = inputs.record;
@ -290,6 +276,6 @@ module.exports = {
}
}
return exits.success(card);
return card;
},
};

View file

@ -1,57 +0,0 @@
module.exports = {
inputs: {
card: {
type: 'ref',
required: true,
},
user: {
type: 'ref',
required: true,
},
values: {
type: 'json',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const action = await Action.create({
...inputs.values,
cardId: inputs.card.id,
userId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`board:${inputs.card.boardId}`,
'actionCreate',
{
item: action,
},
inputs.request,
);
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(action.cardId, action.userId);
userIds.forEach(async (userId) => {
const notification = await Notification.create({
userId,
actionId: action.id,
cardId: action.cardId,
}).fetch();
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
item: notification,
included: {
users: [inputs.user],
cards: [inputs.card],
actions: [action],
},
});
});
return exits.success(action);
},
};

View file

@ -1,63 +0,0 @@
module.exports = {
inputs: {
project: {
type: 'ref',
required: true,
},
user: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
exits: {
userAlreadyProjectMember: {},
},
async fn(inputs, exits) {
const projectMembership = await ProjectMembership.create({
projectId: inputs.project.id,
userId: inputs.user.id,
})
.intercept('E_UNIQUE', 'userAlreadyProjectMember')
.fetch();
const { userIds, projectMemberships } = await sails.helpers.getMembershipUserIdsForProject(
projectMembership.projectId,
true,
);
userIds.forEach((userId) => {
if (userId !== projectMembership.userId) {
sails.sockets.broadcast(
`user:${userId}`,
'projectMembershipCreate',
{
item: projectMembership,
included: {
users: [inputs.user],
},
},
inputs.request,
);
}
});
const users = await sails.helpers.getUsers(userIds);
const boards = await sails.helpers.getBoardsForProject(projectMembership.projectId);
sails.sockets.broadcast(`user:${projectMembership.userId}`, 'projectCreate', {
item: inputs.project,
included: {
users,
projectMemberships,
boards,
},
});
return exits.success(projectMembership);
},
};

View file

@ -1,51 +0,0 @@
module.exports = {
inputs: {
user: {
type: 'ref',
required: true,
},
values: {
type: 'json',
required: true,
},
request: {
type: 'ref',
},
withProjectMembership: {
type: 'boolean',
defaultsTo: false,
},
},
async fn(inputs, exits) {
const project = await Project.create(inputs.values).fetch();
const projectMembership = await ProjectMembership.create({
projectId: project.id,
userId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`user:${projectMembership.userId}`,
'projectCreate',
{
item: project,
included: {
users: [inputs.user],
projectMemberships: [projectMembership],
boards: [],
},
},
inputs.request,
);
return exits.success(
inputs.withProjectMembership
? {
project,
projectMembership,
}
: project,
);
},
};

View file

@ -1,34 +0,0 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const board = await Board.archiveOne(inputs.record.id);
if (board) {
sails.sockets.leaveAll(`board:${board.id}`);
const userIds = await sails.helpers.getMembershipUserIdsForProject(board.projectId);
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardDelete',
{
item: board,
},
inputs.request,
);
});
}
return exits.success(board);
},
};

View file

@ -1,26 +0,0 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const list = await List.archiveOne(inputs.record.id);
sails.sockets.broadcast(
`board:${list.boardId}`,
'listDelete',
{
item: list,
},
inputs.request,
);
return exits.success(list);
},
};

View file

@ -1,61 +0,0 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const boards = await sails.helpers.getBoardsForProject(inputs.record.projectId);
const boardIds = sails.helpers.mapRecords(boards);
const cards = await sails.helpers.getCardsForBoard(boardIds);
const cardIds = sails.helpers.mapRecords(cards);
await CardSubscription.destroy({
cardId: cardIds,
userId: inputs.record.userId,
});
await CardMembership.destroy({
cardId: cardIds,
userId: inputs.record.userId,
});
const projectMembership = await ProjectMembership.destroyOne(inputs.record.id);
if (projectMembership) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(
projectMembership.projectId,
);
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectMembershipDelete',
{
item: projectMembership,
},
inputs.request,
);
});
sails.sockets.removeRoomMembersFromRooms(
`user:${projectMembership.userId}`,
boardIds.map((boardId) => `board:${boardId}`),
);
const project = await Project.findOne(projectMembership.projectId);
sails.sockets.broadcast(`user:${projectMembership.userId}`, 'projectDelete', {
item: project,
});
}
return exits.success(projectMembership);
},
};

View file

@ -1,11 +0,0 @@
module.exports = {
async fn(inputs, exits) {
const users = await sails.helpers.getUsers({
isAdmin: true,
});
const userIds = sails.helpers.mapRecords(users);
return exits.success(userIds);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const attachments = await sails.helpers.getAttachments({
cardId: inputs.id,
});
return exits.success(attachments);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const attachments = await Attachment.find(inputs.criteria).sort('id');
return exits.success(attachments);
},
};

View file

@ -1,29 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptBoardId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
},
async fn(inputs, exits) {
const criteria = {
projectId: inputs.id,
};
if (!_.isUndefined(inputs.exceptBoardId)) {
criteria.id = {
'!=': inputs.exceptBoardId,
};
}
const boards = await sails.helpers.getBoards(criteria);
return exits.success(boards);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const cardLabels = await sails.helpers.getCardLabels({
cardId: inputs.id,
});
return exits.success(cardLabels);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const cardLabels = await CardLabel.find(inputs.criteria).sort('id');
return exits.success(cardLabels);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const cardMemberships = await CardMembership.find(inputs.criteria).sort('id');
return exits.success(cardMemberships);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const cardSubscriptions = await CardSubscription.find(inputs.criteria).sort('id');
return exits.success(cardSubscriptions);
},
};

View file

@ -1,29 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptCardId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
},
async fn(inputs, exits) {
const criteria = {
listId: inputs.id,
};
if (!_.isUndefined(inputs.exceptCardId)) {
criteria.id = {
'!=': inputs.exceptCardId,
};
}
const cards = await sails.helpers.getCards(criteria);
return exits.success(cards);
},
};

View file

@ -1,16 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const cardLabels = await sails.helpers.getCardLabelsForCard(inputs.id);
const labelIds = sails.helpers.mapRecords(cardLabels, 'labelId', _.isArray(inputs.id));
return exits.success(labelIds);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const labels = await sails.helpers.getLabels({
boardId: inputs.id,
});
return exits.success(labels);
},
};

View file

@ -1,16 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const labelIds = await sails.helpers.getLabelIdsForCard(inputs.id);
const labels = await sails.helpers.getLabels(labelIds);
return exits.success(labels);
},
};

View file

@ -1,29 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptListId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
},
async fn(inputs, exits) {
const criteria = {
boardId: inputs.id,
};
if (!_.isUndefined(inputs.exceptListId)) {
criteria.id = {
'!=': inputs.exceptListId,
};
}
const lists = await List.find(criteria).sort('position');
return exits.success(lists);
},
};

View file

@ -1,21 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const projectMemberships = await sails.helpers.getProjectMembershipsForUser(inputs.id);
const projectIds = sails.helpers.mapRecords(
projectMemberships,
'projectId',
_.isArray(inputs.id),
);
return exits.success(projectIds);
},
};

View file

@ -1,27 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
withProjectMemberships: {
type: 'boolean',
defaultsTo: false,
},
},
async fn(inputs, exits) {
const projectMemberships = await sails.helpers.getMembershipsForProject(inputs.id);
const userIds = sails.helpers.mapRecords(projectMemberships, 'userId', _.isArray(inputs.id));
return exits.success(
inputs.withProjectMemberships
? {
userIds,
projectMemberships,
}
: userIds,
);
},
};

View file

@ -1,29 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
},
async fn(inputs, exits) {
const criteria = {
cardId: inputs.id,
};
if (!_.isUndefined(inputs.exceptUserId)) {
criteria.userId = {
'!=': inputs.exceptUserId,
};
}
const cardMemberships = await sails.helpers.getCardMemberships(criteria);
return exits.success(cardMemberships);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const projectMemberships = await sails.helpers.getProjectMemberships({
projectId: inputs.id,
});
return exits.success(projectMemberships);
},
};

View file

@ -1,18 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const notifications = await sails.helpers.getNotifications({
isRead: false,
userId: inputs.id,
});
return exits.success(notifications);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const notifications = await Notification.find(inputs.criteria).sort('id DESC');
return exits.success(notifications);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const projectMemberships = await sails.helpers.getProjectMemberships({
userId: inputs.id,
});
return exits.success(projectMemberships);
},
};

View file

@ -1,14 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs, exits) {
const projectMemberships = await ProjectMembership.find(inputs.criteria).sort('id');
return exits.success(projectMemberships);
},
};

View file

@ -1,35 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
withCardSubscriptions: {
type: 'boolean',
defaultsTo: false,
},
},
async fn(inputs, exits) {
const cardSubscriptions = await sails.helpers.getSubscriptionsForCard(
inputs.id,
inputs.exceptUserId,
);
const userIds = sails.helpers.mapRecords(cardSubscriptions, 'userId', _.isArray(inputs.id));
return exits.success(
inputs.withCardSubscriptions
? {
userIds,
cardSubscriptions,
}
: userIds,
);
},
};

View file

@ -1,22 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
userId: {
type: 'json',
required: true,
},
},
async fn(inputs, exits) {
const cardSubscriptions = await sails.helpers.getCardSubscriptions({
cardId: inputs.id,
userId: inputs.userId,
});
return exits.success(cardSubscriptions);
},
};

View file

@ -1,29 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
},
},
async fn(inputs, exits) {
const criteria = {
cardId: inputs.id,
};
if (!_.isUndefined(inputs.exceptUserId)) {
criteria.userId = {
'!=': inputs.exceptUserId,
};
}
const cardSubscriptions = await sails.helpers.getCardSubscriptions(criteria);
return exits.success(cardSubscriptions);
},
};

View file

@ -1,17 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'json',
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
async fn(inputs, exits) {
const tasks = await sails.helpers.getTasks({
cardId: inputs.id,
});
return exits.success(tasks);
},
};

View file

@ -1,21 +0,0 @@
module.exports = {
inputs: {
id: {
type: 'string',
required: true,
},
userId: {
type: 'string',
required: true,
},
},
async fn(inputs, exits) {
const projectMembership = await ProjectMembership.findOne({
projectId: inputs.id,
userId: inputs.userId,
});
return exits.success(!!projectMembership);
},
};

View file

@ -1,19 +1,19 @@
module.exports = {
inputs: {
board: {
type: 'ref',
required: true,
},
values: {
type: 'json',
required: true,
},
board: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
async fn(inputs) {
const label = await Label.create({
...inputs.values,
boardId: inputs.board.id,
@ -28,6 +28,6 @@ module.exports = {
inputs.request,
);
return exits.success(label);
return label;
},
};

View file

@ -9,7 +9,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
await CardLabel.destroy({
labelId: inputs.record.id,
});
@ -27,6 +27,6 @@ module.exports = {
);
}
return exits.success(label);
return label;
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return Label.find(inputs.criteria).sort('id');
},
};

View file

@ -10,15 +10,15 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const label = await Label.findOne(inputs.criteria);
if (!label) {
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(label.boardId)
const path = await sails.helpers.boards
.getProjectPath(label.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
label,
@ -26,9 +26,9 @@ module.exports = {
},
}));
return exits.success({
return {
label,
...path,
});
};
},
};

View file

@ -13,7 +13,7 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
const label = await Label.updateOne(inputs.record.id).set(inputs.values);
if (label) {
@ -27,6 +27,6 @@ module.exports = {
);
}
return exits.success(label);
return label;
},
};

View file

@ -1,23 +1,23 @@
module.exports = {
inputs: {
board: {
type: 'ref',
required: true,
},
values: {
type: 'json',
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
board: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const lists = await sails.helpers.getListsForBoard(inputs.board.id);
async fn(inputs) {
const lists = await sails.helpers.boards.getLists(inputs.board.id);
const { position, repositions } = sails.helpers.insertToPositionables(
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
lists,
);
@ -53,6 +53,6 @@ module.exports = {
inputs.request,
);
return exits.success(list);
return list;
},
};

View file

@ -0,0 +1,28 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const list = await List.archiveOne(inputs.record.id);
if (list) {
sails.sockets.broadcast(
`board:${list.boardId}`,
'listDelete',
{
item: list,
},
inputs.request,
);
}
return list;
},
};

View file

@ -0,0 +1,27 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
exceptCardIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
},
},
async fn(inputs) {
const criteria = {
listId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.exceptCardIdOrIds)) {
criteria.id = {
'!=': inputs.exceptCardIdOrIds,
};
}
return sails.helpers.cards.getMany(criteria);
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return List.find(inputs.criteria).sort('position');
},
};

View file

@ -10,15 +10,15 @@ module.exports = {
pathNotFound: {},
},
async fn(inputs, exits) {
async fn(inputs) {
const list = await List.findOne(inputs.criteria);
if (!list) {
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(list.boardId)
const path = await sails.helpers.boards
.getProjectPath(list.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
list,
@ -26,9 +26,9 @@ module.exports = {
},
}));
return exits.success({
return {
list,
...path,
});
};
},
};

View file

@ -24,11 +24,11 @@ module.exports = {
},
},
async fn(inputs, exits) {
async fn(inputs) {
if (!_.isUndefined(inputs.values.position)) {
const lists = await sails.helpers.getListsForBoard(inputs.record.boardId, inputs.record.id);
const lists = await sails.helpers.boards.getLists(inputs.record.boardId, inputs.record.id);
const { position, repositions } = sails.helpers.insertToPositionables(
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
lists,
);
@ -65,6 +65,6 @@ module.exports = {
);
}
return exits.success(list);
return list;
},
};

View file

@ -0,0 +1,29 @@
module.exports = {
inputs: {
userOrId: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value),
required: true,
},
action: {
type: 'ref',
required: true,
},
},
async fn(inputs) {
const { userId = inputs.userOrId } = inputs.userOrId;
const notification = await Notification.create({
userId,
actionId: inputs.action.id,
cardId: inputs.action.cardId,
}).fetch();
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
item: notification,
});
return notification;
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return Notification.find(inputs.criteria).sort('id DESC');
},
};

View file

@ -0,0 +1,48 @@
module.exports = {
inputs: {
recordsOrIds: {
type: 'json',
custom: (value) => _.every(value, _.isObjectLike) || _.every(value, _.isString),
required: true,
},
values: {
type: 'json',
required: true,
},
user: {
type: 'ref',
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const criteria = {};
if (_.every(inputs.recordsOrIds, _.isObjectLike)) {
criteria.id = sails.helpers.utils.mapRecords(inputs.recordsOrIds);
} else if (_.every(inputs.recordsOrIds, _.isString)) {
criteria.id = inputs.recordsOrIds;
}
if (inputs.user) {
criteria.userId = inputs.user.id;
}
const notifications = await Notification.update(criteria).set(inputs.values).fetch();
notifications.forEach((notification) => {
sails.sockets.broadcast(
`user:${notification.userId}`,
'notificationUpdate',
{
item: notification,
},
inputs.request,
);
});
return notifications;
},
};

View file

@ -0,0 +1,45 @@
module.exports = {
inputs: {
user: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
exits: {
userAlreadyProjectManager: {},
},
async fn(inputs) {
const projectManager = await ProjectManager.create({
projectId: inputs.project.id,
userId: inputs.user.id,
})
.intercept('E_UNIQUE', 'userAlreadyProjectManager')
.fetch();
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
projectManager.projectId,
);
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectManagerCreate',
{
item: projectManager,
},
inputs.request,
);
});
return projectManager;
},
};

View file

@ -0,0 +1,34 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
inputs.record.projectId,
);
const projectManager = await ProjectManager.destroyOne(inputs.record.id);
if (projectManager) {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectManagerDelete',
{
item: projectManager,
},
inputs.request,
);
});
}
return projectManager;
},
};

View file

@ -0,0 +1,12 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
async fn(inputs) {
return ProjectManager.find(inputs.criteria).sort('id');
},
};

View file

@ -0,0 +1,38 @@
module.exports = {
inputs: {
values: {
type: 'json',
required: true,
},
user: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const project = await Project.create(inputs.values).fetch();
const projectManager = await ProjectManager.create({
projectId: project.id,
userId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`user:${projectManager.userId}`,
'projectCreate',
{
item: project,
},
inputs.request,
);
return {
project,
projectManager,
};
},
};

View file

@ -9,18 +9,21 @@ module.exports = {
},
},
async fn(inputs, exits) {
const projectMemberships = await ProjectMembership.destroy({
async fn(inputs) {
const projectManagers = await ProjectManager.destroy({
projectId: inputs.record.id,
}).fetch();
const project = await Project.archiveOne(inputs.record.id);
if (project) {
const userIds = sails.helpers.mapRecords(projectMemberships, 'userId');
const managerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
const boards = await sails.helpers.getBoardsForProject(project.id);
const boardRooms = boards.map((board) => `board:${board.id}`);
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);
userIds.forEach((userId) => {
sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms);
@ -36,6 +39,6 @@ module.exports = {
});
}
return exits.success(project);
return project;
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const boards = await sails.helpers.projects.getBoards(inputs.idOrIds);
return sails.helpers.utils.mapRecords(boards);
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const boardIds = await sails.helpers.projects.getBoardIds(inputs.idOrIds);
return sails.helpers.boards.getMemberUserIds(boardIds);
},
};

View file

@ -0,0 +1,27 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
exceptBoardIdOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
},
},
async fn(inputs) {
const criteria = {
projectId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.exceptBoardIdOrIds)) {
criteria.id = {
'!=': inputs.exceptBoardIdOrIds,
};
}
return sails.helpers.boards.getMany(criteria);
},
};

Some files were not shown because too many files have changed in this diff Show more