Skip to content

Commit

Permalink
Merge branch 'master' into improveDropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed Dec 21, 2016
2 parents 13d09a2 + 796b4f4 commit 18da368
Show file tree
Hide file tree
Showing 15 changed files with 969 additions and 15 deletions.
34 changes: 34 additions & 0 deletions api/v1/controllers/aspects.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,40 @@ module.exports = {
.catch((err) => u.handleError(next, err, helper.modelName));
}, // getAspectWriter

/**
* POST /aspects/{key}/writers
*
* Add one or more users to an aspect’s list of authorized writers
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
postAspectWriters(req, res, next) {
const params = req.swagger.params;
const toPost = params.queryBody.value;
const options = {};
let usersInsts;
options.where = u.whereClauseForNameInArr(toPost);
userProps.model.findAll(options)
.then((usrs) => {
usersInsts = usrs;
return u.findByKey(helper, req.swagger.params);
})
.then((asp) => asp.addWriters(usersInsts))
.then((o) => {
/*
* The resolved object is either an array of arrays (when
* writers are added) or just an empty array when no writers are added.
* The popping is done to get the array from the array of arrays
*/
let retval = o.length ? o.pop() : o;
retval = u.responsify(retval, helper, req.method);
res.status(httpStatus.CREATED).json(retval);
})
.catch((err) => u.handleError(next, err, helper.modelName));
}, // postAspectWriters

/**
* PATCH /aspects/{key}
*
Expand Down
34 changes: 34 additions & 0 deletions api/v1/controllers/lenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,40 @@ module.exports = {
.catch((err) => u.handleError(next, err, helper.modelName));
}, // getLensWriter

/**
* POST /lenses/{key}/writers
*
* Add one or more users to a lens’ list of authorized writers
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
postLensWriters(req, res, next) {
const params = req.swagger.params;
const toPost = params.queryBody.value;
const options = {};
let usersInsts;
options.where = u.whereClauseForNameInArr(toPost);
userProps.model.findAll(options)
.then((usrs) => {
usersInsts = usrs;
return u.findByKey(helper, req.swagger.params);
})
.then((lns) => lns.addWriters(usersInsts))
.then((o) => {
/*
* The resolved object is either an array of arrays (when
* writers are added) or just an empty array when no writers are added.
* The popping is done to get the array from the array of arrays
*/
let retval = o.length ? o.pop() : o;
retval = u.responsify(retval, helper, req.method);
res.status(httpStatus.CREATED).json(retval);
})
.catch((err) => u.handleError(next, err, helper.modelName));
}, // postLensWriters

/**
* GET /lenses/{key}
*
Expand Down
35 changes: 35 additions & 0 deletions api/v1/controllers/perspectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,41 @@ module.exports = {
})
.catch((err) => u.handleError(next, err, helper.modelName));
}, // getPerspectivesWriter

/**
* POST /perspectives/{key}/writers
*
* Add one or more users to an perspective’s list of authorized writers
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
postPerspectiveWriters(req, res, next) {
const params = req.swagger.params;
const toPost = params.queryBody.value;
const options = {};
let usersInsts;
options.where = u.whereClauseForNameInArr(toPost);
userProps.model.findAll(options)
.then((usrs) => {
usersInsts = usrs;
return u.findByKey(helper, req.swagger.params);
})
.then((pers) => pers.addWriters(usersInsts))
.then((o) => {
/*
* The resolved object is either an array of arrays (when
* writers are added) or just an empty array when no writers are added.
* The popping is done to get the array from the array of arrays
*/
let retval = o.length ? o.pop() : o;
retval = u.responsify(retval, helper, req.method);
res.status(httpStatus.CREATED).json(retval);
})
.catch((err) => u.handleError(next, err, helper.modelName));
}, // postPerspectiveWriters

/**
* PATCH /perspectives/{key}
*
Expand Down
34 changes: 34 additions & 0 deletions api/v1/controllers/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ module.exports = {
.catch((err) => u.handleError(next, err, helper.modelName));
}, // getSubjectWriter

/**
* POST /subjects/{key}/writers
*
* Add one or more users to an subject’s list of authorized writers
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
postSubjectWriters(req, res, next) {
const params = req.swagger.params;
const toPost = params.queryBody.value;
const options = {};
let usersInsts;
options.where = u.whereClauseForNameInArr(toPost);
userProps.model.findAll(options)
.then((usrs) => {
usersInsts = usrs;
return u.findByKey(helper, req.swagger.params);
})
.then((subj) => subj.addWriters(usersInsts))
.then((o) => {
/*
* The resolved object is either an array of arrays (when
* writers are added) or just an empty array when no writers are added.
* The popping is done to get the array from the array of arrays
*/
let retval = o.length ? o.pop() : o;
retval = u.responsify(retval, helper, req.method);
res.status(httpStatus.CREATED).json(retval);
})
.catch((err) => u.handleError(next, err, helper.modelName));
}, // postSubjectWriters

/**
* PATCH /subjects/{key}
*
Expand Down
16 changes: 16 additions & 0 deletions api/v1/helpers/verbs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ function whereClauseForNameOrId(nameOrId) {
} else {
whr.name = nameOrId;
}

return whr;
} // whereClauseForNameOrId

/**
* Returns a where clause object that uses the "IN" operator
* @param {Array} arr - An array that needs to be assigned to the "IN" operator
* @returns {Object} - An where clause object
*/
function whereClauseForNameInArr(arr) {
const whr = {};

whr.name = {};
whr.name[constants.SEQ_IN] = arr;
return whr;
} // whereClauseForNameOrId

Expand Down Expand Up @@ -608,6 +622,8 @@ module.exports = {

whereClauseForNameOrId,

whereClauseForNameInArr,

throwErrorForEmptyArray,

cleanAndStripNulls,
Expand Down

0 comments on commit 18da368

Please sign in to comment.