Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Moving some code out of routes and into the controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise committed Mar 23, 2017
1 parent 8ab2e78 commit 140a392
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 101 deletions.
99 changes: 99 additions & 0 deletions modules/project-comments/server/controllers/comment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,105 @@ module.exports = DBModel.extend ({
})
.then(resolve, reject);
});
},
getPeriodPaginate: function (body) {
var self = this;
// base query / filter
var periodId;
var eaoStatus;
var proponentStatus;
var isPublished;

// filter By Fields...
var commentId;
var authorComment;
var location;
var pillar;
var topic;

// pagination stuff
var skip = 0;
var limit = 50;
var sortby = {};

if (body) {
// base query / filter
if (!_.isEmpty(body.periodId)) {
periodId = body.periodId;
}
if (!_.isEmpty(body.eaoStatus)) {
eaoStatus = body.eaoStatus;
}
if (!_.isEmpty(body.proponentStatus)) {
proponentStatus = body.proponentStatus;
}
if (body.isPublished !== undefined) {
isPublished = Boolean(body.isPublished);
}
// filter By Fields...
if (!_.isEmpty(body.commentId)) {
try {
commentId = parseInt(body.commentId);
} catch(e) {

}
}
if (!_.isEmpty(body.authorComment)) {
authorComment = body.authorComment;
}
if (!_.isEmpty(body.location)) {
location = body.location;
}
if (!_.isEmpty(body.pillar)) {
pillar = body.pillar;
}
if (!_.isEmpty(body.topic)) {
topic = body.topic;
}
// pagination stuff
try {
skip = parseInt(body.start);
limit = parseInt(body.limit);
} catch(e) {
console.log("Non-critical error:", e);
}
if (body.orderBy) {
sortby[body.orderBy] = body.reverse ? -1 : 1;
}
}

return self.getCommentsForPeriod (periodId, eaoStatus, proponentStatus, isPublished, commentId, authorComment, location, pillar, topic, skip, limit, sortby);
},
getPeriodPermsSync: function (body) {
var self = this;
// base query / filter
var periodId;

// pagination stuff
var skip = 0;
var limit = 50;

var projectId; // will need this to check for createCommentPeriod permission

if (body) {
// base query / filter
if (!_.isEmpty(body.periodId)) {
periodId = body.periodId;
}
// pagination stuff
try {
skip = parseInt(body.start);
limit = parseInt(body.limit);
} catch(e) {
console.log('Invalid skip/start or limit value passed in (skip/start =', body.start, ', limit = ', body.limit, '); using defaults: skip/start = ', skip, ', limit =', limit);
}

if (!_.isEmpty(body.projectId)) {
projectId = body.projectId;
}

}
return self.updatePermissionBatch(projectId, periodId, skip, limit);
}
});

103 changes: 2 additions & 101 deletions modules/project-comments/server/routes/comment.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,110 +78,11 @@ module.exports = function (app) {

app.route ('/api/comments/period/:periodId/paginate').all(policy ('guest'))
.put (routes.setAndRun (CommentModel, function (model, req) {

// base query / filter
var periodId;
var eaoStatus;
var proponentStatus;
var isPublished;

// filter By Fields...
var commentId;
var authorComment;
var location;
var pillar;
var topic;

// pagination stuff
var skip = 0;
var limit = 50;
var sortby = {};

if (req.body) {

// base query / filter
if (!_.isEmpty(req.body.periodId)) {
periodId = req.body.periodId;
}
if (!_.isEmpty(req.body.eaoStatus)) {
eaoStatus = req.body.eaoStatus;
}
if (!_.isEmpty(req.body.proponentStatus)) {
proponentStatus = req.body.proponentStatus;
}
if (req.body.isPublished !== undefined) {
isPublished = Boolean(req.body.isPublished);
}

// filter By Fields...
if (!_.isEmpty(req.body.commentId)) {
try {
commentId = parseInt(req.body.commentId);
} catch(e) {

}
}
if (!_.isEmpty(req.body.authorComment)) {
authorComment = req.body.authorComment;
}
if (!_.isEmpty(req.body.location)) {
location = req.body.location;
}
if (!_.isEmpty(req.body.pillar)) {
pillar = req.body.pillar;
}
if (!_.isEmpty(req.body.topic)) {
topic = req.body.topic;
}

// pagination stuff
try {
skip = parseInt(req.body.start);
limit = parseInt(req.body.limit);
} catch(e) {

}
if (req.body.orderBy) {
sortby[req.body.orderBy] = req.body.reverse ? -1 : 1;
}
}

return model.getCommentsForPeriod (periodId, eaoStatus, proponentStatus, isPublished, commentId, authorComment, location, pillar, topic, skip, limit, sortby);
return model.getPeriodPaginate(req.body);
}));

app.route ('/api/comments/period/:periodId/perms/sync').all(policy ('user'))
.put (routes.setAndRun (CommentModel, function (model, req) {

// base query / filter
var periodId;

// pagination stuff
var skip = 0;
var limit = 50;

var projectId; // will need this to check for createCommentPeriod permission

if (req.body) {

// base query / filter
if (!_.isEmpty(req.body.periodId)) {
periodId = req.body.periodId;
}

// pagination stuff
try {
skip = parseInt(req.body.start);
limit = parseInt(req.body.limit);
} catch(e) {
console.log('Invalid skip/start or limit value passed in (skip/start =', req.body.start, ', limit = ', req.body.limit, '); using defaults: skip/start = ', skip, ', limit =', limit);
}

if (!_.isEmpty(req.body.projectId)) {
projectId = req.body.projectId;
}

}
return model.updatePermissionBatch(projectId, periodId, skip, limit);
return model.getPeriodPermsSync(req.body);
}));

// =========================================================================
Expand Down

0 comments on commit 140a392

Please sign in to comment.