1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-26 00:29:48 +02:00

Code formatting with prettier, change eslint config for the server

This commit is contained in:
Maksim Eltyshev 2019-11-05 18:01:42 +05:00
parent b7f37f0f96
commit a11f6260c0
191 changed files with 4321 additions and 2880 deletions

View file

@ -2,11 +2,11 @@ const bcrypt = require('bcrypt');
const Errors = {
EMAIL_NOT_EXIST: {
unauthorized: 'Email does not exist'
unauthorized: 'Email does not exist',
},
PASSWORD_NOT_VALID: {
unauthorized: 'Password is not valid'
}
unauthorized: 'Password is not valid',
},
};
module.exports = {
@ -14,23 +14,23 @@ module.exports = {
email: {
type: 'string',
required: true,
isEmail: true
isEmail: true,
},
password: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
unauthorized: {
responseType: 'unauthorized'
}
responseType: 'unauthorized',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const user = await sails.helpers.getUser({
email: inputs.email.toLowerCase()
email: inputs.email.toLowerCase(),
});
if (!user) {
@ -42,7 +42,7 @@ module.exports = {
}
return exits.success({
item: sails.helpers.signToken(user.id)
item: sails.helpers.signToken(user.id),
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
notFound: 'Card is not found',
},
};
module.exports = {
@ -9,21 +9,21 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
beforeId: {
type: 'string',
regex: /^[0-9]+$/
}
regex: /^[0-9]+$/,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { project } = await sails.helpers
@ -32,17 +32,14 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
const actions = await sails.helpers.getActionsForCard(
inputs.cardId,
inputs.beforeId
);
const actions = await sails.helpers.getActionsForCard(inputs.cardId, inputs.beforeId);
const userIds = sails.helpers.mapRecords(actions, 'userId', true);
const users = await sails.helpers.getUsers(userIds);
@ -50,8 +47,8 @@ module.exports = {
return exits.success({
items: actions,
included: {
users
}
users,
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found'
}
notFound: 'Project is not found',
},
};
module.exports = {
@ -9,25 +9,25 @@ module.exports = {
projectId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
position: {
type: 'number',
required: true
required: true,
},
name: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const project = await Project.findOne(inputs.projectId);
if (!project) {
@ -42,8 +42,8 @@ module.exports = {
item: board,
included: {
lists: [],
labels: []
}
labels: [],
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found'
}
notFound: 'Board is not found',
},
};
module.exports = {
@ -9,17 +9,17 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let board = await Board.findOne(inputs.id);
if (!board) {
@ -33,7 +33,7 @@ module.exports = {
}
return exits.success({
item: board
item: board,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found'
}
notFound: 'Board is not found',
},
};
module.exports = {
@ -9,17 +9,17 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
// TODO: allow over HTTP without subscription
if (!this.req.isSocket) {
return this.res.badRequest();
@ -33,7 +33,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -48,7 +48,7 @@ module.exports = {
const cardSubscriptions = await sails.helpers.getSubscriptionsByUserForCard(
cardIds,
currentUser.id
currentUser.id,
);
const cardMemberships = await sails.helpers.getMembershipsForCard(cardIds);
@ -59,12 +59,12 @@ module.exports = {
const isSubscribedByCardId = cardSubscriptions.reduce(
(result, cardSubscription) => ({
...result,
[cardSubscription.cardId]: true
[cardSubscription.cardId]: true,
}),
{}
{},
);
cards.forEach(card => {
cards.forEach((card) => {
card.isSubscribed = isSubscribedByCardId[card.id] || false;
});
@ -78,8 +78,8 @@ module.exports = {
cards,
cardMemberships,
cardLabels,
tasks
}
tasks,
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found'
}
notFound: 'Board is not found',
},
};
module.exports = {
@ -9,24 +9,24 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
position: {
type: 'number'
type: 'number',
},
name: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let board = await Board.findOne(inputs.id);
if (!board) {
@ -42,7 +42,7 @@ module.exports = {
}
return exits.success({
item: board
item: board,
});
}
},
};

View file

@ -1,13 +1,13 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
notFound: 'Card is not found',
},
LABEL_NOT_FOUND: {
notFound: 'Label is not found'
notFound: 'Label is not found',
},
CARD_LABEL_EXIST: {
conflict: 'Card label is already exist'
}
conflict: 'Card label is already exist',
},
};
module.exports = {
@ -15,25 +15,25 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
labelId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
conflict: {
responseType: 'conflict'
}
responseType: 'conflict',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers
@ -42,7 +42,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -51,7 +51,7 @@ module.exports = {
const label = await Label.findOne({
id: inputs.labelId,
boardId: card.boardId
boardId: card.boardId,
});
if (!label) {
@ -63,7 +63,7 @@ module.exports = {
.intercept('conflict', () => Errors.CARD_LABEL_EXIST);
return exits.success({
item: cardLabel
item: cardLabel,
});
}
},
};

View file

@ -1,10 +1,10 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
notFound: 'Card is not found',
},
CARD_LABEL_NOT_FOUND: {
notFound: 'Card label is not found'
}
notFound: 'Card label is not found',
},
};
module.exports = {
@ -12,22 +12,22 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
labelId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers
@ -36,7 +36,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -45,7 +45,7 @@ module.exports = {
let cardLabel = await CardLabel.findOne({
cardId: inputs.cardId,
labelId: inputs.labelId
labelId: inputs.labelId,
});
if (!cardLabel) {
@ -59,7 +59,7 @@ module.exports = {
}
return exits.success({
item: cardLabel
item: cardLabel,
});
}
},
};

View file

@ -1,13 +1,13 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
notFound: 'Card is not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found'
notFound: 'User is not found',
},
CARD_MEMBERSHIP_EXIST: {
conflict: 'Card membership is already exist'
}
conflict: 'Card membership is already exist',
},
};
module.exports = {
@ -15,25 +15,25 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
userId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
conflict: {
responseType: 'conflict'
}
responseType: 'conflict',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers
@ -42,17 +42,14 @@ module.exports = {
let isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
throw Errors.CARD_NOT_FOUND; // Forbidden
}
isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
inputs.userId
);
isUserMemberForProject = await sails.helpers.isUserMemberForProject(project.id, inputs.userId);
if (!isUserMemberForProject) {
throw Errors.USER_NOT_FOUND;
@ -63,7 +60,7 @@ module.exports = {
.intercept('conflict', () => Errors.CARD_MEMBERSHIP_EXIST);
return exits.success({
item: cardMembership
item: cardMembership,
});
}
},
};

View file

@ -1,10 +1,10 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
notFound: 'Card is not found',
},
CARD_MEMBERSHIP_NOT_FOUND: {
notFound: 'Card membership is not found'
}
notFound: 'Card membership is not found',
},
};
module.exports = {
@ -12,22 +12,22 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
userId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers
@ -36,7 +36,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -45,25 +45,21 @@ module.exports = {
let cardMembership = await CardMembership.findOne({
cardId: inputs.cardId,
userId: inputs.userId
userId: inputs.userId,
});
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
}
cardMembership = await sails.helpers.deleteCardMembership(
cardMembership,
board,
this.req
);
cardMembership = await sails.helpers.deleteCardMembership(cardMembership, board, this.req);
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
}
return exits.success({
item: cardMembership
item: cardMembership,
});
}
},
};

View file

@ -2,8 +2,8 @@ const moment = require('moment');
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found'
}
notFound: 'List is not found',
},
};
module.exports = {
@ -11,43 +11,41 @@ module.exports = {
listId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
position: {
type: 'number',
required: true
required: true,
},
name: {
type: 'string',
required: true
required: true,
},
description: {
type: 'string',
isNotEmptyString: true,
allowNull: true
allowNull: true,
},
dueDate: {
type: 'string',
custom: value => moment(value, moment.ISO_8601, true).isValid()
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
},
timer: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) ||
moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
_.isFinite(value.total)
}
custom: (value) => _.isPlainObject(value)
&& _.size(value) === 2
&& (_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid())
&& _.isFinite(value.total),
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { list, project } = await sails.helpers
@ -56,30 +54,19 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
throw Errors.LIST_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, [
'position',
'name',
'description',
'dueDate',
'timer'
]);
const values = _.pick(inputs, ['position', 'name', 'description', 'dueDate', 'timer']);
const card = await sails.helpers.createCard(
list,
values,
currentUser,
this.req
);
const card = await sails.helpers.createCard(list, values, currentUser, this.req);
return exits.success({
item: card
item: card,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
notFound: 'Card is not found',
},
};
module.exports = {
@ -9,26 +9,29 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { card, project } = await sails.helpers
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { project } = cardToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -42,7 +45,7 @@ module.exports = {
}
return exits.success({
item: card
item: card,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
notFound: 'Card is not found',
},
};
module.exports = {
@ -9,17 +9,17 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers
@ -28,7 +28,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -36,7 +36,7 @@ module.exports = {
}
return exits.success({
item: card
item: card,
});
}
},
};

View file

@ -2,11 +2,11 @@ const moment = require('moment');
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
notFound: 'Card is not found',
},
LIST_NOT_FOUND: {
notFound: 'List is not found'
}
notFound: 'List is not found',
},
};
module.exports = {
@ -14,59 +14,60 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
listId: {
type: 'string',
regex: /^[0-9]+$/
regex: /^[0-9]+$/,
},
position: {
type: 'number'
type: 'number',
},
name: {
type: 'string',
isNotEmptyString: true
isNotEmptyString: true,
},
description: {
type: 'string',
isNotEmptyString: true,
allowNull: true
allowNull: true,
},
dueDate: {
type: 'string',
custom: value => moment(value, moment.ISO_8601, true).isValid(),
allowNull: true
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
allowNull: true,
},
timer: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) ||
moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
_.isFinite(value.total)
custom: (value) => _.isPlainObject(value)
&& _.size(value) === 2
&& (_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid())
&& _.isFinite(value.total),
},
isSubscribed: {
type: 'boolean'
}
type: 'boolean',
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { card, list, project } = await sails.helpers
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { list, project } = cardToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -77,7 +78,7 @@ module.exports = {
if (!_.isUndefined(inputs.listId) && inputs.listId !== list.id) {
toList = await List.findOne({
id: inputs.listId,
boardId: card.boardId
boardId: card.boardId,
});
if (!toList) {
@ -91,24 +92,17 @@ module.exports = {
'description',
'dueDate',
'timer',
'isSubscribed'
'isSubscribed',
]);
card = await sails.helpers.updateCard(
card,
values,
toList,
list,
currentUser,
this.req
);
card = await sails.helpers.updateCard(card, values, toList, list, currentUser, this.req);
if (!card) {
throw Errors.CARD_NOT_FOUND;
}
return exits.success({
item: card
item: card,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
notFound: 'Card is not found',
},
};
module.exports = {
@ -9,21 +9,21 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
text: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers
@ -32,7 +32,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -41,13 +41,13 @@ module.exports = {
const values = {
type: 'commentCard',
data: _.pick(inputs, ['text'])
data: _.pick(inputs, ['text']),
};
const action = await sails.helpers.createAction(card, currentUser, values, this.req);
return exits.success({
item: action
item: action,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found'
}
notFound: 'Comment action is not found',
},
};
module.exports = {
@ -9,35 +9,38 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const criteria = {
id: inputs.id,
type: 'commentCard'
type: 'commentCard',
};
if (!currentUser.isAdmin) {
criteria.userId = currentUser.id;
}
let { action, board, project } = await sails.helpers
const actionToProjectPath = await sails.helpers
.getActionToProjectPath(criteria)
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -51,7 +54,7 @@ module.exports = {
}
return exits.success({
item: action
item: action,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found'
}
notFound: 'Comment action is not found',
},
};
module.exports = {
@ -9,34 +9,37 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
text: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { action, board, project } = await sails.helpers
const actionToProjectPath = await sails.helpers
.getActionToProjectPath({
id: inputs.id,
type: 'commentCard',
userId: currentUser.id
userId: currentUser.id,
})
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -44,7 +47,7 @@ module.exports = {
}
const values = {
data: _.pick(inputs, ['text'])
data: _.pick(inputs, ['text']),
};
action = await sails.helpers.updateAction(action, values, board, this.req);
@ -54,7 +57,7 @@ module.exports = {
}
return exits.success({
item: action
item: action,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found'
}
notFound: 'Board is not found',
},
};
module.exports = {
@ -9,27 +9,27 @@ module.exports = {
boardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
name: {
type: 'string',
isNotEmptyString: true,
allowNull: true
allowNull: true,
},
color: {
type: 'string',
isIn: Label.COLORS,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers
@ -38,7 +38,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -50,7 +50,7 @@ module.exports = {
const label = await sails.helpers.createLabel(board, values, this.req);
return exits.success({
item: label
item: label,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found'
}
notFound: 'Label is not found',
},
};
module.exports = {
@ -9,26 +9,29 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { label, project } = await sails.helpers
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -42,7 +45,7 @@ module.exports = {
}
return exits.success({
item: label
item: label,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found'
}
notFound: 'Label is not found',
},
};
module.exports = {
@ -9,36 +9,39 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
name: {
type: 'string',
isNotEmptyString: true,
allowNull: true
allowNull: true,
},
color: {
type: 'string',
isIn: Label.COLORS,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { label, project } = await sails.helpers
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -50,7 +53,7 @@ module.exports = {
label = await sails.helpers.updateLabel(label, values, this.req);
return exits.success({
item: label
item: label,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found'
}
notFound: 'Board is not found',
},
};
module.exports = {
@ -9,25 +9,25 @@ module.exports = {
boardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
position: {
type: 'number',
required: true
required: true,
},
name: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers
@ -36,7 +36,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -48,7 +48,7 @@ module.exports = {
const list = await sails.helpers.createList(board, values, this.req);
return exits.success({
item: list
item: list,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found'
}
notFound: 'List is not found',
},
};
module.exports = {
@ -9,26 +9,29 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { list, project } = await sails.helpers
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -42,7 +45,7 @@ module.exports = {
}
return exits.success({
item: list
item: list,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found'
}
notFound: 'List is not found',
},
};
module.exports = {
@ -9,33 +9,36 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
position: {
type: 'number'
type: 'number',
},
name: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { list, project } = await sails.helpers
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -51,7 +54,7 @@ module.exports = {
}
return exits.success({
item: list
item: list,
});
}
},
};

View file

@ -1,10 +1,8 @@
module.exports = {
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const notifications = await sails.helpers.getNotificationsForUser(
currentUser.id
);
const notifications = await sails.helpers.getNotificationsForUser(currentUser.id);
const actionIds = sails.helpers.mapRecords(notifications, 'actionId');
const actions = await sails.helpers.getActions(actionIds);
@ -20,8 +18,8 @@ module.exports = {
included: {
users,
cards,
actions
}
actions,
},
});
}
},
};

View file

@ -3,20 +3,20 @@ module.exports = {
ids: {
type: 'string',
required: true,
regex: /^[0-9]+(,[0-9]+)*$/
regex: /^[0-9]+(,[0-9]+)*$/,
},
isRead: {
type: 'boolean'
}
type: 'boolean',
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const values = _.pick(inputs, ['isRead']);
@ -25,11 +25,11 @@ module.exports = {
inputs.ids.split(','),
currentUser,
values,
this.req
this.req,
);
return exits.success({
items: notifications
items: notifications,
});
}
},
};

View file

@ -1,13 +1,13 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found'
notFound: 'Project is not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found'
notFound: 'User is not found',
},
PROJECT_MEMBERSHIP_EXIST: {
conflict: 'Project membership is already exist'
}
conflict: 'Project membership is already exist',
},
};
module.exports = {
@ -15,25 +15,25 @@ module.exports = {
projectId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
userId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
conflict: {
responseType: 'conflict'
}
responseType: 'conflict',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const project = await Project.findOne(inputs.projectId);
if (!project) {
@ -53,8 +53,8 @@ module.exports = {
return exits.success({
item: projectMembership,
included: {
users: [user]
}
users: [user],
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
PROJECT_MEMBERSHIP_NOT_FOUND: {
notFound: 'Project membership is not found'
}
notFound: 'Project membership is not found',
},
};
module.exports = {
@ -9,34 +9,31 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let projectMembership = await ProjectMembership.findOne(inputs.id);
if (!projectMembership) {
throw Errors.PROJECT_MEMBERSHIP_NOT_FOUND;
}
projectMembership = await sails.helpers.deleteProjectMembership(
projectMembership,
this.req
);
projectMembership = await sails.helpers.deleteProjectMembership(projectMembership, this.req);
if (!projectMembership) {
throw Errors.PROJECT_MEMBERSHIP_NOT_FOUND;
}
return exits.success({
item: projectMembership
item: projectMembership,
});
}
},
};

View file

@ -2,11 +2,11 @@ module.exports = {
inputs: {
name: {
type: 'string',
required: true
}
required: true,
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const values = _.pick(inputs, ['name']);
@ -15,7 +15,7 @@ module.exports = {
values,
currentUser,
this.req,
true
true,
);
return exits.success({
@ -23,8 +23,8 @@ module.exports = {
included: {
users: [currentUser],
projectMemberships: [projectMembership],
boards: []
}
boards: [],
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found'
}
notFound: 'Project is not found',
},
};
module.exports = {
@ -9,17 +9,17 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let project = await Project.findOne(inputs.id);
if (!project) {
@ -33,7 +33,7 @@ module.exports = {
}
return exits.success({
item: project
item: project,
});
}
},
};

View file

@ -1,17 +1,15 @@
module.exports = {
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
currentUser.id
);
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(currentUser.id);
const projects = await sails.helpers.getProjects(projectIds);
const {
userIds,
projectMemberships
} = await sails.helpers.getMembershipUserIdsForProject(projectIds, true);
const { userIds, projectMemberships } = await sails.helpers.getMembershipUserIdsForProject(
projectIds,
true,
);
const users = await sails.helpers.getUsers(userIds);
@ -22,8 +20,8 @@ module.exports = {
included: {
users,
projectMemberships,
boards
}
boards,
},
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found'
}
notFound: 'Project is not found',
},
};
module.exports = {
@ -9,21 +9,21 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
name: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let project = await Project.findOne(inputs.id);
if (!project) {
@ -39,7 +39,7 @@ module.exports = {
}
return exits.success({
item: project
item: project,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found'
}
notFound: 'Card is not found',
},
};
module.exports = {
@ -9,24 +9,24 @@ module.exports = {
cardId: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
name: {
type: 'string',
required: true
required: true,
},
isCompleted: {
type: 'boolean'
}
type: 'boolean',
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
const { card, project } = await sails.helpers
@ -35,7 +35,7 @@ module.exports = {
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -47,7 +47,7 @@ module.exports = {
const task = await sails.helpers.createTask(card, values, this.req);
return exits.success({
item: task
item: task,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found'
}
notFound: 'Task is not found',
},
};
module.exports = {
@ -9,26 +9,29 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { task, board, project } = await sails.helpers
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -42,7 +45,7 @@ module.exports = {
}
return exits.success({
item: task
item: task,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found'
}
notFound: 'Task is not found',
},
};
module.exports = {
@ -9,33 +9,36 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
name: {
type: 'string',
isNotEmptyString: true
isNotEmptyString: true,
},
isCompleted: {
type: 'boolean'
}
type: 'boolean',
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let { task, board, project } = await sails.helpers
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
currentUser.id
currentUser.id,
);
if (!isUserMemberForProject) {
@ -51,7 +54,7 @@ module.exports = {
}
return exits.success({
item: task
item: task,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
USER_EXIST: {
conflict: 'User is already exist'
}
conflict: 'User is already exist',
},
};
module.exports = {
@ -9,25 +9,25 @@ module.exports = {
email: {
type: 'string',
isEmail: true,
required: true
required: true,
},
password: {
type: 'string',
required: true
required: true,
},
name: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
conflict: {
responseType: 'conflict'
}
responseType: 'conflict',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const values = _.pick(inputs, ['email', 'password', 'name']);
const user = await sails.helpers
@ -35,7 +35,7 @@ module.exports = {
.intercept('conflict', () => Errors.USER_EXIST);
return exits.success({
item: user
item: user,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found'
}
notFound: 'User is not found',
},
};
module.exports = {
@ -9,17 +9,17 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
let user = await sails.helpers.getUser(inputs.id);
if (!user) {
@ -33,7 +33,7 @@ module.exports = {
}
return exits.success({
item: user
item: user,
});
}
},
};

View file

@ -1,9 +1,9 @@
module.exports = {
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const users = await sails.helpers.getUsers();
return exits.success({
items: users
items: users,
});
}
},
};

View file

@ -1,5 +1,5 @@
module.exports = {
fn: async function(inputs, exits) {
async fn(inputs, exits) {
// TODO: allow over HTTP without subscription
if (!this.req.isSocket) {
return this.res.badRequest();
@ -10,7 +10,7 @@ module.exports = {
sails.sockets.join(this.req, `user:${currentUser.id}`); // TODO: only when subscription needed
return exits.success({
item: currentUser
item: currentUser,
});
}
},
};

View file

@ -2,14 +2,14 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found'
notFound: 'User is not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid'
forbidden: 'Current password is not valid',
},
USER_EXIST: {
conflict: 'User is already exist'
}
conflict: 'User is already exist',
},
};
module.exports = {
@ -17,32 +17,32 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
email: {
type: 'string',
isEmail: true,
required: true
required: true,
},
currentPassword: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
forbidden: {
responseType: 'forbidden'
responseType: 'forbidden',
},
conflict: {
responseType: 'conflict'
}
responseType: 'conflict',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
if (inputs.id === currentUser.id) {
@ -60,8 +60,8 @@ module.exports = {
}
if (
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
inputs.id === currentUser.id
&& !bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
}
@ -77,7 +77,7 @@ module.exports = {
}
return exits.success({
item: user.email
item: user.email,
});
}
},
};

View file

@ -2,11 +2,11 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found'
notFound: 'User is not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid'
}
forbidden: 'Current password is not valid',
},
};
module.exports = {
@ -14,28 +14,28 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
password: {
type: 'string',
required: true
required: true,
},
currentPassword: {
type: 'string',
isNotEmptyString: true
}
isNotEmptyString: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
forbidden: {
responseType: 'forbidden'
}
responseType: 'forbidden',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
if (inputs.id === currentUser.id) {
@ -53,8 +53,8 @@ module.exports = {
}
if (
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
inputs.id === currentUser.id
&& !bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
}
@ -68,7 +68,7 @@ module.exports = {
}
return exits.success({
item: null
item: null,
});
}
},
};

View file

@ -1,7 +1,7 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found'
}
notFound: 'User is not found',
},
};
module.exports = {
@ -9,28 +9,28 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
required: true,
},
isAdmin: {
type: 'boolean'
type: 'boolean',
},
name: {
type: 'string',
isNotEmptyString: true
isNotEmptyString: true,
},
avatar: {
type: 'json',
custom: value => _.isNull(value)
}
custom: (value) => _.isNull(value),
},
},
exits: {
notFound: {
responseType: 'notFound'
}
responseType: 'notFound',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
if (!currentUser.isAdmin) {
@ -56,7 +56,7 @@ module.exports = {
}
return exits.success({
item: user
item: user,
});
}
},
};

View file

@ -1,27 +1,31 @@
const stream = require('stream');
const fs = require('fs');
const path = require('path');
const util = require('util');
const stream = require('stream');
const uuid = require('uuid/v4');
const sharp = require('sharp');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found'
}
notFound: 'User is not found',
},
};
const pipeline = util.promisify(stream.pipeline);
const createReceiver = () => {
const receiver = require('stream').Writable({ objectMode: true });
const receiver = stream.Writable({ objectMode: true });
let firstFileHandled = false;
receiver._write = (file, encoding, done) => {
// eslint-disable-next-line no-underscore-dangle
receiver._write = async (file, receiverEncoding, done) => {
if (firstFileHandled) {
file.pipe(
new stream.Writable({
write(chunk, encoding, callback) {
write(chunk, streamEncoding, callback) {
callback();
}
})
},
}),
);
return done();
@ -33,30 +37,25 @@ const createReceiver = () => {
.jpeg();
const transform = new stream.Transform({
transform(chunk, encoding, callback) {
transform(chunk, streamEncoding, callback) {
callback(null, chunk);
}
},
});
stream.pipeline(file, resize, transform, error => {
if (error) {
return done(error.message);
}
try {
await pipeline(file, resize, transform);
file.fd = `${uuid()}.jpg`;
const output = fs.createWriteStream(
path.join(sails.config.custom.uploadsPath, file.fd)
await pipeline(
transform,
fs.createWriteStream(path.join(sails.config.custom.uploadsPath, file.fd)),
);
stream.pipeline(transform, output, error => {
if (error) {
return done(error);
}
done();
});
});
return done();
} catch (error) {
return done(error);
}
};
return receiver;
@ -67,20 +66,20 @@ module.exports = {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true
}
required: true,
},
},
exits: {
notFound: {
responseType: 'notFound'
responseType: 'notFound',
},
unprocessableEntity: {
responseType: 'unprocessableEntity'
}
responseType: 'unprocessableEntity',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { currentUser } = this.req;
let user;
@ -98,7 +97,7 @@ module.exports = {
this.req.file('file').upload(createReceiver(), async (error, files) => {
if (error) {
return exits.unprocessableEntity(error);
return exits.unprocessableEntity(error.message);
}
if (files.length === 0) {
@ -108,18 +107,18 @@ module.exports = {
user = await sails.helpers.updateUser(
user,
{
avatar: files[0].fd
avatar: files[0].fd,
},
this.req
this.req,
);
if (!user) {
throw Errors.USER_NOT_FOUND;
}
return this.res.json({
item: user.avatar
return exits.success({
item: user.toJSON().avatar,
});
});
}
},
};

View file

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

View file

@ -2,44 +2,42 @@ module.exports = {
inputs: {
project: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
required: true
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const boards = await sails.helpers.getBoardsForProject(inputs.project.id);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
boards
boards,
);
const userIds = await sails.helpers.getMembershipUserIdsForProject(
inputs.project.id
);
const userIds = await sails.helpers.getMembershipUserIdsForProject(inputs.project.id);
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
projectId: inputs.project.id
projectId: inputs.project.id,
}).set({
position
position: nextPosition,
});
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
position
}
position: nextPosition,
},
});
});
});
@ -47,10 +45,10 @@ module.exports = {
const board = await Board.create({
...inputs.values,
position,
projectId: inputs.project.id
projectId: inputs.project.id,
}).fetch();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',
@ -58,13 +56,13 @@ module.exports = {
item: board,
included: {
lists: [],
labels: []
}
labels: [],
},
},
inputs.request
inputs.request,
);
});
return exits.success(board);
}
},
};

View file

@ -2,21 +2,21 @@ module.exports = {
inputs: {
card: {
type: 'ref',
required: true
required: true,
},
label: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cardLabel = await CardLabel.create({
cardId: inputs.card.id,
labelId: inputs.label.id
labelId: inputs.label.id,
})
.intercept('E_UNIQUE', 'conflict')
.fetch();
@ -25,11 +25,11 @@ module.exports = {
`board:${inputs.card.boardId}`,
'cardLabelCreate',
{
item: cardLabel
item: cardLabel,
},
inputs.request
inputs.request,
);
return exits.success(cardLabel);
}
},
};

View file

@ -2,24 +2,24 @@ module.exports = {
inputs: {
card: {
type: 'ref',
required: true
required: true,
},
userOrUserId: {
type: 'ref',
custom: value => _.isPlainObject(value) || _.isString(value),
required: true
custom: (value) => _.isPlainObject(value) || _.isString(value),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { userId = inputs.userOrUserId } = inputs.userOrUserId;
const cardMembership = await CardMembership.create({
userId,
cardId: inputs.card.id
cardId: inputs.card.id,
})
.intercept('E_UNIQUE', 'conflict')
.fetch();
@ -28,15 +28,15 @@ module.exports = {
`board:${inputs.card.boardId}`,
'cardMembershipCreate',
{
item: cardMembership
item: cardMembership,
},
inputs.request
inputs.request,
);
const cardSubscription = await CardSubscription.create({
cardId: cardMembership.cardId,
userId: cardMembership.userId,
isPermanent: false
isPermanent: false,
})
.tolerate('E_UNIQUE')
.fetch();
@ -48,13 +48,13 @@ module.exports = {
{
item: {
id: cardMembership.cardId,
isSubscribed: true
}
isSubscribed: true,
},
},
inputs.request
inputs.request,
);
}
return exits.success(cardMembership);
}
},
};

View file

@ -2,43 +2,43 @@ module.exports = {
inputs: {
list: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
required: true
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
user: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cards = await sails.helpers.getCardsForList(inputs.list.id);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
cards
cards,
);
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await Card.update({
id,
listId: inputs.list.id
listId: inputs.list.id,
}).set({
position
position: nextPosition,
});
sails.sockets.broadcast(`board:${list.boardId}`, 'cardUpdate', {
item: {
id,
position
}
position: nextPosition,
},
});
});
@ -46,27 +46,27 @@ module.exports = {
...inputs.values,
position,
listId: inputs.list.id,
boardId: inputs.list.boardId
boardId: inputs.list.boardId,
}).fetch();
sails.sockets.broadcast(
`board:${card.boardId}`,
'cardCreate',
{
item: card
item: card,
},
inputs.request
inputs.request,
);
const values = {
type: 'createCard',
data: {
list: _.pick(inputs.list, ['id', 'name'])
}
list: _.pick(inputs.list, ['id', 'name']),
},
};
await sails.helpers.createAction(card, inputs.user, values);
return exits.success(card);
}
},
};

View file

@ -2,32 +2,32 @@ module.exports = {
inputs: {
board: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const label = await Label.create({
...inputs.values,
boardId: inputs.board.id
boardId: inputs.board.id,
}).fetch();
sails.sockets.broadcast(
`board:${label.boardId}`,
'labelCreate',
{
item: label
item: label,
},
inputs.request
inputs.request,
);
return exits.success(label);
}
},
};

View file

@ -2,57 +2,57 @@ module.exports = {
inputs: {
board: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
required: true
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const lists = await sails.helpers.getListsForBoard(inputs.board.id);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
lists
lists,
);
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await List.update({
id,
boardId: inputs.board.id
boardId: inputs.board.id,
}).set({
position
position: nextPosition,
});
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
item: {
id,
position
}
position: nextPosition,
},
});
});
const list = await List.create({
...inputs.values,
position,
boardId: inputs.board.id
boardId: inputs.board.id,
}).fetch();
sails.sockets.broadcast(
`board:${list.boardId}`,
'listCreate',
{
item: list
item: list,
},
inputs.request
inputs.request,
);
return exits.success(list);
}
},
};

View file

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

View file

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

View file

@ -2,32 +2,32 @@ module.exports = {
inputs: {
card: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const task = await Task.create({
...inputs.values,
cardId: inputs.card.id
cardId: inputs.card.id,
}).fetch();
sails.sockets.broadcast(
`board:${inputs.card.boardId}`,
'taskCreate',
{
item: task
item: task,
},
inputs.request
inputs.request,
);
return exits.success(task);
}
},
};

View file

@ -4,45 +4,47 @@ module.exports = {
inputs: {
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
_.isString(value.email) &&
_.isString(value.password),
required: true
// eslint-disable-next-line max-len
custom: (value) => _.isPlainObject(value) && _.isString(value.email) && _.isString(value.password),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
exits: {
conflict: {}
conflict: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const user = await User.create({
...inputs.values,
email: inputs.values.email.toLowerCase(),
password: bcrypt.hashSync(inputs.values.password, 10)
password: bcrypt.hashSync(inputs.values.password, 10),
})
.intercept({
message: 'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"'
}, 'conflict')
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
)
.fetch();
const userIds = await sails.helpers.getAdminUserIds();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userCreate',
{
item: user
item: user,
},
inputs.request
inputs.request,
);
});
return exits.success(user);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const action = await Action.archiveOne(inputs.record.id);
if (action) {
@ -21,12 +21,12 @@ module.exports = {
`board:${inputs.board.id}`,
'actionDelete',
{
item: action
item: action,
},
inputs.request
inputs.request,
);
}
return exits.success(action);
}
},
};

View file

@ -2,35 +2,33 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
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
);
const userIds = await sails.helpers.getMembershipUserIdsForProject(board.projectId);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardDelete',
{
item: board
item: board,
},
inputs.request
inputs.request,
);
});
}
return exits.success(board);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cardLabel = await CardLabel.destroyOne(inputs.record.id);
if (cardLabel) {
@ -21,12 +21,12 @@ module.exports = {
`board:${inputs.board.id}`,
'cardLabelDelete',
{
item: cardLabel
item: cardLabel,
},
inputs.request
inputs.request,
);
}
return exits.success(cardLabel);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cardMembership = await CardMembership.destroyOne(inputs.record.id);
if (cardMembership) {
@ -21,27 +21,27 @@ module.exports = {
`board:${inputs.board.id}`,
'cardMembershipDelete',
{
item: cardMembership
item: cardMembership,
},
inputs.request
inputs.request,
);
const cardSubscription = await CardSubscription.destroyOne({
cardId: cardMembership.cardId,
userId: cardMembership.userId,
isPermanent: false
isPermanent: false,
});
if (cardSubscription) {
sails.sockets.broadcast(`user:${cardMembership.userId}`, 'cardUpdate', {
item: {
id: cardMembership.cardId,
isSubscribed: false
}
isSubscribed: false,
},
});
}
}
return exits.success(cardMembership);
}
},
};

View file

@ -2,14 +2,14 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const card = await Card.archiveOne(inputs.record.id);
if (card) {
@ -17,12 +17,12 @@ module.exports = {
`board:${card.boardId}`,
'cardDelete',
{
item: card
item: card,
},
inputs.request
inputs.request,
);
}
return exits.success(card);
}
},
};

View file

@ -2,16 +2,16 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
await CardLabel.destroy({
labelId: inputs.record.id
labelId: inputs.record.id,
});
const label = await Label.archiveOne(inputs.record.id);
@ -21,12 +21,12 @@ module.exports = {
`board:${label.boardId}`,
'labelDelete',
{
item: label
item: label,
},
inputs.request
inputs.request,
);
}
return exits.success(label);
}
},
};

View file

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

View file

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

View file

@ -2,16 +2,16 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const projectMemberships = await ProjectMembership.destroy({
projectId: inputs.record.id
projectId: inputs.record.id,
}).fetch();
const project = await Project.archiveOne(inputs.record.id);
@ -20,22 +20,22 @@ module.exports = {
const userIds = sails.helpers.mapRecords(projectMemberships, 'userId');
const boards = await sails.helpers.getBoardsForProject(project.id);
const boardRooms = boards.map(board => `board:${board.id}`);
const boardRooms = boards.map((board) => `board:${board.id}`);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms);
sails.sockets.broadcast(
`user:${userId}`,
'projectDelete',
{
item: project
item: project,
},
inputs.request
inputs.request,
);
});
}
return exits.success(project);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const task = await Task.archiveOne(inputs.record.id);
if (task) {
@ -21,12 +21,12 @@ module.exports = {
`board:${inputs.board.id}`,
'taskDelete',
{
item: task
item: task,
},
inputs.request
inputs.request,
);
}
return exits.success(task);
}
},
};

View file

@ -2,58 +2,54 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
await ProjectMembership.destroy({
userId: inputs.record.id
userId: inputs.record.id,
});
await CardSubscription.destroy({
userId: inputs.record.id
userId: inputs.record.id,
});
await CardMembership.destroy({
userId: inputs.record.id
userId: inputs.record.id,
});
const user = await User.updateOne({
id: inputs.record.id,
deletedAt: null
deletedAt: null,
}).set({
deletedAt: new Date().toUTCString()
deletedAt: new Date().toUTCString(),
});
if (user) {
const adminUserIds = await sails.helpers.getAdminUserIds();
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
user.id
);
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(user.id);
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(
projectIds
);
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(projectIds);
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userDelete',
{
item: user
item: user,
},
inputs.request
inputs.request,
);
});
}
return exits.success(user);
}
},
};

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const action = await Action.findOne(inputs.criteria);
if (!action) {
@ -19,16 +19,16 @@ module.exports = {
const path = await sails.helpers
.getCardToProjectPath(action.cardId)
.intercept('notFound', path => ({
.intercept('notFound', (nodes) => ({
notFound: {
action,
...path
}
...nodes,
},
}));
return exits.success({
action,
...path
...path,
});
}
},
};

View file

@ -4,27 +4,27 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
required: true
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
beforeId: {
type: 'string'
}
type: 'string',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const criteria = {
cardId: inputs.id
cardId: inputs.id,
};
if (!_.isUndefined(inputs.beforeId)) {
criteria.id = {
'<': inputs.beforeId
'<': inputs.beforeId,
};
}
const actions = await sails.helpers.getActions(criteria, LIMIT);
return exits.success(actions);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
limit: {
type: 'number'
}
type: 'number',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const actions = await Action.find(inputs.criteria)
.sort('id DESC')
.limit(inputs.limit);
return exits.success(actions);
}
},
};

View file

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

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const board = await Board.findOne(inputs.criteria);
if (!board) {
@ -22,14 +22,14 @@ module.exports = {
if (!project) {
throw {
notFound: {
board
}
board,
},
};
}
return exits.success({
board,
project
project,
});
}
},
};

View file

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

View file

@ -2,13 +2,13 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
}
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const boards = await Board.find(inputs.criteria).sort('position');
return exits.success(boards);
}
},
};

View file

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

View file

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

View file

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

View file

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

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const card = await Card.findOne(inputs.criteria);
if (!card) {
@ -19,16 +19,16 @@ module.exports = {
const path = await sails.helpers
.getListToProjectPath(card.listId)
.intercept('notFound', path => ({
.intercept('notFound', (nodes) => ({
notFound: {
card,
...path
}
...nodes,
},
}));
return exits.success({
card,
...path
...path,
});
}
},
};

View file

@ -2,16 +2,16 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
required: true
}
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cards = await sails.helpers.getCards({
boardId: inputs.id
boardId: inputs.id,
});
return exits.success(cards);
}
},
};

View file

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

View file

@ -2,13 +2,13 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
}
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const cards = await Card.find(inputs.criteria).sort('position');
return exits.success(cards);
}
},
};

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const label = await Label.findOne(inputs.criteria);
if (!label) {
@ -19,16 +19,16 @@ module.exports = {
const path = await sails.helpers
.getBoardToProjectPath(label.boardId)
.intercept('notFound', path => ({
.intercept('notFound', (nodes) => ({
notFound: {
label,
...path
}
...nodes,
},
}));
return exits.success({
label,
...path
...path,
});
}
},
};

View file

@ -2,16 +2,16 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
required: true
}
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const labels = await Label.find({
boardId: inputs.id
boardId: inputs.id,
}).sort('id');
return exits.success(labels);
}
},
};

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const list = await List.findOne(inputs.criteria);
if (!list) {
@ -19,16 +19,16 @@ module.exports = {
const path = await sails.helpers
.getBoardToProjectPath(list.boardId)
.intercept('notFound', path => ({
.intercept('notFound', (nodes) => ({
notFound: {
list,
...path
}
...nodes,
},
}));
return exits.success({
list,
...path
...path,
});
}
},
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,13 +2,13 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
}
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const projects = await Project.find(inputs.criteria).sort('id');
return exits.success(projects);
}
},
};

View file

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

View file

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

View file

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

View file

@ -2,15 +2,15 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
required: true
}
required: true,
},
},
exits: {
notFound: {}
notFound: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const task = await Task.findOne(inputs.criteria);
if (!task) {
@ -19,16 +19,16 @@ module.exports = {
const path = await sails.helpers
.getCardToProjectPath(task.cardId)
.intercept('notFound', path => ({
.intercept('notFound', (nodes) => ({
notFound: {
task,
...path
}
...nodes,
},
}));
return exits.success({
task,
...path
...path,
});
}
},
};

View file

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

View file

@ -2,13 +2,13 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
}
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const tasks = await Task.find(inputs.criteria).sort('id');
return exits.success(tasks);
}
},
};

View file

@ -2,14 +2,14 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isString(value) || _.isPlainObject(value),
required: true
}
custom: (value) => _.isString(value) || _.isPlainObject(value),
required: true,
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const criteria = {
deletedAt: null
deletedAt: null,
};
if (_.isString(inputs.criteria)) {
@ -21,5 +21,5 @@ module.exports = {
const user = await User.findOne(criteria);
return exits.success(user);
}
},
};

View file

@ -2,13 +2,13 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value)
}
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const criteria = {
deletedAt: null
deletedAt: null,
};
if (_.isArray(inputs.criteria)) {
@ -20,5 +20,5 @@ module.exports = {
const users = await User.find(criteria).sort('id');
return exits.success(users);
}
},
};

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