mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
Code formatting with prettier, change eslint config for the server
This commit is contained in:
parent
bc87c1d883
commit
7a3805e64c
191 changed files with 4321 additions and 2880 deletions
|
@ -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),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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],
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue