1
0
Fork 0
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:
Maksim Eltyshev 2019-11-05 18:01:42 +05:00
parent bc87c1d883
commit 7a3805e64c
191 changed files with 4321 additions and 2880 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,13 +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];
_.forEachRight(positions, position => {
// eslint-disable-next-line consistent-return
_.forEachRight(positions, (position) => {
if (prevPosition - MIN_GAP >= position) {
return false;
}
@ -20,7 +21,7 @@ const findBeginnings = positions => {
return beginnings;
};
const getRepositionsMap = positions => {
const getRepositionsMap = (positions) => {
const repositionsMap = {};
if (positions.length <= 1) {
@ -33,7 +34,7 @@ const getRepositionsMap = positions => {
let prevPosition = positions.shift();
for (let i = 0; i < positions.length; i++) {
for (let i = 0; i < positions.length; i += 1) {
const position = positions[i];
const nextPosition = positions[i + 1];
@ -41,12 +42,9 @@ const getRepositionsMap = positions => {
break;
}
if (
!_.isUndefined(nextPosition) &&
prevPosition + MIN_GAP * 2 <= nextPosition
) {
if (!_.isUndefined(nextPosition) && prevPosition + MIN_GAP * 2 <= nextPosition) {
(repositionsMap[position] || (repositionsMap[position] = [])).push(
prevPosition + (nextPosition - prevPosition) / 2
prevPosition + (nextPosition - prevPosition) / 2,
);
break;
@ -58,21 +56,17 @@ const getRepositionsMap = positions => {
return null;
}
(repositionsMap[position] || (repositionsMap[position] = [])).push(
prevPosition
);
(repositionsMap[position] || (repositionsMap[position] = [])).push(prevPosition);
}
return repositionsMap;
};
const getFullRepositionsMap = positions => {
const getFullRepositionsMap = (positions) => {
const repositionsMap = {};
_.forEach(positions, (position, index) => {
(repositionsMap[position] || (repositionsMap[position] = [])).push(
GAP * (index + 1)
);
(repositionsMap[position] || (repositionsMap[position] = [])).push(GAP * (index + 1));
});
return repositionsMap;
@ -84,15 +78,15 @@ module.exports = {
inputs: {
position: {
type: 'number',
required: true
required: true,
},
records: {
type: 'ref',
required: true
}
required: true,
},
},
fn: function(inputs, exits) {
fn(inputs, exits) {
const lowers = [];
const uppers = [];
@ -102,30 +96,29 @@ module.exports = {
const beginnings = findBeginnings([...lowers, inputs.position]);
const repositionsMap =
getRepositionsMap([...beginnings, ...uppers]) ||
getFullRepositionsMap([...lowers, inputs.position, ...uppers]);
const repositionsMap = getRepositionsMap([...beginnings, ...uppers])
|| getFullRepositionsMap([...lowers, inputs.position, ...uppers]);
let position = repositionsMap[inputs.position]
const position = repositionsMap[inputs.position]
? repositionsMap[inputs.position].pop()
: inputs.position;
const repositions = [];
_.forEachRight(inputs.records, ({ id, position }) => {
if (_.isEmpty(repositionsMap[position])) {
_.forEachRight(inputs.records, ({ id, position: currentPosition }) => {
if (_.isEmpty(repositionsMap[currentPosition])) {
return;
}
repositions.unshift({
id,
position: repositionsMap[position].pop()
position: repositionsMap[currentPosition].pop(),
});
});
return exits.success({
position,
repositions
repositions,
});
}
},
};

View file

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

View file

@ -4,25 +4,25 @@ module.exports = {
inputs: {
records: {
type: 'ref',
custom: value => _.isArray(value),
required: true
custom: (value) => _.isArray(value),
required: true,
},
attribute: {
type: 'string',
defaultsTo: 'id'
defaultsTo: 'id',
},
unique: {
type: 'boolean',
defaultsTo: false
}
defaultsTo: false,
},
},
fn: function(inputs, exits) {
fn(inputs, exits) {
let result = _.map(inputs.records, inputs.attribute);
if (inputs.unique) {
result = _.uniq(result);
}
return exits.success(result);
}
},
};

View file

@ -1,4 +1,4 @@
var jwt = require('jsonwebtoken');
const jwt = require('jsonwebtoken');
module.exports = {
sync: true,
@ -6,13 +6,13 @@ module.exports = {
inputs: {
payload: {
type: 'json',
required: true
}
required: true,
},
},
fn: function(inputs, exits) {
fn(inputs, exits) {
const token = jwt.sign(inputs.payload, sails.config.session.secret);
return exits.success(token);
}
},
};

View file

@ -2,22 +2,22 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const action = await Action.updateOne(inputs.record.id).set(inputs.values);
if (action) {
@ -25,12 +25,12 @@ module.exports = {
`board:${inputs.board.id}`,
'actionUpdate',
{
item: action
item: action,
},
inputs.request
inputs.request,
);
}
return exits.success(action);
}
},
};

View file

@ -2,52 +2,49 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
(_.isUndefined(value.position) || _.isFinite(value.position)),
required: true
// eslint-disable-next-line max-len
custom: (value) => _.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(
inputs.record.projectId
);
async fn(inputs, exits) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(inputs.record.projectId);
if (!_.isUndefined(inputs.values.position)) {
const boards = await sails.helpers.getBoardsForProject(
inputs.record.projectId,
inputs.record.id
inputs.record.id,
);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
boards
boards,
);
inputs.values.position = position;
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
projectId: inputs.record.projectId
projectId: inputs.record.projectId,
}).set({
position
position: nextPosition,
});
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
position
}
position: nextPosition,
},
});
});
});
@ -56,18 +53,18 @@ 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',
{
item: board
item: board,
},
inputs.request
inputs.request,
);
});
}
return exits.success(board);
}
},
};

View file

@ -2,32 +2,31 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
(_.isUndefined(value.position) || _.isFinite(value.position)),
required: true
// eslint-disable-next-line max-len
custom: (value) => _.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},
toList: {
type: 'ref'
type: 'ref',
},
list: {
type: 'ref',
required: true
required: true,
},
user: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const { isSubscribed, ...values } = inputs.values;
let listId;
@ -44,36 +43,26 @@ module.exports = {
}
if (!_.isUndefined(values.position)) {
const cards = await sails.helpers.getCardsForList(
listId,
inputs.record.id
);
const cards = await sails.helpers.getCardsForList(listId, inputs.record.id);
const { position, repositions } = sails.helpers.insertToPositionables(
values.position,
cards
);
const { position, repositions } = sails.helpers.insertToPositionables(values.position, cards);
values.position = position;
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await Card.update({
id,
listId
listId,
}).set({
position
position: nextPosition,
});
sails.sockets.broadcast(
`board:${inputs.record.boardId}`,
'cardUpdate',
{
item: {
id,
position
}
}
);
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
item: {
id,
position: nextPosition,
},
});
});
}
@ -89,21 +78,19 @@ module.exports = {
`board:${card.boardId}`,
'cardUpdate',
{
item: card
item: card,
},
inputs.request
inputs.request,
);
if (inputs.toList) {
const values = {
await sails.helpers.createAction(card, inputs.user, {
type: 'moveCard',
data: {
fromList: _.pick(inputs.list, ['id', 'name']),
toList: _.pick(inputs.toList, ['id', 'name'])
}
};
await sails.helpers.createAction(card, inputs.user, values);
toList: _.pick(inputs.toList, ['id', 'name']),
},
});
}
} else {
card = inputs.record;
@ -112,19 +99,19 @@ module.exports = {
if (!_.isUndefined(isSubscribed)) {
const cardSubscription = await CardSubscription.findOne({
cardId: card.id,
userId: inputs.user.id
userId: inputs.user.id,
});
if (isSubscribed !== !!cardSubscription) {
if (isSubscribed) {
await CardSubscription.create({
cardId: card.id,
userId: inputs.user.id
userId: inputs.user.id,
}).tolerate('E_UNIQUE');
} else {
await CardSubscription.destroyOne({
cardId: card.id,
userId: inputs.user.id
userId: inputs.user.id,
});
}
@ -134,14 +121,14 @@ module.exports = {
{
item: {
isSubscribed,
id: card.id
}
id: card.id,
},
},
inputs.request
inputs.request,
);
}
}
return exits.success(card);
}
},
};

View file

@ -2,18 +2,18 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const label = await Label.updateOne(inputs.record.id).set(inputs.values);
if (label) {
@ -21,12 +21,12 @@ module.exports = {
`board:${label.boardId}`,
'labelUpdate',
{
item: label
item: label,
},
inputs.request
inputs.request,
);
}
return exits.success(label);
}
},
};

View file

@ -2,52 +2,44 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
(_.isUndefined(value.position) || _.isFinite(value.position)),
required: true
// eslint-disable-next-line max-len
custom: (value) => _.isPlainObject(value) && (_.isUndefined(value.position) || _.isFinite(value.position)),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
if (!_.isUndefined(inputs.values.position)) {
const lists = await sails.helpers.getListsForBoard(
inputs.record.boardId,
inputs.record.id
);
const lists = await sails.helpers.getListsForBoard(inputs.record.boardId, inputs.record.id);
const { position, repositions } = sails.helpers.insertToPositionables(
inputs.values.position,
lists
lists,
);
inputs.values.position = position;
repositions.forEach(async ({ id, position }) => {
repositions.forEach(async ({ id, position: nextPosition }) => {
await List.update({
id,
boardId: inputs.record.boardId
boardId: inputs.record.boardId,
}).set({
position
position: nextPosition,
});
sails.sockets.broadcast(
`board:${inputs.record.boardId}`,
'listUpdate',
{
item: {
id,
position
}
}
);
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'listUpdate', {
item: {
id,
position: nextPosition,
},
});
});
}
@ -58,12 +50,12 @@ module.exports = {
`board:${list.boardId}`,
'listUpdate',
{
item: list
item: list,
},
inputs.request
inputs.request,
);
}
return exits.success(list);
}
},
};

View file

@ -2,41 +2,41 @@ module.exports = {
inputs: {
ids: {
type: 'json',
custom: value => _.isArray(value),
required: true
custom: (value) => _.isArray(value),
required: true,
},
user: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const notifications = await Notification.update({
id: inputs.ids,
userId: inputs.user.id
userId: inputs.user.id,
})
.set(inputs.values)
.fetch();
notifications.forEach(notification => {
notifications.forEach((notification) => {
sails.sockets.broadcast(
`user:${notification.userId}`,
'notificationUpdate',
{
item: notification
item: notification,
},
inputs.request
inputs.request,
);
});
return exits.success(notifications);
}
},
};

View file

@ -2,39 +2,35 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
const project = await Project.updateOne(inputs.record.id).set(
inputs.values
);
async fn(inputs, exits) {
const project = await Project.updateOne(inputs.record.id).set(inputs.values);
if (project) {
const userIds = await sails.helpers.getMembershipUserIdsForProject(
project.id
);
const userIds = await sails.helpers.getMembershipUserIdsForProject(project.id);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectUpdate',
{
item: project
item: project,
},
inputs.request
inputs.request,
);
});
}
return exits.success(project);
}
},
};

View file

@ -2,22 +2,22 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
required: true
required: true,
},
board: {
type: 'ref',
required: true
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
const task = await Task.updateOne(inputs.record.id).set(inputs.values);
if (task) {
@ -25,12 +25,12 @@ module.exports = {
`board:${inputs.board.id}`,
'taskUpdate',
{
item: task
item: task,
},
inputs.request
inputs.request,
);
}
return exits.success(task);
}
},
};

View file

@ -6,26 +6,25 @@ module.exports = {
inputs: {
record: {
type: 'ref',
required: true
required: true,
},
values: {
type: 'json',
custom: value =>
_.isPlainObject(value) &&
(_.isUndefined(value.email) || _.isString(value.email)) &&
(_.isUndefined(value.password) || _.isString(value.password)),
required: true
custom: (value) => _.isPlainObject(value)
&& (_.isUndefined(value.email) || _.isString(value.email))
&& (_.isUndefined(value.password) || _.isString(value.password)),
required: true,
},
request: {
type: 'ref'
}
type: 'ref',
},
},
exits: {
conflict: {}
conflict: {},
},
fn: async function(inputs, exits) {
async fn(inputs, exits) {
if (!_.isUndefined(inputs.values.email)) {
inputs.values.email = inputs.values.email.toLowerCase();
}
@ -42,48 +41,48 @@ module.exports = {
const user = await User.updateOne({
id: inputs.record.id,
deletedAt: null
deletedAt: null,
})
.set(inputs.values)
.intercept({
message: 'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"'
}, 'conflict');
.intercept(
{
message:
'Unexpected error from database adapter: conflicting key value violates exclusion constraint "user_email_unique"',
},
'conflict',
);
if (user) {
if (inputs.record.avatar && user.avatar !== inputs.record.avatar) {
try {
fs.unlinkSync(
path.join(sails.config.custom.uploadsPath, inputs.record.avatar)
);
} catch (unusedError) {}
fs.unlinkSync(path.join(sails.config.custom.uploadsPath, inputs.record.avatar));
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console
}
}
if (!isOnlyPasswordChange) {
const adminUserIds = await sails.helpers.getAdminUserIds();
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
user.id
);
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(user.id);
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(
projectIds
);
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(projectIds);
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
userIds.forEach(userId => {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'userUpdate',
{
item: user
item: user,
},
inputs.request
inputs.request,
);
});
}
}
return exits.success(user);
}
},
};

View file

@ -6,23 +6,23 @@ module.exports = {
inputs: {
token: {
type: 'string',
required: true
}
required: true,
},
},
exits: {
notValid: {}
notValid: {},
},
fn: function(inputs, exits) {
fn(inputs, exits) {
let payload;
try {
payload = jwt.verify(inputs.token, sails.config.session.secret);
} catch (unusedError) {
} catch (error) {
throw 'notValid';
}
return exits.success(payload);
}
},
};