1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00

Add username to user

This commit is contained in:
Maksim Eltyshev 2020-04-03 00:35:25 +05:00
parent 1320c697db
commit ce1e1f741d
143 changed files with 1051 additions and 420 deletions

View file

@ -1,20 +1,24 @@
const bcrypt = require('bcrypt');
const validator = require('validator');
const Errors = {
EMAIL_NOT_EXIST: {
unauthorized: 'Email does not exist',
INVALID_EMAIL_OR_USERNAME: {
invalidEmailOrUsername: 'Invalid email or username',
},
PASSWORD_NOT_VALID: {
unauthorized: 'Password is not valid',
INVALID_PASSWORD: {
invalidPassword: 'Invalid password',
},
};
module.exports = {
inputs: {
email: {
emailOrUsername: {
type: 'string',
custom: (value) =>
value.includes('@')
? validator.isEmail(value)
: value.length >= 3 && value.length <= 16 && /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/.test(value),
required: true,
isEmail: true,
},
password: {
type: 'string',
@ -23,22 +27,23 @@ module.exports = {
},
exits: {
unauthorized: {
invalidEmailOrUsername: {
responseType: 'unauthorized',
},
invalidPassword: {
responseType: 'unauthorized',
},
},
async fn(inputs, exits) {
const user = await sails.helpers.getUser({
email: inputs.email.toLowerCase(),
});
const user = await sails.helpers.getUserByEmailOrUsername(inputs.emailOrUsername);
if (!user) {
throw Errors.EMAIL_NOT_EXIST;
throw Errors.INVALID_EMAIL_OR_USERNAME;
}
if (!bcrypt.compareSync(inputs.password, user.password)) {
throw Errors.PASSWORD_NOT_VALID;
throw Errors.INVALID_PASSWORD;
}
return exits.success({

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -28,7 +28,7 @@ module.exports = {
const { project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -22,7 +22,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -29,7 +29,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -64,7 +64,7 @@ module.exports = {
{},
);
cards.map(card => ({
cards.map((card) => ({
...card,
isSubscribed: isSubscribedByCardId[card.id] || false,
}));

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,12 +1,12 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
CARD_LABEL_EXIST: {
conflict: 'Card label is already exist',
LABEL_ALREADY_IN_CARD: {
labelAlreadyInCard: 'Label already in card',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
conflict: {
labelNotFound: {
responseType: 'notFound',
},
labelAlreadyInCard: {
responseType: 'conflict',
},
},
@ -38,7 +41,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -60,7 +63,7 @@ module.exports = {
const cardLabel = await sails.helpers
.createCardLabel(card, label, this.req)
.intercept('conflict', () => Errors.CARD_LABEL_EXIST);
.intercept('labelAlreadyInCard', () => Errors.LABEL_ALREADY_IN_CARD);
return exits.success({
item: cardLabel,

View file

@ -1,9 +1,9 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
CARD_LABEL_NOT_FOUND: {
notFound: 'Card label is not found',
LABEL_NOT_IN_CARD: {
labelNotInCard: 'Label not in card',
},
};
@ -22,7 +22,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
labelNotInCard: {
responseType: 'notFound',
},
},
@ -32,7 +35,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -49,13 +52,13 @@ module.exports = {
});
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
throw Errors.LABEL_NOT_IN_CARD;
}
cardLabel = await sails.helpers.deleteCardLabel(cardLabel, board, this.req);
if (!cardLabel) {
throw Errors.CARD_LABEL_NOT_FOUND;
throw Errors.LABEL_NOT_IN_CARD;
}
return exits.success({

View file

@ -1,12 +1,12 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CARD_MEMBERSHIP_EXIST: {
conflict: 'Card membership is already exist',
USER_ALREADY_CARD_MEMBER: {
userAlreadyCardMember: 'User already card member',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
conflict: {
userNotFound: {
responseType: 'notFound',
},
userAlreadyCardMember: {
responseType: 'conflict',
},
},
@ -38,7 +41,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -57,7 +60,7 @@ module.exports = {
const cardMembership = await sails.helpers
.createCardMembership(card, inputs.userId, this.req)
.intercept('conflict', () => Errors.CARD_MEMBERSHIP_EXIST);
.intercept('userAlreadyCardMember', () => Errors.USER_ALREADY_CARD_MEMBER);
return exits.success({
item: cardMembership,

View file

@ -1,9 +1,9 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
CARD_MEMBERSHIP_NOT_FOUND: {
notFound: 'Card membership is not found',
USER_NOT_CARD_MEMBER: {
userNotCardMember: 'User not card member',
},
};
@ -22,7 +22,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
userNotCardMember: {
responseType: 'notFound',
},
},
@ -32,7 +35,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,
@ -49,13 +52,13 @@ module.exports = {
});
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
throw Errors.USER_NOT_CARD_MEMBER;
}
cardMembership = await sails.helpers.deleteCardMembership(cardMembership, board, this.req);
if (!cardMembership) {
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
throw Errors.USER_NOT_CARD_MEMBER;
}
return exits.success({

View file

@ -2,7 +2,7 @@ const moment = require('moment');
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -28,11 +28,11 @@ module.exports = {
},
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 =>
custom: (value) =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
@ -41,7 +41,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -51,7 +51,7 @@ module.exports = {
const { list, project } = await sails.helpers
.getListToProjectPath(inputs.listId)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { project } = cardToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -2,10 +2,10 @@ const moment = require('moment');
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -34,12 +34,12 @@ module.exports = {
},
dueDate: {
type: 'string',
custom: value => moment(value, moment.ISO_8601, true).isValid(),
custom: (value) => moment(value, moment.ISO_8601, true).isValid(),
allowNull: true,
},
timer: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) &&
_.size(value) === 2 &&
(_.isNull(value.startedAt) || moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
@ -51,7 +51,10 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
listNotFound: {
responseType: 'notFound',
},
},
@ -61,7 +64,7 @@ module.exports = {
const cardToProjectPath = await sails.helpers
.getCardToProjectPath(inputs.id)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
let { card } = cardToProjectPath;
const { list, project } = cardToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -28,7 +28,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found',
commentActionNotFound: 'Comment action not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
commentActionNotFound: {
responseType: 'notFound',
},
},
@ -33,7 +33,7 @@ module.exports = {
const actionToProjectPath = await sails.helpers
.getActionToProjectPath(criteria)
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
COMMENT_ACTION_NOT_FOUND: {
notFound: 'Comment action is not found',
commentActionNotFound: 'Comment action not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
commentActionNotFound: {
responseType: 'notFound',
},
},
@ -32,7 +32,7 @@ module.exports = {
type: 'commentCard',
userId: currentUser.id,
})
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
.intercept('pathNotFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
let { action } = actionToProjectPath;
const { board, project } = actionToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -24,7 +24,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -34,7 +34,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.boardId)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
labelNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
LABEL_NOT_FOUND: {
notFound: 'Label is not found',
labelNotFound: 'Label not found',
},
};
@ -24,7 +24,7 @@ module.exports = {
},
exits: {
notFound: {
labelNotFound: {
responseType: 'notFound',
},
},
@ -34,7 +34,7 @@ module.exports = {
const labelToProjectPath = await sails.helpers
.getLabelToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LABEL_NOT_FOUND);
let { label } = labelToProjectPath;
const { project } = labelToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
BOARD_NOT_FOUND: {
notFound: 'Board is not found',
boardNotFound: 'Board not found',
},
};
@ -22,7 +22,7 @@ module.exports = {
},
exits: {
notFound: {
boardNotFound: {
responseType: 'notFound',
},
},
@ -32,7 +32,7 @@ module.exports = {
const { board, project } = await sails.helpers
.getBoardToProjectPath(inputs.boardId)
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
LIST_NOT_FOUND: {
notFound: 'List is not found',
listNotFound: 'List not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
listNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const listToProjectPath = await sails.helpers
.getListToProjectPath(inputs.id)
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
let { list } = listToProjectPath;
const { project } = listToProjectPath;

View file

@ -10,12 +10,6 @@ module.exports = {
},
},
exits: {
notFound: {
responseType: 'notFound',
},
},
async fn(inputs, exits) {
const { currentUser } = this.req;

View file

@ -1,12 +1,12 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
PROJECT_MEMBERSHIP_EXIST: {
conflict: 'Project membership is already exist',
USER_ALREADY_PROJECT_MEMBER: {
userAlreadyProjectMember: 'User already project member',
},
};
@ -25,10 +25,13 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
conflict: {
userNotFound: {
responseType: 'notFound',
},
userAlreadyProjectMember: {
responseType: 'conflict',
},
},
@ -48,7 +51,7 @@ module.exports = {
const projectMembership = await sails.helpers
.createProjectMembership(project, user, this.req)
.intercept('conflict', () => Errors.PROJECT_MEMBERSHIP_EXIST);
.intercept('userAlreadyProjectMember', () => Errors.USER_ALREADY_PROJECT_MEMBER);
return exits.success({
item: projectMembership,

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_MEMBERSHIP_NOT_FOUND: {
notFound: 'Project membership is not found',
projectMembershipNotFound: 'Project membership not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
projectMembershipNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
PROJECT_NOT_FOUND: {
notFound: 'Project is not found',
projectNotFound: 'Project not found',
},
};
@ -18,7 +18,7 @@ module.exports = {
},
exits: {
notFound: {
projectNotFound: {
responseType: 'notFound',
},
},

View file

@ -1,6 +1,6 @@
const Errors = {
CARD_NOT_FOUND: {
notFound: 'Card is not found',
cardNotFound: 'Card not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
cardNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const { card, project } = await sails.helpers
.getCardToProjectPath(inputs.cardId)
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
project.id,

View file

@ -1,6 +1,6 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found',
taskNotFound: 'Task not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
taskNotFound: {
responseType: 'notFound',
},
},
@ -24,7 +24,7 @@ module.exports = {
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;

View file

@ -1,6 +1,6 @@
const Errors = {
TASK_NOT_FOUND: {
notFound: 'Task is not found',
taskNotFound: 'Task not found',
},
};
@ -21,7 +21,7 @@ module.exports = {
},
exits: {
notFound: {
taskNotFound: {
responseType: 'notFound',
},
},
@ -31,7 +31,7 @@ module.exports = {
const taskToProjectPath = await sails.helpers
.getTaskToProjectPath(inputs.id)
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
.intercept('pathNotFound', () => Errors.TASK_NOT_FOUND);
let { task } = taskToProjectPath;
const { board, project } = taskToProjectPath;

View file

@ -1,6 +1,9 @@
const Errors = {
USER_EXIST: {
conflict: 'User is already exist',
EMAIL_ALREADY_IN_USE: {
emailAlreadyInUse: 'Email already in use',
},
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
};
@ -19,20 +22,32 @@ module.exports = {
type: 'string',
required: true,
},
username: {
type: 'string',
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
allowNull: true,
},
},
exits: {
conflict: {
emailAlreadyInUse: {
responseType: 'conflict',
},
usernameAlreadyInUse: {
responseType: 'conflict',
},
},
async fn(inputs, exits) {
const values = _.pick(inputs, ['email', 'password', 'name']);
const values = _.pick(inputs, ['email', 'password', 'name', 'username']);
const user = await sails.helpers
.createUser(values, this.req)
.intercept('conflict', () => Errors.USER_EXIST);
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
return exits.success({
item: user,

View file

@ -1,6 +1,6 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -14,7 +14,7 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
},

View file

@ -2,13 +2,13 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid',
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
USER_EXIST: {
conflict: 'User is already exist',
EMAIL_ALREADY_IN_USE: {
emailAlreadyInUse: 'Email already in use',
},
};
@ -31,13 +31,13 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
forbidden: {
invalidCurrentPassword: {
responseType: 'forbidden',
},
conflict: {
emailAlreadyInUse: {
responseType: 'conflict',
},
},
@ -47,7 +47,7 @@ module.exports = {
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
@ -63,14 +63,14 @@ module.exports = {
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['email']);
user = await sails.helpers
.updateUser(user, values, this.req)
.intercept('conflict', () => Errors.USER_EXIST);
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE);
if (!user) {
throw Errors.USER_NOT_FOUND;

View file

@ -2,10 +2,10 @@ const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
CURRENT_PASSWORD_NOT_VALID: {
forbidden: 'Current password is not valid',
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
};
@ -27,10 +27,10 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
forbidden: {
invalidCurrentPassword: {
responseType: 'forbidden',
},
},
@ -40,7 +40,7 @@ module.exports = {
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
@ -56,7 +56,7 @@ module.exports = {
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.CURRENT_PASSWORD_NOT_VALID;
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['password']);

View file

@ -0,0 +1,85 @@
const bcrypt = require('bcrypt');
const Errors = {
USER_NOT_FOUND: {
userNotFound: 'User not found',
},
INVALID_CURRENT_PASSWORD: {
invalidCurrentPassword: 'Invalid current password',
},
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
username: {
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
allowNull: true,
},
currentPassword: {
type: 'string',
isNotEmptyString: true,
},
},
exits: {
userNotFound: {
responseType: 'notFound',
},
invalidCurrentPassword: {
responseType: 'forbidden',
},
usernameAlreadyInUse: {
responseType: 'conflict',
},
},
async fn(inputs, exits) {
const { currentUser } = this.req;
if (inputs.id === currentUser.id) {
if (!inputs.currentPassword) {
throw Errors.INVALID_CURRENT_PASSWORD;
}
} else if (!currentUser.isAdmin) {
throw Errors.USER_NOT_FOUND; // Forbidden
}
let user = await sails.helpers.getUser(inputs.id);
if (!user) {
throw Errors.USER_NOT_FOUND;
}
if (
inputs.id === currentUser.id &&
!bcrypt.compareSync(inputs.currentPassword, user.password)
) {
throw Errors.INVALID_CURRENT_PASSWORD;
}
const values = _.pick(inputs, ['username']);
user = await sails.helpers
.updateUser(user, values, this.req)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
if (!user) {
throw Errors.USER_NOT_FOUND;
}
return exits.success({
item: user.username,
});
},
};

View file

@ -1,6 +1,6 @@
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -20,12 +20,12 @@ module.exports = {
},
avatar: {
type: 'json',
custom: value => _.isNull(value),
custom: (value) => _.isNull(value),
},
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
},

View file

@ -7,7 +7,7 @@ const sharp = require('sharp');
const Errors = {
USER_NOT_FOUND: {
notFound: 'User is not found',
userNotFound: 'User not found',
},
};
@ -32,9 +32,7 @@ const createReceiver = () => {
}
firstFileHandled = true;
const resize = sharp()
.resize(36, 36)
.jpeg();
const resize = sharp().resize(36, 36).jpeg();
const transform = new stream.Transform({
transform(chunk, streamEncoding, callback) {
@ -71,10 +69,10 @@ module.exports = {
},
exits: {
notFound: {
userNotFound: {
responseType: 'notFound',
},
unprocessableEntity: {
uploadError: {
responseType: 'unprocessableEntity',
},
},
@ -97,11 +95,11 @@ module.exports = {
this.req.file('file').upload(createReceiver(), async (error, files) => {
if (error) {
return exits.unprocessableEntity(error.message);
return exits.uploadError(error.message);
}
if (files.length === 0) {
return exits.unprocessableEntity('No file was uploaded');
return exits.uploadError('No file was uploaded');
}
user = await sails.helpers.updateUser(

View file

@ -35,7 +35,7 @@ module.exports = {
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,

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {
@ -32,7 +32,7 @@ module.exports = {
position: nextPosition,
});
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
@ -48,7 +48,7 @@ module.exports = {
projectId: inputs.project.id,
}).fetch();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',

View file

@ -13,12 +13,16 @@ module.exports = {
},
},
exits: {
labelAlreadyInCard: {},
},
async fn(inputs, exits) {
const cardLabel = await CardLabel.create({
cardId: inputs.card.id,
labelId: inputs.label.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'labelAlreadyInCard')
.fetch();
sails.sockets.broadcast(

View file

@ -6,7 +6,7 @@ module.exports = {
},
userOrUserId: {
type: 'ref',
custom: value => _.isPlainObject(value) || _.isString(value),
custom: (value) => _.isPlainObject(value) || _.isString(value),
required: true,
},
request: {
@ -14,6 +14,10 @@ module.exports = {
},
},
exits: {
userAlreadyCardMember: {},
},
async fn(inputs, exits) {
const { userId = inputs.userOrUserId } = inputs.userOrUserId;
@ -21,7 +25,7 @@ module.exports = {
userId,
cardId: inputs.card.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'userAlreadyCardMember')
.fetch();
sails.sockets.broadcast(

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
user: {

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
request: {

View file

@ -14,7 +14,7 @@ module.exports = {
},
exits: {
conflict: {},
userAlreadyProjectMember: {},
},
async fn(inputs, exits) {
@ -22,7 +22,7 @@ module.exports = {
projectId: inputs.project.id,
userId: inputs.user.id,
})
.intercept('E_UNIQUE', 'conflict')
.intercept('E_UNIQUE', 'userAlreadyProjectMember')
.fetch();
const { userIds, projectMemberships } = await sails.helpers.getMembershipUserIdsForProject(
@ -30,7 +30,7 @@ module.exports = {
true,
);
userIds.forEach(userId => {
userIds.forEach((userId) => {
if (userId !== projectMembership.userId) {
sails.sockets.broadcast(
`user:${userId}`,

View file

@ -4,8 +4,11 @@ module.exports = {
inputs: {
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) && _.isString(value.email) && _.isString(value.password),
custom: (value) =>
_.isPlainObject(value) &&
_.isString(value.email) &&
_.isString(value.password) &&
(!value.username || _.isString(value.username)),
required: true,
},
request: {
@ -14,10 +17,16 @@ module.exports = {
},
exits: {
conflict: {},
emailAlreadyInUse: {},
usernameAlreadyInUse: {},
},
async fn(inputs, exits) {
if (inputs.values.username) {
// eslint-disable-next-line no-param-reassign
inputs.values.username = inputs.values.username.toLowerCase();
}
const user = await User.create({
...inputs.values,
email: inputs.values.email.toLowerCase(),
@ -28,13 +37,20 @@ module.exports = {
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
'emailAlreadyInUse',
)
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_username_unique"',
},
'usernameAlreadyInUse',
)
.fetch();
const userIds = await sails.helpers.getAdminUserIds();
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userCreate',

View file

@ -17,7 +17,7 @@ module.exports = {
const userIds = await sails.helpers.getMembershipUserIdsForProject(board.projectId);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardDelete',

View file

@ -34,7 +34,7 @@ module.exports = {
projectMembership.projectId,
);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectMembershipDelete',
@ -47,7 +47,7 @@ module.exports = {
sails.sockets.removeRoomMembersFromRooms(
`user:${projectMembership.userId}`,
boardIds.map(boardId => `board:${boardId}`),
boardIds.map((boardId) => `board:${boardId}`),
);
const project = await Project.findOne(projectMembership.projectId);

View file

@ -20,9 +20,9 @@ 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(

View file

@ -38,7 +38,7 @@ module.exports = {
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userDelete',

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const action = await Action.findOne(inputs.criteria);
if (!action) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getCardToProjectPath(action.cardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
action,
...nodes,
},

View file

@ -4,7 +4,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
beforeId: {

View file

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

View file

@ -7,21 +7,21 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const board = await Board.findOne(inputs.criteria);
if (!board) {
throw 'notFound';
throw 'pathNotFound';
}
const project = await Project.findOne(board.projectId);
if (!project) {
throw {
notFound: {
pathNotFound: {
board,
},
};

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptBoardId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const card = await Card.findOne(inputs.criteria);
if (!card) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getListToProjectPath(card.listId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
card,
...nodes,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptCardId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const label = await Label.findOne(inputs.criteria);
if (!label) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(label.boardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
label,
...nodes,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const list = await List.findOne(inputs.criteria);
if (!list) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getBoardToProjectPath(list.boardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
list,
...nodes,
},

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptListId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
withProjectMemberships: {

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
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',

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
userId: {

View file

@ -2,12 +2,12 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
exceptUserId: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
},
},

View file

@ -7,20 +7,20 @@ module.exports = {
},
exits: {
notFound: {},
pathNotFound: {},
},
async fn(inputs, exits) {
const task = await Task.findOne(inputs.criteria);
if (!task) {
throw 'notFound';
throw 'pathNotFound';
}
const path = await sails.helpers
.getCardToProjectPath(task.cardId)
.intercept('notFound', nodes => ({
notFound: {
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
task,
...nodes,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
id: {
type: 'json',
custom: value => _.isString(value) || _.isArray(value),
custom: (value) => _.isString(value) || _.isArray(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -0,0 +1,18 @@
module.exports = {
inputs: {
emailOrUsername: {
type: 'string',
required: true,
},
},
async fn(inputs, exits) {
const fieldName = inputs.emailOrUsername.includes('@') ? 'email' : 'username';
const user = await sails.helpers.getUser({
[fieldName]: inputs.emailOrUsername.toLowerCase(),
});
return exits.success(user);
},
};

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isString(value) || _.isPlainObject(value),
custom: (value) => _.isString(value) || _.isPlainObject(value),
required: true,
},
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
criteria: {
type: 'json',
custom: value => _.isArray(value) || _.isPlainObject(value),
custom: (value) => _.isArray(value) || _.isPlainObject(value),
},
},

View file

@ -2,14 +2,14 @@ const GAP = 2 ** 14;
const MIN_GAP = 0.125;
const MAX_POSITION = 2 ** 50;
const findBeginnings = positions => {
const findBeginnings = (positions) => {
positions.unshift(0);
let prevPosition = positions.pop();
const beginnings = [prevPosition];
// eslint-disable-next-line consistent-return
_.forEachRight(positions, position => {
_.forEachRight(positions, (position) => {
if (prevPosition - MIN_GAP >= position) {
return false;
}
@ -21,7 +21,7 @@ const findBeginnings = positions => {
return beginnings;
};
const getRepositionsMap = positions => {
const getRepositionsMap = (positions) => {
const repositionsMap = {};
if (positions.length <= 1) {
@ -62,7 +62,7 @@ const getRepositionsMap = positions => {
return repositionsMap;
};
const getFullRepositionsMap = positions => {
const getFullRepositionsMap = (positions) => {
const repositionsMap = {};
_.forEach(positions, (position, index) => {

View file

@ -4,7 +4,7 @@ module.exports = {
inputs: {
records: {
type: 'ref',
custom: value => _.isArray(value),
custom: (value) => _.isArray(value),
required: true,
},
attribute: {

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},
@ -39,7 +39,7 @@ module.exports = {
position: nextPosition,
});
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
@ -53,7 +53,7 @@ module.exports = {
const board = await Board.updateOne(inputs.record.id).set(inputs.values);
if (board) {
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardUpdate',

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},

View file

@ -6,7 +6,7 @@ module.exports = {
},
values: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},

View file

@ -2,7 +2,7 @@ module.exports = {
inputs: {
ids: {
type: 'json',
custom: value => _.isArray(value),
custom: (value) => _.isArray(value),
required: true,
},
user: {
@ -26,7 +26,7 @@ module.exports = {
.set(inputs.values)
.fetch();
notifications.forEach(notification => {
notifications.forEach((notification) => {
sails.sockets.broadcast(
`user:${notification.userId}`,
'notificationUpdate',

View file

@ -19,7 +19,7 @@ module.exports = {
if (project) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(project.id);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectUpdate',

View file

@ -10,10 +10,11 @@ module.exports = {
},
values: {
type: 'json',
custom: value =>
custom: (value) =>
_.isPlainObject(value) &&
(_.isUndefined(value.email) || _.isString(value.email)) &&
(_.isUndefined(value.password) || _.isString(value.password)),
(_.isUndefined(value.password) || _.isString(value.password)) &&
(!value.username || _.isString(value.username)),
required: true,
},
request: {
@ -22,7 +23,8 @@ module.exports = {
},
exits: {
conflict: {},
emailAlreadyInUse: {},
usernameAlreadyInUse: {},
},
async fn(inputs, exits) {
@ -42,6 +44,11 @@ module.exports = {
}
}
if (inputs.values.username) {
// eslint-disable-next-line no-param-reassign
inputs.values.username = inputs.values.username.toLowerCase();
}
const user = await User.updateOne({
id: inputs.record.id,
deletedAt: null,
@ -52,7 +59,14 @@ module.exports = {
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
'emailAlreadyInUse',
)
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_username_unique"',
},
'usernameAlreadyInUse',
);
if (user) {
@ -73,7 +87,7 @@ module.exports = {
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userUpdate',

View file

@ -11,7 +11,7 @@ module.exports = {
},
exits: {
notValid: {},
invalidToken: {},
},
fn(inputs, exits) {
@ -20,7 +20,7 @@ module.exports = {
try {
payload = jwt.verify(inputs.token, sails.config.session.secret);
} catch (error) {
throw 'notValid';
throw 'invalidToken';
}
return exits.success(payload);

View file

@ -9,7 +9,7 @@
module.exports = function defineCurrentUserHook(sails) {
const TOKEN_PATTERN = /^Bearer /;
const getUser = async accessToken => {
const getUser = async (accessToken) => {
let id;
try {

View file

@ -29,6 +29,14 @@ module.exports = {
type: 'string',
required: true,
},
username: {
type: 'string',
isNotEmptyString: true,
minLength: 3,
maxLength: 16,
regex: /^[a-zA-Z0-9]+(_?[a-zA-Z0-9])*$/,
allowNull: true,
},
avatar: {
type: 'string',
isNotEmptyString: true,

View file

@ -17,6 +17,7 @@ module.exports.routes = {
'PATCH /api/users/:id': 'users/update',
'PATCH /api/users/:id/email': 'users/update-email',
'PATCH /api/users/:id/password': 'users/update-password',
'PATCH /api/users/:id/username': 'users/update-username',
'POST /api/users/:id/upload-avatar': 'users/upload-avatar',
'DELETE /api/users/:id': 'users/delete',

View file

@ -1,4 +1,4 @@
module.exports.up = knex =>
module.exports.up = (knex) =>
knex.raw(`
CREATE SEQUENCE next_id_seq;
@ -20,7 +20,7 @@ module.exports.up = knex =>
$$ LANGUAGE PLPGSQL;
`);
module.exports.down = knex =>
module.exports.down = (knex) =>
knex.raw(`
DROP SEQUENCE next_id_seq;
DROP FUNCTION next_id(OUT id BIGINT);

View file

@ -1,11 +1,8 @@
module.exports.up = knex =>
knex.schema.createTable('archive', table => {
module.exports.up = (knex) =>
knex.schema.createTable('archive', (table) => {
/* Columns */
table
.bigInteger('id')
.primary()
.defaultTo(knex.raw('next_id()'));
table.bigInteger('id').primary().defaultTo(knex.raw('next_id()'));
table.text('from_model').notNullable();
table.bigInteger('original_record_id').notNullable();
@ -19,4 +16,4 @@ module.exports.up = knex =>
table.unique(['from_model', 'original_record_id']);
});
module.exports.down = knex => knex.schema.dropTable('archive');
module.exports.down = (knex) => knex.schema.dropTable('archive');

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