mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
31
server/.editorconfig
Normal file
31
server/.editorconfig
Normal file
|
@ -0,0 +1,31 @@
|
|||
################################################
|
||||
# ╔═╗╔╦╗╦╔╦╗╔═╗╦═╗┌─┐┌─┐┌┐┌┌─┐┬┌─┐
|
||||
# ║╣ ║║║ ║ ║ ║╠╦╝│ │ ││││├┤ ││ ┬
|
||||
# o╚═╝═╩╝╩ ╩ ╚═╝╩╚═└─┘└─┘┘└┘└ ┴└─┘
|
||||
#
|
||||
# > Formatting conventions for your Sails app.
|
||||
#
|
||||
# This file (`.editorconfig`) exists to help
|
||||
# maintain consistent formatting throughout the
|
||||
# files in your Sails app.
|
||||
#
|
||||
# For the sake of convention, the Sails team's
|
||||
# preferred settings are included here out of the
|
||||
# box. You can also change this file to fit your
|
||||
# team's preferences (for example, if all of the
|
||||
# developers on your team have a strong preference
|
||||
# for tabs over spaces),
|
||||
#
|
||||
# To review what each of these options mean, see:
|
||||
# http://editorconfig.org/
|
||||
#
|
||||
################################################
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
3
server/.env
Normal file
3
server/.env
Normal file
|
@ -0,0 +1,3 @@
|
|||
TZ=UTC
|
||||
DATABASE_URL=postgresql://localhost/planka
|
||||
BASE_URL=http://localhost:1337
|
0
server/.eslintignore
Normal file
0
server/.eslintignore
Normal file
88
server/.eslintrc
Normal file
88
server/.eslintrc
Normal file
|
@ -0,0 +1,88 @@
|
|||
{
|
||||
// ╔═╗╔═╗╦ ╦╔╗╔╔╦╗┬─┐┌─┐
|
||||
// ║╣ ╚═╗║ ║║║║ ║ ├┬┘│
|
||||
// o╚═╝╚═╝╩═╝╩╝╚╝ ╩ ┴└─└─┘
|
||||
// A set of basic code conventions designed to encourage quality and consistency
|
||||
// across your Sails app's code base. These rules are checked against
|
||||
// automatically any time you run `npm test`.
|
||||
//
|
||||
// > Note: If you're using mocha, you'll want to add an extra override file to your
|
||||
// > `test/` folder so that eslint will tolerate mocha-specific globals like `before`
|
||||
// > and `describe`.
|
||||
// Designed for ESLint v4.
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// For more information about any of the rules below, check out the relevant
|
||||
// reference page on eslint.org. For example, to get details on "no-sequences",
|
||||
// you would visit `http://eslint.org/docs/rules/no-sequences`. If you're unsure
|
||||
// or could use some advice, come by https://sailsjs.com/support.
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 8,
|
||||
"ecmaFeatures": {
|
||||
"experimentalObjectRestSpread": true
|
||||
}
|
||||
},
|
||||
|
||||
"globals": {
|
||||
// If "no-undef" is enabled below, be sure to list all global variables that
|
||||
// are used in this app's backend code (including the globalIds of models):
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
"Promise": true,
|
||||
"sails": true,
|
||||
"_": true
|
||||
// …and any others (e.g. `"Organization": true`)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
},
|
||||
|
||||
"rules": {
|
||||
"block-scoped-var": ["error"],
|
||||
"callback-return": ["error", ["done", "proceed", "next", "onwards", "callback", "cb"]],
|
||||
"camelcase": ["warn", {"properties":"always"}],
|
||||
"comma-style": ["warn", "last"],
|
||||
"curly": ["warn"],
|
||||
"eqeqeq": ["error", "always"],
|
||||
"eol-last": ["warn"],
|
||||
"handle-callback-err": ["error"],
|
||||
"indent": ["warn", 2, {
|
||||
"SwitchCase": 1,
|
||||
"MemberExpression": "off",
|
||||
"FunctionDeclaration": {"body":1, "parameters":"off"},
|
||||
"FunctionExpression": {"body":1, "parameters":"off"},
|
||||
"CallExpression": {"arguments":"off"},
|
||||
"ArrayExpression": 1,
|
||||
"ObjectExpression": 1,
|
||||
"ignoredNodes": ["ConditionalExpression"]
|
||||
}],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"no-dupe-keys": ["error"],
|
||||
"no-duplicate-case": ["error"],
|
||||
"no-extra-semi": ["warn"],
|
||||
"no-labels": ["error"],
|
||||
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
||||
"no-redeclare": ["warn"],
|
||||
"no-return-assign": ["error", "always"],
|
||||
"no-sequences": ["error"],
|
||||
"no-trailing-spaces": ["warn"],
|
||||
"no-undef": ["off"],
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// ^^Note: If this "no-undef" rule is enabled (set to `["error"]`), then all model globals
|
||||
// (e.g. `"Organization": true`) should be included above under "globals".
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
"no-unexpected-multiline": ["warn"],
|
||||
"no-unreachable": ["warn"],
|
||||
"no-unused-vars": ["warn", {"caughtErrors":"all", "caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)", "argsIgnorePattern": "^unused($|[A-Z].*$)", "varsIgnorePattern": "^unused($|[A-Z].*$)" }],
|
||||
"no-use-before-define": ["error", {"functions":false}],
|
||||
"one-var": ["warn", "never"],
|
||||
"prefer-arrow-callback": ["warn", {"allowNamedFunctions":true}],
|
||||
"quotes": ["warn", "single", {"avoidEscape":false, "allowTemplateLiterals":true}],
|
||||
"semi": ["warn", "always"],
|
||||
"semi-spacing": ["warn", {"before":false, "after":true}],
|
||||
"semi-style": ["warn", "last"]
|
||||
}
|
||||
|
||||
}
|
132
server/.gitignore
vendored
Normal file
132
server/.gitignore
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
################################################
|
||||
# ┌─┐┬┌┬┐╦╔═╗╔╗╔╔═╗╦═╗╔═╗
|
||||
# │ ┬│ │ ║║ ╦║║║║ ║╠╦╝║╣
|
||||
# o└─┘┴ ┴ ╩╚═╝╝╚╝╚═╝╩╚═╚═╝
|
||||
#
|
||||
# > Files to exclude from your app's repo.
|
||||
#
|
||||
# This file (`.gitignore`) is only relevant if
|
||||
# you are using git.
|
||||
#
|
||||
# It exists to signify to git that certain files
|
||||
# and/or directories should be ignored for the
|
||||
# purposes of version control.
|
||||
#
|
||||
# This keeps tmp files and sensitive credentials
|
||||
# from being uploaded to your repository. And
|
||||
# it allows you to configure your app for your
|
||||
# machine without accidentally committing settings
|
||||
# which will smash the local settings of other
|
||||
# developers on your team.
|
||||
#
|
||||
# Some reasonable defaults are included below,
|
||||
# but, of course, you should modify/extend/prune
|
||||
# to fit your needs!
|
||||
#
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Local Configuration
|
||||
#
|
||||
# Explicitly ignore files which contain:
|
||||
#
|
||||
# 1. Sensitive information you'd rather not push to
|
||||
# your git repository.
|
||||
# e.g., your personal API keys or passwords.
|
||||
#
|
||||
# 2. Developer-specific configuration
|
||||
# Basically, anything that would be annoying
|
||||
# to have to change every time you do a
|
||||
# `git pull` on your laptop.
|
||||
# e.g. your local development database, or
|
||||
# the S3 bucket you're using for file uploads
|
||||
# during development.
|
||||
#
|
||||
################################################
|
||||
|
||||
config/local.js
|
||||
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
################################################
|
||||
# Dependencies
|
||||
#
|
||||
#
|
||||
# When releasing a production app, you _could_
|
||||
# hypothetically include your node_modules folder
|
||||
# in your git repo, but during development, it
|
||||
# is always best to exclude it, since different
|
||||
# developers may be working on different kernels,
|
||||
# where dependencies would need to be recompiled
|
||||
# anyway.
|
||||
#
|
||||
# Most of the time, the node_modules folder can
|
||||
# be excluded from your code repository, even
|
||||
# in production, thanks to features like the
|
||||
# package-lock.json file / NPM shrinkwrap.
|
||||
#
|
||||
# But no matter what, since this is a Sails app,
|
||||
# you should always push up the package-lock.json
|
||||
# or shrinkwrap file to your repository, to avoid
|
||||
# accidentally pulling in upgraded dependencies
|
||||
# and breaking your code.
|
||||
#
|
||||
# That said, if you are having trouble with
|
||||
# dependencies, (particularly when using
|
||||
# `npm link`) this can be pretty discouraging.
|
||||
# But rather than just adding the lockfile to
|
||||
# your .gitignore, try this first:
|
||||
# ```
|
||||
# rm -rf node_modules
|
||||
# rm package-lock.json
|
||||
# npm install
|
||||
# ```
|
||||
#
|
||||
# [?] For more tips/advice, come by and say hi
|
||||
# over at https://sailsjs.com/support
|
||||
#
|
||||
################################################
|
||||
|
||||
node_modules
|
||||
|
||||
################################################
|
||||
#
|
||||
# > Do you use bower?
|
||||
# > re: the bower_components dir, see this:
|
||||
# > http://addyosmani.com/blog/checking-in-front-end-dependencies/
|
||||
# > (credit Addy Osmani, @addyosmani)
|
||||
#
|
||||
################################################
|
||||
|
||||
################################################
|
||||
# Temporary files generated by Sails/Waterline.
|
||||
################################################
|
||||
|
||||
.tmp/*
|
||||
!.tmp/public
|
||||
.tmp/public/uploads/*
|
||||
!.tmp/public/uploads/.gitkeep
|
||||
|
||||
################################################
|
||||
# Miscellaneous
|
||||
#
|
||||
# Common files generated by text editors,
|
||||
# operating systems, file systems, dbs, etc.
|
||||
################################################
|
||||
|
||||
*~
|
||||
*#
|
||||
.DS_STORE
|
||||
.netbeans
|
||||
nbproject
|
||||
.idea
|
||||
.node_history
|
||||
dump.rdb
|
||||
|
||||
npm-debug.log
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.out
|
||||
*.pid
|
16
server/.sailsrc
Normal file
16
server/.sailsrc
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"generators": {
|
||||
"modules": {}
|
||||
},
|
||||
"_generatedWith": {
|
||||
"sails": "1.1.0",
|
||||
"sails-generate": "1.16.4"
|
||||
},
|
||||
"hooks": {
|
||||
"blueprints": false,
|
||||
"grunt": false,
|
||||
"i18n": false,
|
||||
"session": false,
|
||||
"views": false
|
||||
}
|
||||
}
|
0
server/.tmp/public/uploads/.gitkeep
Normal file
0
server/.tmp/public/uploads/.gitkeep
Normal file
1
server/README.md
Normal file
1
server/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# Planka server
|
0
server/api/controllers/.gitkeep
Normal file
0
server/api/controllers/.gitkeep
Normal file
48
server/api/controllers/access-tokens/create.js
Executable file
48
server/api/controllers/access-tokens/create.js
Executable file
|
@ -0,0 +1,48 @@
|
|||
const bcrypt = require('bcrypt');
|
||||
|
||||
const Errors = {
|
||||
EMAIL_NOT_EXIST: {
|
||||
unauthorized: 'Email does not exist'
|
||||
},
|
||||
PASSWORD_NOT_VALID: {
|
||||
unauthorized: 'Password is not valid'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
email: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
isEmail: true
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
unauthorized: {
|
||||
responseType: 'unauthorized'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const user = await sails.helpers.getUser({
|
||||
email: inputs.email.toLowerCase()
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw Errors.EMAIL_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (!bcrypt.compareSync(inputs.password, user.password)) {
|
||||
throw Errors.PASSWORD_NOT_VALID;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: sails.helpers.signToken(user.id)
|
||||
});
|
||||
}
|
||||
};
|
55
server/api/controllers/actions/index.js
Executable file
55
server/api/controllers/actions/index.js
Executable file
|
@ -0,0 +1,55 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
beforeId: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const actions = await sails.helpers.getActionsForCard(
|
||||
inputs.cardId,
|
||||
inputs.beforeId
|
||||
);
|
||||
|
||||
const userIds = sails.helpers.mapRecords(actions, 'userId', true);
|
||||
const users = await sails.helpers.getUsers(userIds);
|
||||
|
||||
return exits.success({
|
||||
items: actions,
|
||||
included: {
|
||||
users
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
48
server/api/controllers/boards/create.js
Executable file
48
server/api/controllers/boards/create.js
Executable file
|
@ -0,0 +1,48 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
notFound: 'Project is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
projectId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const project = await Project.findOne(inputs.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const board = await sails.helpers.createBoard(project, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: board,
|
||||
included: {
|
||||
lists: [],
|
||||
labels: []
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
38
server/api/controllers/boards/delete.js
Executable file
38
server/api/controllers/boards/delete.js
Executable file
|
@ -0,0 +1,38 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let board = await Board.findOne(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
board = await sails.helpers.deleteBoard(board, this.req);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: board
|
||||
});
|
||||
}
|
||||
};
|
84
server/api/controllers/boards/show.js
Executable file
84
server/api/controllers/boards/show.js
Executable file
|
@ -0,0 +1,84 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
}
|
||||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getBoardToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const lists = await sails.helpers.getListsForBoard(board.id);
|
||||
const labels = await sails.helpers.getLabelsForBoard(board.id);
|
||||
|
||||
const cards = await sails.helpers.getCardsForBoard(board.id);
|
||||
const cardIds = sails.helpers.mapRecords(cards);
|
||||
|
||||
const cardSubscriptions = await sails.helpers.getSubscriptionsByUserForCard(
|
||||
cardIds,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
const cardMemberships = await sails.helpers.getMembershipsForCard(cardIds);
|
||||
const cardLabels = await sails.helpers.getCardLabelsForCard(cardIds);
|
||||
|
||||
const tasks = await sails.helpers.getTasksForCard(cardIds);
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
...result,
|
||||
[cardSubscription.cardId]: true
|
||||
}),
|
||||
{}
|
||||
);
|
||||
|
||||
cards.forEach(card => {
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||
});
|
||||
|
||||
sails.sockets.join(this.req, `board:${board.id}`); // TODO: only when subscription needed
|
||||
|
||||
return exits.success({
|
||||
item: board,
|
||||
included: {
|
||||
lists,
|
||||
labels,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
tasks
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/boards/update.js
Executable file
47
server/api/controllers/boards/update.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let board = await Board.findOne(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
board = await sails.helpers.updateBoard(board, values, this.req);
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: board
|
||||
});
|
||||
}
|
||||
};
|
67
server/api/controllers/card-labels/create.js
Executable file
67
server/api/controllers/card-labels/create.js
Executable file
|
@ -0,0 +1,67 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
LABEL_NOT_FOUND: {
|
||||
notFound: 'Label is not found'
|
||||
},
|
||||
CARD_LABEL_EXIST: {
|
||||
conflict: 'Card label is already exist'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
labelId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
},
|
||||
conflict: {
|
||||
responseType: 'conflict'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const label = await Label.findOne({
|
||||
id: inputs.labelId,
|
||||
boardId: card.boardId
|
||||
});
|
||||
|
||||
if (!label) {
|
||||
throw Errors.LABEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardLabel = await sails.helpers
|
||||
.createCardLabel(card, label, this.req)
|
||||
.intercept('conflict', () => Errors.CARD_LABEL_EXIST);
|
||||
|
||||
return exits.success({
|
||||
item: cardLabel
|
||||
});
|
||||
}
|
||||
};
|
63
server/api/controllers/card-labels/delete.js
Executable file
63
server/api/controllers/card-labels/delete.js
Executable file
|
@ -0,0 +1,63 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
CARD_LABEL_NOT_FOUND: {
|
||||
notFound: 'Card label is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
labelId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
let cardLabel = await CardLabel.findOne({
|
||||
cardId: inputs.cardId,
|
||||
labelId: inputs.labelId
|
||||
});
|
||||
|
||||
if (!cardLabel) {
|
||||
throw Errors.CARD_LABEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
cardLabel = await sails.helpers.deleteCardLabel(cardLabel, board, this.req);
|
||||
|
||||
if (!cardLabel) {
|
||||
throw Errors.CARD_LABEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: cardLabel
|
||||
});
|
||||
}
|
||||
};
|
67
server/api/controllers/card-memberships/create.js
Executable file
67
server/api/controllers/card-memberships/create.js
Executable file
|
@ -0,0 +1,67 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
},
|
||||
CARD_MEMBERSHIP_EXIST: {
|
||||
conflict: 'Card membership is already exist'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
},
|
||||
conflict: {
|
||||
responseType: 'conflict'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
let isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
inputs.userId
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const cardMembership = await sails.helpers
|
||||
.createCardMembership(card, inputs.userId, this.req)
|
||||
.intercept('conflict', () => Errors.CARD_MEMBERSHIP_EXIST);
|
||||
|
||||
return exits.success({
|
||||
item: cardMembership
|
||||
});
|
||||
}
|
||||
};
|
67
server/api/controllers/card-memberships/delete.js
Executable file
67
server/api/controllers/card-memberships/delete.js
Executable file
|
@ -0,0 +1,67 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
CARD_MEMBERSHIP_NOT_FOUND: {
|
||||
notFound: 'Card membership is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
let cardMembership = await CardMembership.findOne({
|
||||
cardId: inputs.cardId,
|
||||
userId: inputs.userId
|
||||
});
|
||||
|
||||
if (!cardMembership) {
|
||||
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
|
||||
}
|
||||
|
||||
cardMembership = await sails.helpers.deleteCardMembership(
|
||||
cardMembership,
|
||||
board,
|
||||
this.req
|
||||
);
|
||||
|
||||
if (!cardMembership) {
|
||||
throw Errors.CARD_MEMBERSHIP_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: cardMembership
|
||||
});
|
||||
}
|
||||
};
|
84
server/api/controllers/cards/create.js
Executable file
84
server/api/controllers/cards/create.js
Executable file
|
@ -0,0 +1,84 @@
|
|||
const moment = require('moment');
|
||||
|
||||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
notFound: 'List is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
listId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
allowNull: true
|
||||
},
|
||||
deadline: {
|
||||
type: 'string',
|
||||
custom: value => moment(value, moment.ISO_8601, true).isValid()
|
||||
},
|
||||
timer: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
_.size(value) === 2 &&
|
||||
(_.isNull(value.startedAt) ||
|
||||
moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
|
||||
_.isFinite(value.total)
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { list, project } = await sails.helpers
|
||||
.getListToProjectPath(inputs.listId)
|
||||
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, [
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'deadline',
|
||||
'timer'
|
||||
]);
|
||||
|
||||
const card = await sails.helpers.createCard(
|
||||
list,
|
||||
values,
|
||||
currentUser,
|
||||
this.req
|
||||
);
|
||||
|
||||
return exits.success({
|
||||
item: card
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/cards/delete.js
Executable file
47
server/api/controllers/cards/delete.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
card = await sails.helpers.deleteCard(card, this.req);
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: card
|
||||
});
|
||||
}
|
||||
};
|
41
server/api/controllers/cards/show.js
Executable file
41
server/api/controllers/cards/show.js
Executable file
|
@ -0,0 +1,41 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: card
|
||||
});
|
||||
}
|
||||
};
|
112
server/api/controllers/cards/update.js
Executable file
112
server/api/controllers/cards/update.js
Executable file
|
@ -0,0 +1,112 @@
|
|||
const moment = require('moment');
|
||||
|
||||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
notFound: 'List is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
listId: {
|
||||
type: 'number'
|
||||
},
|
||||
position: {
|
||||
type: 'number'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
allowNull: true
|
||||
},
|
||||
deadline: {
|
||||
type: 'string',
|
||||
custom: value => moment(value, moment.ISO_8601, true).isValid(),
|
||||
allowNull: true
|
||||
},
|
||||
timer: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
_.size(value) === 2 &&
|
||||
(_.isNull(value.startedAt) ||
|
||||
moment(value.startedAt, moment.ISO_8601, true).isValid()) &&
|
||||
_.isFinite(value.total)
|
||||
},
|
||||
isSubscribed: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { card, list, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
let toList;
|
||||
if (!_.isUndefined(inputs.listId) && inputs.listId !== list.id) {
|
||||
toList = await List.findOne({
|
||||
id: inputs.listId,
|
||||
boardId: card.boardId
|
||||
});
|
||||
|
||||
if (!toList) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, [
|
||||
'position',
|
||||
'name',
|
||||
'description',
|
||||
'deadline',
|
||||
'timer',
|
||||
'isSubscribed'
|
||||
]);
|
||||
|
||||
card = await sails.helpers.updateCard(
|
||||
card,
|
||||
values,
|
||||
toList,
|
||||
list,
|
||||
currentUser,
|
||||
this.req
|
||||
);
|
||||
|
||||
if (!card) {
|
||||
throw Errors.CARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: card
|
||||
});
|
||||
}
|
||||
};
|
52
server/api/controllers/comment-actions/create.js
Executable file
52
server/api/controllers/comment-actions/create.js
Executable file
|
@ -0,0 +1,52 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = {
|
||||
type: 'commentCard',
|
||||
data: _.pick(inputs, ['text'])
|
||||
};
|
||||
|
||||
const action = await sails.helpers.createAction(card, currentUser, values);
|
||||
|
||||
return exits.success({
|
||||
item: action
|
||||
});
|
||||
}
|
||||
};
|
56
server/api/controllers/comment-actions/delete.js
Executable file
56
server/api/controllers/comment-actions/delete.js
Executable file
|
@ -0,0 +1,56 @@
|
|||
const Errors = {
|
||||
COMMENT_ACTION_NOT_FOUND: {
|
||||
notFound: 'Comment action is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const criteria = {
|
||||
id: inputs.id,
|
||||
type: 'commentCard'
|
||||
};
|
||||
|
||||
if (!currentUser.isAdmin) {
|
||||
criteria.userId = currentUser.id;
|
||||
}
|
||||
|
||||
let { action, board, project } = await sails.helpers
|
||||
.getActionToProjectPath(criteria)
|
||||
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
action = await sails.helpers.deleteAction(action, board, this.req);
|
||||
|
||||
if (!action) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: action
|
||||
});
|
||||
}
|
||||
};
|
59
server/api/controllers/comment-actions/update.js
Executable file
59
server/api/controllers/comment-actions/update.js
Executable file
|
@ -0,0 +1,59 @@
|
|||
const Errors = {
|
||||
COMMENT_ACTION_NOT_FOUND: {
|
||||
notFound: 'Comment action is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { action, board, project } = await sails.helpers
|
||||
.getActionToProjectPath({
|
||||
id: inputs.id,
|
||||
type: 'commentCard',
|
||||
userId: currentUser.id
|
||||
})
|
||||
.intercept('notFound', () => Errors.COMMENT_ACTION_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = {
|
||||
data: _.pick(inputs, ['text'])
|
||||
};
|
||||
|
||||
action = await sails.helpers.updateAction(action, values, board, this.req);
|
||||
|
||||
if (!action) {
|
||||
throw Errors.COMMENT_ACTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: action
|
||||
});
|
||||
}
|
||||
};
|
54
server/api/controllers/labels/create.js
Executable file
54
server/api/controllers/labels/create.js
Executable file
|
@ -0,0 +1,54 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
boardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
color: {
|
||||
type: 'string',
|
||||
isIn: Label.COLORS,
|
||||
allowNull: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getBoardToProjectPath(inputs.boardId)
|
||||
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
|
||||
const label = await sails.helpers.createLabel(board, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: label
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/labels/delete.js
Executable file
47
server/api/controllers/labels/delete.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
LABEL_NOT_FOUND: {
|
||||
notFound: 'Label is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { label, project } = await sails.helpers
|
||||
.getLabelToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LABEL_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
label = await sails.helpers.deleteLabel(label, this.req);
|
||||
|
||||
if (!label) {
|
||||
throw Errors.LABEL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: label
|
||||
});
|
||||
}
|
||||
};
|
54
server/api/controllers/labels/update.js
Executable file
54
server/api/controllers/labels/update.js
Executable file
|
@ -0,0 +1,54 @@
|
|||
const Errors = {
|
||||
LABEL_NOT_FOUND: {
|
||||
notFound: 'Label is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
},
|
||||
color: {
|
||||
type: 'string',
|
||||
isIn: Label.COLORS,
|
||||
allowNull: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { label, project } = await sails.helpers
|
||||
.getLabelToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.LABEL_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LABEL_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
|
||||
label = await sails.helpers.updateLabel(label, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: label
|
||||
});
|
||||
}
|
||||
};
|
53
server/api/controllers/lists/create.js
Executable file
53
server/api/controllers/lists/create.js
Executable file
|
@ -0,0 +1,53 @@
|
|||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
notFound: 'Board is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
boardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers
|
||||
.getBoardToProjectPath(inputs.boardId)
|
||||
.intercept('notFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const list = await sails.helpers.createList(board, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: list
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/lists/delete.js
Executable file
47
server/api/controllers/lists/delete.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
notFound: 'List is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { list, project } = await sails.helpers
|
||||
.getListToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
list = await sails.helpers.deleteList(list, this.req);
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: list
|
||||
});
|
||||
}
|
||||
};
|
56
server/api/controllers/lists/update.js
Executable file
56
server/api/controllers/lists/update.js
Executable file
|
@ -0,0 +1,56 @@
|
|||
const Errors = {
|
||||
LIST_NOT_FOUND: {
|
||||
notFound: 'List is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: 'number'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { list, project } = await sails.helpers
|
||||
.getListToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.LIST_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
list = await sails.helpers.updateList(list, values, this.req);
|
||||
|
||||
if (!list) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: list
|
||||
});
|
||||
}
|
||||
};
|
27
server/api/controllers/notifications/index.js
Executable file
27
server/api/controllers/notifications/index.js
Executable file
|
@ -0,0 +1,27 @@
|
|||
module.exports = {
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const notifications = await sails.helpers.getNotificationsForUser(
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
const actionIds = sails.helpers.mapRecords(notifications, 'actionId');
|
||||
const actions = await sails.helpers.getActions(actionIds);
|
||||
|
||||
const cardIds = sails.helpers.mapRecords(notifications, 'cardId');
|
||||
const cards = await sails.helpers.getCards(cardIds);
|
||||
|
||||
const userIds = sails.helpers.mapRecords(actions, 'userId', true);
|
||||
const users = await sails.helpers.getUsers(userIds);
|
||||
|
||||
return exits.success({
|
||||
items: notifications,
|
||||
included: {
|
||||
users,
|
||||
cards,
|
||||
actions
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
35
server/api/controllers/notifications/update.js
Executable file
35
server/api/controllers/notifications/update.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
ids: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
regex: /^[0-9]+(,[0-9]+)*$/
|
||||
},
|
||||
isRead: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const values = _.pick(inputs, ['isRead']);
|
||||
|
||||
const notifications = await sails.helpers.updateNotificationsForUser(
|
||||
inputs.ids.split(','),
|
||||
currentUser,
|
||||
values,
|
||||
this.req
|
||||
);
|
||||
|
||||
return exits.success({
|
||||
items: notifications
|
||||
});
|
||||
}
|
||||
};
|
58
server/api/controllers/project-memberships/create.js
Executable file
58
server/api/controllers/project-memberships/create.js
Executable file
|
@ -0,0 +1,58 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
notFound: 'Project is not found'
|
||||
},
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
},
|
||||
PROJECT_MEMBERSHIP_EXIST: {
|
||||
conflict: 'Project membership is already exist'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
projectId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
userId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
},
|
||||
conflict: {
|
||||
responseType: 'conflict'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const project = await Project.findOne(inputs.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const user = await sails.helpers.getUser(inputs.userId);
|
||||
|
||||
if (!user) {
|
||||
throw Error.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const projectMembership = await sails.helpers
|
||||
.createProjectMembership(project, user, this.req)
|
||||
.intercept('conflict', () => Errors.PROJECT_MEMBERSHIP_EXIST);
|
||||
|
||||
return exits.success({
|
||||
item: projectMembership,
|
||||
included: {
|
||||
users: [user]
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
41
server/api/controllers/project-memberships/delete.js
Executable file
41
server/api/controllers/project-memberships/delete.js
Executable file
|
@ -0,0 +1,41 @@
|
|||
const Errors = {
|
||||
PROJECT_MEMBERSHIP_NOT_FOUND: {
|
||||
notFound: 'Project membership is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let projectMembership = await ProjectMembership.findOne(inputs.id);
|
||||
|
||||
if (!projectMembership) {
|
||||
throw Errors.PROJECT_MEMBERSHIP_NOT_FOUND;
|
||||
}
|
||||
|
||||
projectMembership = await sails.helpers.deleteProjectMembership(
|
||||
projectMembership,
|
||||
this.req
|
||||
);
|
||||
|
||||
if (!projectMembership) {
|
||||
throw Errors.PROJECT_MEMBERSHIP_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: projectMembership
|
||||
});
|
||||
}
|
||||
};
|
30
server/api/controllers/projects/create.js
Executable file
30
server/api/controllers/projects/create.js
Executable file
|
@ -0,0 +1,30 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const values = _.pick(inputs, ['name']);
|
||||
|
||||
const { project, projectMembership } = await sails.helpers.createProject(
|
||||
values,
|
||||
currentUser,
|
||||
this.req,
|
||||
true
|
||||
);
|
||||
|
||||
return exits.success({
|
||||
item: project,
|
||||
included: {
|
||||
users: [currentUser],
|
||||
projectMemberships: [projectMembership],
|
||||
boards: []
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
38
server/api/controllers/projects/delete.js
Executable file
38
server/api/controllers/projects/delete.js
Executable file
|
@ -0,0 +1,38 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
notFound: 'Project is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let project = await Project.findOne(inputs.id);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
project = await sails.helpers.deleteProject(project, this.req);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: project
|
||||
});
|
||||
}
|
||||
};
|
29
server/api/controllers/projects/index.js
Executable file
29
server/api/controllers/projects/index.js
Executable file
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
const projects = await sails.helpers.getProjects(projectIds);
|
||||
|
||||
const {
|
||||
userIds,
|
||||
projectMemberships
|
||||
} = await sails.helpers.getMembershipUserIdsForProject(projectIds, true);
|
||||
|
||||
const users = await sails.helpers.getUsers(userIds);
|
||||
|
||||
const boards = await sails.helpers.getBoardsForProject(projectIds);
|
||||
|
||||
return exits.success({
|
||||
items: projects,
|
||||
included: {
|
||||
users,
|
||||
projectMemberships,
|
||||
boards
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
44
server/api/controllers/projects/update.js
Executable file
44
server/api/controllers/projects/update.js
Executable file
|
@ -0,0 +1,44 @@
|
|||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
notFound: 'Project is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let project = await Project.findOne(inputs.id);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name']);
|
||||
|
||||
project = await sails.helpers.updateProject(project, values, this.req);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: project
|
||||
});
|
||||
}
|
||||
};
|
52
server/api/controllers/tasks/create.js
Executable file
52
server/api/controllers/tasks/create.js
Executable file
|
@ -0,0 +1,52 @@
|
|||
const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
notFound: 'Card is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
cardId: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
isCompleted: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { card, project } = await sails.helpers
|
||||
.getCardToProjectPath(inputs.cardId)
|
||||
.intercept('notFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'isCompleted']);
|
||||
|
||||
const task = await sails.helpers.createTask(card, values, this.req);
|
||||
|
||||
return exits.success({
|
||||
item: task
|
||||
});
|
||||
}
|
||||
};
|
47
server/api/controllers/tasks/delete.js
Executable file
47
server/api/controllers/tasks/delete.js
Executable file
|
@ -0,0 +1,47 @@
|
|||
const Errors = {
|
||||
TASK_NOT_FOUND: {
|
||||
notFound: 'Task is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { task, board, project } = await sails.helpers
|
||||
.getTaskToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.TASK_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
task = await sails.helpers.deleteTask(task, board, this.req);
|
||||
|
||||
if (!task) {
|
||||
throw Errors.TASK_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: task
|
||||
});
|
||||
}
|
||||
};
|
56
server/api/controllers/tasks/update.js
Executable file
56
server/api/controllers/tasks/update.js
Executable file
|
@ -0,0 +1,56 @@
|
|||
const Errors = {
|
||||
TASK_NOT_FOUND: {
|
||||
notFound: 'Task is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
},
|
||||
isCompleted: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let { task, board, project } = await sails.helpers
|
||||
.getTaskToProjectPath(inputs.id)
|
||||
.intercept('notFound', () => Errors.TASK_NOT_FOUND);
|
||||
|
||||
const isUserMemberForProject = await sails.helpers.isUserMemberForProject(
|
||||
project.id,
|
||||
currentUser.id
|
||||
);
|
||||
|
||||
if (!isUserMemberForProject) {
|
||||
throw Errors.TASK_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'isCompleted']);
|
||||
|
||||
task = await sails.helpers.updateTask(task, values, board, this.req);
|
||||
|
||||
if (!task) {
|
||||
throw Errors.TASK_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: task
|
||||
});
|
||||
}
|
||||
};
|
41
server/api/controllers/users/create.js
Executable file
41
server/api/controllers/users/create.js
Executable file
|
@ -0,0 +1,41 @@
|
|||
const Errors = {
|
||||
USER_EXIST: {
|
||||
conflict: 'User is already exist'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
email: {
|
||||
type: 'string',
|
||||
isEmail: true,
|
||||
required: true
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
conflict: {
|
||||
responseType: 'conflict'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const values = _.pick(inputs, ['email', 'password', 'name']);
|
||||
|
||||
const user = await sails.helpers
|
||||
.createUser(values, this.req)
|
||||
.intercept('conflict', () => Errors.USER_EXIST);
|
||||
|
||||
return exits.success({
|
||||
item: user
|
||||
});
|
||||
}
|
||||
};
|
38
server/api/controllers/users/delete.js
Executable file
38
server/api/controllers/users/delete.js
Executable file
|
@ -0,0 +1,38 @@
|
|||
const Errors = {
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
let user = await sails.helpers.getUser(inputs.id);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
user = await sails.helpers.deleteUser(user, this.req);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: user
|
||||
});
|
||||
}
|
||||
};
|
9
server/api/controllers/users/index.js
Executable file
9
server/api/controllers/users/index.js
Executable file
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
fn: async function(inputs, exits) {
|
||||
const users = await sails.helpers.getUsers();
|
||||
|
||||
return exits.success({
|
||||
items: users
|
||||
});
|
||||
}
|
||||
};
|
16
server/api/controllers/users/show.js
Executable file
16
server/api/controllers/users/show.js
Executable file
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
fn: async function(inputs, exits) {
|
||||
// TODO: allow over HTTP without subscription
|
||||
if (!this.req.isSocket) {
|
||||
return this.res.badRequest();
|
||||
}
|
||||
|
||||
const { currentUser } = this.req;
|
||||
|
||||
sails.sockets.join(this.req, `user:${currentUser.id}`); // TODO: only when subscription needed
|
||||
|
||||
return exits.success({
|
||||
item: currentUser
|
||||
});
|
||||
}
|
||||
};
|
61
server/api/controllers/users/update.js
Executable file
61
server/api/controllers/users/update.js
Executable file
|
@ -0,0 +1,61 @@
|
|||
const Errors = {
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
isAdmin: {
|
||||
type: 'boolean'
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true
|
||||
},
|
||||
avatar: {
|
||||
type: 'json',
|
||||
custom: value => _.isNull(value)
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
if (!currentUser.isAdmin) {
|
||||
if (inputs.id !== currentUser.id) {
|
||||
throw Errors.USER_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
delete inputs.isAdmin;
|
||||
}
|
||||
|
||||
let user = await sails.helpers.getUser(inputs.id);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['isAdmin', 'name', 'avatar']);
|
||||
|
||||
user = await sails.helpers.updateUser(user, values, this.req);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
item: user
|
||||
});
|
||||
}
|
||||
};
|
124
server/api/controllers/users/upload-avatar.js
Executable file
124
server/api/controllers/users/upload-avatar.js
Executable file
|
@ -0,0 +1,124 @@
|
|||
const stream = require('stream');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const uuid = require('uuid/v4');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const Errors = {
|
||||
USER_NOT_FOUND: {
|
||||
notFound: 'User is not found'
|
||||
}
|
||||
};
|
||||
|
||||
const createReceiver = () => {
|
||||
const receiver = require('stream').Writable({ objectMode: true });
|
||||
|
||||
let firstFileHandled = false;
|
||||
receiver._write = (file, encoding, done) => {
|
||||
if (firstFileHandled) {
|
||||
file.pipe(
|
||||
new stream.Writable({
|
||||
write(chunk, encoding, callback) {
|
||||
callback();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return done();
|
||||
}
|
||||
firstFileHandled = true;
|
||||
|
||||
const resize = sharp()
|
||||
.resize(36, 36)
|
||||
.jpeg();
|
||||
|
||||
const transform = new stream.Transform({
|
||||
transform(chunk, encoding, callback) {
|
||||
callback(null, chunk);
|
||||
}
|
||||
});
|
||||
|
||||
stream.pipeline(file, resize, transform, error => {
|
||||
if (error) {
|
||||
return done(error.message);
|
||||
}
|
||||
|
||||
file.fd = `${uuid()}.jpg`;
|
||||
|
||||
const output = fs.createWriteStream(
|
||||
path.join(sails.config.custom.uploadsPath, file.fd)
|
||||
);
|
||||
|
||||
stream.pipeline(transform, output, error => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return receiver;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'number',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {
|
||||
responseType: 'notFound'
|
||||
},
|
||||
unprocessableEntity: {
|
||||
responseType: 'unprocessableEntity'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let user;
|
||||
if (currentUser.isAdmin) {
|
||||
user = await sails.helpers.getUser(inputs.id);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
} else if (inputs.id !== currentUser.id) {
|
||||
throw Errors.USER_NOT_FOUND; // Forbidden
|
||||
} else {
|
||||
user = currentUser;
|
||||
}
|
||||
|
||||
this.req.file('file').upload(createReceiver(), async (error, files) => {
|
||||
if (error) {
|
||||
return exits.unprocessableEntity(error);
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
return exits.unprocessableEntity('No file was uploaded');
|
||||
}
|
||||
|
||||
user = await sails.helpers.updateUser(
|
||||
user,
|
||||
{
|
||||
avatar: files[0].fd
|
||||
},
|
||||
this.req
|
||||
);
|
||||
|
||||
if (!user) {
|
||||
throw Errors.USER_NOT_FOUND;
|
||||
}
|
||||
|
||||
return this.res.json({
|
||||
item: user
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
0
server/api/helpers/.gitkeep
Normal file
0
server/api/helpers/.gitkeep
Normal file
52
server/api/helpers/create-action.js
Normal file
52
server/api/helpers/create-action.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const action = await Action.create({
|
||||
...inputs.values,
|
||||
cardId: inputs.card.id,
|
||||
userId: inputs.user.id
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.card.boardId}`, 'actionCreate', {
|
||||
item: action
|
||||
});
|
||||
|
||||
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(
|
||||
action.cardId,
|
||||
action.userId
|
||||
);
|
||||
|
||||
userIds.forEach(async userId => {
|
||||
const notification = await Notification.create({
|
||||
userId,
|
||||
actionId: action.id,
|
||||
cardId: action.cardId
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(`user:${userId}`, 'notificationCreate', {
|
||||
item: notification,
|
||||
included: {
|
||||
users: [inputs.user],
|
||||
cards: [inputs.card],
|
||||
actions: [action]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return exits.success(action);
|
||||
}
|
||||
};
|
70
server/api/helpers/create-board.js
Normal file
70
server/api/helpers/create-board.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const boards = await sails.helpers.getBoardsForProject(inputs.project.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
inputs.values.position,
|
||||
boards
|
||||
);
|
||||
|
||||
const userIds = await sails.helpers.getMembershipUserIdsForProject(
|
||||
inputs.project.id
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.project.id
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const board = await Board.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
projectId: inputs.project.id
|
||||
}).fetch();
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardCreate',
|
||||
{
|
||||
item: board,
|
||||
included: {
|
||||
lists: [],
|
||||
labels: []
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
|
||||
return exits.success(board);
|
||||
}
|
||||
};
|
35
server/api/helpers/create-card-label.js
Normal file
35
server/api/helpers/create-card-label.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
label: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardLabel = await CardLabel.create({
|
||||
cardId: inputs.card.id,
|
||||
labelId: inputs.label.id
|
||||
})
|
||||
.intercept('E_UNIQUE', 'conflict')
|
||||
.fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
'cardLabelCreate',
|
||||
{
|
||||
item: cardLabel
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(cardLabel);
|
||||
}
|
||||
};
|
60
server/api/helpers/create-card-membership.js
Normal file
60
server/api/helpers/create-card-membership.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
userOrUserId: {
|
||||
type: 'ref',
|
||||
custom: value => _.isPlainObject(value) || _.isFinite(value),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const { userId = inputs.userOrUserId } = inputs.userOrUserId;
|
||||
|
||||
const cardMembership = await CardMembership.create({
|
||||
userId,
|
||||
cardId: inputs.card.id
|
||||
})
|
||||
.intercept('E_UNIQUE', 'conflict')
|
||||
.fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
'cardMembershipCreate',
|
||||
{
|
||||
item: cardMembership
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
const cardSubscription = await CardSubscription.create({
|
||||
cardId: cardMembership.cardId,
|
||||
userId: cardMembership.userId,
|
||||
isPermanent: false
|
||||
})
|
||||
.tolerate('E_UNIQUE')
|
||||
.fetch();
|
||||
|
||||
if (cardSubscription) {
|
||||
sails.sockets.broadcast(
|
||||
`user:${cardMembership.userId}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: {
|
||||
id: cardMembership.cardId,
|
||||
isSubscribed: true
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(cardMembership);
|
||||
}
|
||||
};
|
72
server/api/helpers/create-card.js
Normal file
72
server/api/helpers/create-card.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cards = await sails.helpers.getCardsForList(inputs.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
inputs.values.position,
|
||||
cards
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: inputs.list.id
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${list.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const card = await Card.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
listId: inputs.list.id,
|
||||
boardId: inputs.list.boardId
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardCreate',
|
||||
{
|
||||
item: card
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
const values = {
|
||||
type: 'createCard',
|
||||
data: {
|
||||
list: _.pick(inputs.list, ['id', 'name'])
|
||||
}
|
||||
};
|
||||
|
||||
await sails.helpers.createAction(card, inputs.user, values);
|
||||
|
||||
return exits.success(card);
|
||||
}
|
||||
};
|
33
server/api/helpers/create-label.js
Normal file
33
server/api/helpers/create-label.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const label = await Label.create({
|
||||
...inputs.values,
|
||||
boardId: inputs.board.id
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${label.boardId}`,
|
||||
'labelCreate',
|
||||
{
|
||||
item: label
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(label);
|
||||
}
|
||||
};
|
58
server/api/helpers/create-list.js
Normal file
58
server/api/helpers/create-list.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const lists = await sails.helpers.getListsForBoard(inputs.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.insertToPositionables(
|
||||
inputs.values.position,
|
||||
lists
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position }) => {
|
||||
await List.update({
|
||||
id,
|
||||
boardId: inputs.board.id
|
||||
}).set({
|
||||
position
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const list = await List.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
boardId: inputs.board.id
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listCreate',
|
||||
{
|
||||
item: list
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(list);
|
||||
}
|
||||
};
|
73
server/api/helpers/create-project-membership.js
Normal file
73
server/api/helpers/create-project-membership.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
conflict: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMembership = await ProjectMembership.create({
|
||||
projectId: inputs.project.id,
|
||||
userId: inputs.user.id
|
||||
})
|
||||
.intercept('E_UNIQUE', 'conflict')
|
||||
.fetch();
|
||||
|
||||
const {
|
||||
userIds,
|
||||
projectMemberships
|
||||
} = await sails.helpers.getMembershipUserIdsForProject(
|
||||
projectMembership.projectId,
|
||||
true
|
||||
);
|
||||
|
||||
userIds.forEach(userId => {
|
||||
if (userId !== projectMembership.userId) {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectMembershipCreate',
|
||||
{
|
||||
item: projectMembership,
|
||||
included: {
|
||||
users: [inputs.user]
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const users = await sails.helpers.getUsers(userIds);
|
||||
|
||||
const boards = await sails.helpers.getBoardsForProject(
|
||||
projectMembership.projectId
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${projectMembership.userId}`,
|
||||
'projectCreate',
|
||||
{
|
||||
item: inputs.project,
|
||||
included: {
|
||||
users,
|
||||
projectMemberships,
|
||||
boards
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return exits.success(projectMembership);
|
||||
}
|
||||
};
|
51
server/api/helpers/create-project.js
Normal file
51
server/api/helpers/create-project.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
},
|
||||
withProjectMembership: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const project = await Project.create(inputs.values).fetch();
|
||||
|
||||
const projectMembership = await ProjectMembership.create({
|
||||
projectId: project.id,
|
||||
userId: inputs.user.id
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${projectMembership.userId}`,
|
||||
'projectCreate',
|
||||
{
|
||||
item: project,
|
||||
included: {
|
||||
users: [inputs.user],
|
||||
projectMemberships: [projectMembership],
|
||||
boards: []
|
||||
}
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(
|
||||
inputs.withProjectMembership
|
||||
? {
|
||||
project,
|
||||
projectMembership
|
||||
}
|
||||
: project
|
||||
);
|
||||
}
|
||||
};
|
33
server/api/helpers/create-task.js
Normal file
33
server/api/helpers/create-task.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const task = await Task.create({
|
||||
...inputs.values,
|
||||
cardId: inputs.card.id
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.card.boardId}`,
|
||||
'taskCreate',
|
||||
{
|
||||
item: task
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(task);
|
||||
}
|
||||
};
|
46
server/api/helpers/create-user.js
Normal file
46
server/api/helpers/create-user.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const bcrypt = require('bcrypt');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: value =>
|
||||
_.isPlainObject(value) &&
|
||||
_.isString(value.email) &&
|
||||
_.isString(value.password),
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
conflict: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const user = await User.create({
|
||||
...inputs.values,
|
||||
email: inputs.values.email.toLowerCase(),
|
||||
password: bcrypt.hashSync(inputs.values.password, 10)
|
||||
})
|
||||
.intercept(undefined, 'conflict')
|
||||
.fetch();
|
||||
|
||||
const userIds = await sails.helpers.getAdminUserIds();
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'userCreate',
|
||||
{
|
||||
item: user
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
|
||||
return exits.success(user);
|
||||
}
|
||||
};
|
32
server/api/helpers/delete-action.js
Normal file
32
server/api/helpers/delete-action.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const action = await Action.archiveOne(inputs.record.id);
|
||||
|
||||
if (action) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'actionDelete',
|
||||
{
|
||||
item: action
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(action);
|
||||
}
|
||||
};
|
36
server/api/helpers/delete-board.js
Normal file
36
server/api/helpers/delete-board.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const board = await Board.archiveOne(inputs.record.id);
|
||||
|
||||
if (board) {
|
||||
sails.sockets.leaveAll(`board:${board.id}`);
|
||||
|
||||
const userIds = await sails.helpers.getMembershipUserIdsForProject(
|
||||
board.projectId
|
||||
);
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardDelete',
|
||||
{
|
||||
item: board
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return exits.success(board);
|
||||
}
|
||||
};
|
32
server/api/helpers/delete-card-label.js
Normal file
32
server/api/helpers/delete-card-label.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardLabel = await CardLabel.destroyOne(inputs.record.id);
|
||||
|
||||
if (cardLabel) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'cardLabelDelete',
|
||||
{
|
||||
item: cardLabel
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(cardLabel);
|
||||
}
|
||||
};
|
47
server/api/helpers/delete-card-membership.js
Normal file
47
server/api/helpers/delete-card-membership.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardMembership = await CardMembership.destroyOne(inputs.record.id);
|
||||
|
||||
if (cardMembership) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'cardMembershipDelete',
|
||||
{
|
||||
item: cardMembership
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
const cardSubscription = await CardSubscription.destroyOne({
|
||||
cardId: cardMembership.cardId,
|
||||
userId: cardMembership.userId,
|
||||
isPermanent: false
|
||||
});
|
||||
|
||||
if (cardSubscription) {
|
||||
sails.sockets.broadcast(`user:${cardMembership.userId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: cardMembership.cardId,
|
||||
isSubscribed: false
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return exits.success(cardMembership);
|
||||
}
|
||||
};
|
28
server/api/helpers/delete-card.js
Normal file
28
server/api/helpers/delete-card.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const card = await Card.archiveOne(inputs.record.id);
|
||||
|
||||
if (card) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardDelete',
|
||||
{
|
||||
item: card
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(card);
|
||||
}
|
||||
};
|
32
server/api/helpers/delete-label.js
Normal file
32
server/api/helpers/delete-label.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
await CardLabel.destroy({
|
||||
labelId: inputs.record.id
|
||||
});
|
||||
|
||||
const label = await Label.archiveOne(inputs.record.id);
|
||||
|
||||
if (label) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${label.boardId}`,
|
||||
'labelDelete',
|
||||
{
|
||||
item: label
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(label);
|
||||
}
|
||||
};
|
26
server/api/helpers/delete-list.js
Normal file
26
server/api/helpers/delete-list.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const list = await List.archiveOne(inputs.record.id);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listDelete',
|
||||
{
|
||||
item: list
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
|
||||
return exits.success(list);
|
||||
}
|
||||
};
|
70
server/api/helpers/delete-project-membership.js
Normal file
70
server/api/helpers/delete-project-membership.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const boards = await sails.helpers.getBoardsForProject(
|
||||
inputs.record.projectId
|
||||
);
|
||||
|
||||
const boardIds = sails.helpers.mapRecords(boards);
|
||||
|
||||
const cards = await sails.helpers.getCardsForBoard(boardIds);
|
||||
const cardIds = sails.helpers.mapRecords(cards);
|
||||
|
||||
await CardSubscription.destroy({
|
||||
cardId: cardIds,
|
||||
userId: inputs.record.userId
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
cardId: cardIds,
|
||||
userId: inputs.record.userId
|
||||
});
|
||||
|
||||
const projectMembership = await ProjectMembership.destroyOne(
|
||||
inputs.record.id
|
||||
);
|
||||
|
||||
if (projectMembership) {
|
||||
const userIds = await sails.helpers.getMembershipUserIdsForProject(
|
||||
projectMembership.projectId
|
||||
);
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectMembershipDelete',
|
||||
{
|
||||
item: projectMembership
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(
|
||||
`user:${projectMembership.userId}`,
|
||||
boardIds.map(boardId => `board:${boardId}`)
|
||||
);
|
||||
|
||||
const project = await Project.findOne(projectMembership.projectId);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${projectMembership.userId}`,
|
||||
'projectDelete',
|
||||
{
|
||||
item: project
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(projectMembership);
|
||||
}
|
||||
};
|
41
server/api/helpers/delete-project.js
Normal file
41
server/api/helpers/delete-project.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await ProjectMembership.destroy({
|
||||
projectId: inputs.record.id
|
||||
}).fetch();
|
||||
|
||||
const project = await Project.archiveOne(inputs.record.id);
|
||||
|
||||
if (project) {
|
||||
const userIds = sails.helpers.mapRecords(projectMemberships, 'userId');
|
||||
|
||||
const boards = await sails.helpers.getBoardsForProject(project.id);
|
||||
const boardRooms = boards.map(board => `board:${board.id}`);
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'projectDelete',
|
||||
{
|
||||
item: project
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return exits.success(project);
|
||||
}
|
||||
};
|
32
server/api/helpers/delete-task.js
Normal file
32
server/api/helpers/delete-task.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const task = await Task.archiveOne(inputs.record.id);
|
||||
|
||||
if (task) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'taskDelete',
|
||||
{
|
||||
item: task
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
}
|
||||
|
||||
return exits.success(task);
|
||||
}
|
||||
};
|
59
server/api/helpers/delete-user.js
Normal file
59
server/api/helpers/delete-user.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true
|
||||
},
|
||||
request: {
|
||||
type: 'ref'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
await ProjectMembership.destroy({
|
||||
userId: inputs.record.id
|
||||
});
|
||||
|
||||
await CardSubscription.destroy({
|
||||
userId: inputs.record.id
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
userId: inputs.record.id
|
||||
});
|
||||
|
||||
const user = await User.updateOne({
|
||||
id: inputs.record.id,
|
||||
deletedAt: null
|
||||
}).set({
|
||||
deletedAt: new Date().toUTCString()
|
||||
});
|
||||
|
||||
if (user) {
|
||||
const adminUserIds = await sails.helpers.getAdminUserIds();
|
||||
|
||||
const projectIds = await sails.helpers.getMembershipProjectIdsForUser(
|
||||
user.id
|
||||
);
|
||||
|
||||
const userIdsForProject = await sails.helpers.getMembershipUserIdsForProject(
|
||||
projectIds
|
||||
);
|
||||
|
||||
const userIds = _.union([user.id], adminUserIds, userIdsForProject);
|
||||
|
||||
userIds.forEach(userId => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'userDelete',
|
||||
{
|
||||
item: user
|
||||
},
|
||||
inputs.request
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return exits.success(user);
|
||||
}
|
||||
};
|
34
server/api/helpers/get-action-to-project-path.js
Executable file
34
server/api/helpers/get-action-to-project-path.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const action = await Action.findOne(inputs.criteria);
|
||||
|
||||
if (!action) {
|
||||
throw 'notFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers
|
||||
.getCardToProjectPath(action.cardId)
|
||||
.intercept('notFound', path => ({
|
||||
notFound: {
|
||||
action,
|
||||
...path
|
||||
}
|
||||
}));
|
||||
|
||||
return exits.success({
|
||||
action,
|
||||
...path
|
||||
});
|
||||
}
|
||||
};
|
30
server/api/helpers/get-actions-for-card.js
Normal file
30
server/api/helpers/get-actions-for-card.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const LIMIT = 10;
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
beforeId: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const criteria = {
|
||||
cardId: inputs.id
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.beforeId)) {
|
||||
criteria.id = {
|
||||
'<': inputs.beforeId
|
||||
};
|
||||
}
|
||||
|
||||
const actions = await sails.helpers.getActions(criteria, LIMIT);
|
||||
|
||||
return exits.success(actions);
|
||||
}
|
||||
};
|
19
server/api/helpers/get-actions.js
Normal file
19
server/api/helpers/get-actions.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
},
|
||||
limit: {
|
||||
type: 'number'
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const actions = await Action.find(inputs.criteria)
|
||||
.sort('id DESC')
|
||||
.limit(inputs.limit);
|
||||
|
||||
return exits.success(actions);
|
||||
}
|
||||
};
|
11
server/api/helpers/get-admin-user-ids.js
Executable file
11
server/api/helpers/get-admin-user-ids.js
Executable file
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
fn: async function(inputs, exits) {
|
||||
const users = await sails.helpers.getUsers({
|
||||
isAdmin: true
|
||||
});
|
||||
|
||||
const userIds = sails.helpers.mapRecords(users);
|
||||
|
||||
return exits.success(userIds);
|
||||
}
|
||||
};
|
35
server/api/helpers/get-board-to-project-path.js
Executable file
35
server/api/helpers/get-board-to-project-path.js
Executable file
|
@ -0,0 +1,35 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const board = await Board.findOne(inputs.criteria);
|
||||
|
||||
if (!board) {
|
||||
throw 'notFound';
|
||||
}
|
||||
|
||||
const project = await Project.findOne(board.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
||||
notFound: {
|
||||
board
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return exits.success({
|
||||
board,
|
||||
project
|
||||
});
|
||||
}
|
||||
};
|
29
server/api/helpers/get-boards-for-project.js
Normal file
29
server/api/helpers/get-boards-for-project.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
exceptBoardId: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const criteria = {
|
||||
projectId: inputs.id
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptBoardId)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptBoardId
|
||||
};
|
||||
}
|
||||
|
||||
const boards = await sails.helpers.getBoards(criteria);
|
||||
|
||||
return exits.success(boards);
|
||||
}
|
||||
};
|
14
server/api/helpers/get-boards.js
Normal file
14
server/api/helpers/get-boards.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const boards = await Board.find(inputs.criteria).sort('position');
|
||||
|
||||
return exits.success(boards);
|
||||
}
|
||||
};
|
17
server/api/helpers/get-card-labels-for-card.js
Normal file
17
server/api/helpers/get-card-labels-for-card.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardLabels = await sails.helpers.getCardLabels({
|
||||
cardId: inputs.id
|
||||
});
|
||||
|
||||
return exits.success(cardLabels);
|
||||
}
|
||||
};
|
14
server/api/helpers/get-card-labels.js
Normal file
14
server/api/helpers/get-card-labels.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardLabels = await CardLabel.find(inputs.criteria).sort('id');
|
||||
|
||||
return exits.success(cardLabels);
|
||||
}
|
||||
};
|
16
server/api/helpers/get-card-memberships.js
Normal file
16
server/api/helpers/get-card-memberships.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardMemberships = await CardMembership.find(inputs.criteria).sort(
|
||||
'id'
|
||||
);
|
||||
|
||||
return exits.success(cardMemberships);
|
||||
}
|
||||
};
|
16
server/api/helpers/get-card-subscriptions.js
Normal file
16
server/api/helpers/get-card-subscriptions.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cardSubscriptions = await CardSubscription.find(inputs.criteria).sort(
|
||||
'id'
|
||||
);
|
||||
|
||||
return exits.success(cardSubscriptions);
|
||||
}
|
||||
};
|
34
server/api/helpers/get-card-to-project-path.js
Executable file
34
server/api/helpers/get-card-to-project-path.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const card = await Card.findOne(inputs.criteria);
|
||||
|
||||
if (!card) {
|
||||
throw 'notFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers
|
||||
.getListToProjectPath(card.listId)
|
||||
.intercept('notFound', path => ({
|
||||
notFound: {
|
||||
card,
|
||||
...path
|
||||
}
|
||||
}));
|
||||
|
||||
return exits.success({
|
||||
card,
|
||||
...path
|
||||
});
|
||||
}
|
||||
};
|
17
server/api/helpers/get-cards-for-board.js
Normal file
17
server/api/helpers/get-cards-for-board.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cards = await sails.helpers.getCards({
|
||||
boardId: inputs.id
|
||||
});
|
||||
|
||||
return exits.success(cards);
|
||||
}
|
||||
};
|
29
server/api/helpers/get-cards-for-list.js
Normal file
29
server/api/helpers/get-cards-for-list.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
exceptCardId: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const criteria = {
|
||||
listId: inputs.id
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptCardId)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptCardId
|
||||
};
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.getCards(criteria);
|
||||
|
||||
return exits.success(cards);
|
||||
}
|
||||
};
|
14
server/api/helpers/get-cards.js
Normal file
14
server/api/helpers/get-cards.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const cards = await Card.find(inputs.criteria).sort('position');
|
||||
|
||||
return exits.success(cards);
|
||||
}
|
||||
};
|
34
server/api/helpers/get-label-to-project-path.js
Executable file
34
server/api/helpers/get-label-to-project-path.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const label = await Label.findOne(inputs.criteria);
|
||||
|
||||
if (!label) {
|
||||
throw 'notFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers
|
||||
.getBoardToProjectPath(label.boardId)
|
||||
.intercept('notFound', path => ({
|
||||
notFound: {
|
||||
label,
|
||||
...path
|
||||
}
|
||||
}));
|
||||
|
||||
return exits.success({
|
||||
label,
|
||||
...path
|
||||
});
|
||||
}
|
||||
};
|
17
server/api/helpers/get-labels-for-board.js
Normal file
17
server/api/helpers/get-labels-for-board.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const labels = await Label.find({
|
||||
boardId: inputs.id
|
||||
}).sort('id');
|
||||
|
||||
return exits.success(labels);
|
||||
}
|
||||
};
|
34
server/api/helpers/get-list-to-project-path.js
Executable file
34
server/api/helpers/get-list-to-project-path.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
exits: {
|
||||
notFound: {}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const list = await List.findOne(inputs.criteria);
|
||||
|
||||
if (!list) {
|
||||
throw 'notFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers
|
||||
.getBoardToProjectPath(list.boardId)
|
||||
.intercept('notFound', path => ({
|
||||
notFound: {
|
||||
list,
|
||||
...path
|
||||
}
|
||||
}));
|
||||
|
||||
return exits.success({
|
||||
list,
|
||||
...path
|
||||
});
|
||||
}
|
||||
};
|
29
server/api/helpers/get-lists-for-board.js
Normal file
29
server/api/helpers/get-lists-for-board.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
exceptListId: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const criteria = {
|
||||
boardId: inputs.id
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptListId)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptListId
|
||||
};
|
||||
}
|
||||
|
||||
const lists = await List.find(criteria).sort('position');
|
||||
|
||||
return exits.success(lists);
|
||||
}
|
||||
};
|
23
server/api/helpers/get-membership-project-ids-for-user.js
Executable file
23
server/api/helpers/get-membership-project-ids-for-user.js
Executable file
|
@ -0,0 +1,23 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await sails.helpers.getProjectMembershipsForUser(
|
||||
inputs.id
|
||||
);
|
||||
|
||||
const projectIds = sails.helpers.mapRecords(
|
||||
projectMemberships,
|
||||
'projectId',
|
||||
_.isArray(inputs.id)
|
||||
);
|
||||
|
||||
return exits.success(projectIds);
|
||||
}
|
||||
};
|
34
server/api/helpers/get-membership-user-ids-for-project.js
Executable file
34
server/api/helpers/get-membership-user-ids-for-project.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
withProjectMemberships: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await sails.helpers.getMembershipsForProject(
|
||||
inputs.id
|
||||
);
|
||||
|
||||
const userIds = sails.helpers.mapRecords(
|
||||
projectMemberships,
|
||||
'userId',
|
||||
_.isArray(inputs.id)
|
||||
);
|
||||
|
||||
return exits.success(
|
||||
inputs.withProjectMemberships
|
||||
? {
|
||||
userIds,
|
||||
projectMemberships
|
||||
}
|
||||
: userIds
|
||||
);
|
||||
}
|
||||
};
|
29
server/api/helpers/get-memberships-for-card.js
Normal file
29
server/api/helpers/get-memberships-for-card.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
},
|
||||
exceptUserId: {
|
||||
type: 'number',
|
||||
custom: value => _.isInteger(value) || _.isArray(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const criteria = {
|
||||
cardId: inputs.id
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptUserId)) {
|
||||
criteria.userId = {
|
||||
'!=': inputs.exceptUserId
|
||||
};
|
||||
}
|
||||
|
||||
const cardMemberships = await sails.helpers.getCardMemberships(criteria);
|
||||
|
||||
return exits.success(cardMemberships);
|
||||
}
|
||||
};
|
17
server/api/helpers/get-memberships-for-project.js
Normal file
17
server/api/helpers/get-memberships-for-project.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await sails.helpers.getProjectMemberships({
|
||||
projectId: inputs.id
|
||||
});
|
||||
|
||||
return exits.success(projectMemberships);
|
||||
}
|
||||
};
|
18
server/api/helpers/get-notifications-for-user.js
Normal file
18
server/api/helpers/get-notifications-for-user.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const notifications = await sails.helpers.getNotifications({
|
||||
isRead: false,
|
||||
userId: inputs.id
|
||||
});
|
||||
|
||||
return exits.success(notifications);
|
||||
}
|
||||
};
|
16
server/api/helpers/get-notifications.js
Normal file
16
server/api/helpers/get-notifications.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const notifications = await Notification.find(inputs.criteria).sort(
|
||||
'id DESC'
|
||||
);
|
||||
|
||||
return exits.success(notifications);
|
||||
}
|
||||
};
|
17
server/api/helpers/get-project-memberships-for-user.js
Normal file
17
server/api/helpers/get-project-memberships-for-user.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'json',
|
||||
custom: value => _.isInteger(value) || _.isArray(value),
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await sails.helpers.getProjectMemberships({
|
||||
userId: inputs.id
|
||||
});
|
||||
|
||||
return exits.success(projectMemberships);
|
||||
}
|
||||
};
|
16
server/api/helpers/get-project-memberships.js
Normal file
16
server/api/helpers/get-project-memberships.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projectMemberships = await ProjectMembership.find(
|
||||
inputs.criteria
|
||||
).sort('id');
|
||||
|
||||
return exits.success(projectMemberships);
|
||||
}
|
||||
};
|
14
server/api/helpers/get-projects.js
Normal file
14
server/api/helpers/get-projects.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: value => _.isArray(value) || _.isPlainObject(value)
|
||||
}
|
||||
},
|
||||
|
||||
fn: async function(inputs, exits) {
|
||||
const projects = await Project.find(inputs.criteria).sort('id');
|
||||
|
||||
return exits.success(projects);
|
||||
}
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue