Skip to content

Commit

Permalink
Merge pull request #238 from NickPhura/ACRFD-14
Browse files Browse the repository at this point in the history
ACRFD-14: Update/Fix swagger param parsing, add application sortBy, support basic applicant search, remove deprecated swagger comment period field
  • Loading branch information
NickPhura authored Sep 13, 2019
2 parents ff64b57 + 75626fb commit b4c9c9a
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 47 deletions.
35 changes: 29 additions & 6 deletions api/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ exports.publicGet = function(args, res, next) {
};

exports.protectedGet = function(args, res, next) {
var query = {};
var sort = {};
var skip = null;
var limit = null;

defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on appId route
var query = {};
if (args.swagger.params.appId) {
query = Utils.buildQuery('_id', args.swagger.params.appId.value, query);
} else {
Expand All @@ -171,6 +175,12 @@ exports.protectedGet = function(args, res, next) {
skip = processedParameters.skip;
limit = processedParameters.limit;

if (args.swagger.params.sortBy && args.swagger.params.sortBy.value) {
var order_by = args.swagger.params.sortBy.value.charAt(0) == '-' ? -1 : 1;
var sort_by = args.swagger.params.sortBy.value.slice(1);
sort[sort_by] = order_by;
}

try {
query = addStandardQueryFilters(query, args);
} catch (error) {
Expand All @@ -192,7 +202,7 @@ exports.protectedGet = function(args, res, next) {
query,
getSanitizedFields(args.swagger.params.fields.value), // Fields
null, // sort warmup
null, // sort
sort, // sort
skip, // skip
limit, // limit
false
Expand All @@ -207,7 +217,10 @@ exports.protectedGet = function(args, res, next) {
};

exports.protectedHead = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on appId route
var query = {};
Expand Down Expand Up @@ -719,10 +732,18 @@ var addStandardQueryFilters = function(query, args) {
_.assignIn(query, { agency: args.swagger.params.agency.value });
}
if (args.swagger.params.businessUnit && args.swagger.params.businessUnit.value !== undefined) {
_.assignIn(query, { businessUnit: args.swagger.params.businessUnit.value });
_.assignIn(query, { businessUnit: { $eq: args.swagger.params.businessUnit.value.eq } });
}
if (args.swagger.params.client && args.swagger.params.client.value !== undefined) {
_.assignIn(query, { client: args.swagger.params.client.value });
var queryString = qs.parse(args.swagger.params.client.value);
if (queryString.text) {
// This searches for text indexed fields, which client is currently marked as in the application model.
// If more fields are added to the text index, this logic may need to change as it will then search those fields
// as well, which may be un-desired. See docs.mongodb.com/manual/reference/operator/query/text/
_.assignIn(query, { $text: { $search: queryString.text } });
} else if (queryString.eq) {
_.assignIn(query, { client: { $eq: queryString.eq } });
}
}
if (args.swagger.params.tenureStage && args.swagger.params.tenureStage.value !== undefined) {
_.assignIn(query, { tenureStage: args.swagger.params.tenureStage.value });
Expand Down Expand Up @@ -831,6 +852,8 @@ var addStandardQueryFilters = function(query, args) {
}
}

defaultLog.debug('query:', JSON.stringify(query));

return query;
};
/* eslint-enable no-redeclare */
5 changes: 4 additions & 1 deletion api/controllers/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ exports.publicGet = function(args, res, next) {
};

exports.protectedHead = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on CommentPeriodId route
var query = {};
Expand Down
10 changes: 8 additions & 2 deletions api/controllers/commentperiod.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ exports.publicGet = function(args, res, next) {
};

exports.protectedHead = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on CommentPeriodId route
var query = {};
Expand Down Expand Up @@ -85,7 +88,10 @@ exports.protectedHead = function(args, res, next) {
};

exports.protectedGet = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on CommentPeriodId route
var query = {};
Expand Down
10 changes: 8 additions & 2 deletions api/controllers/decision.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ exports.publicGet = function(args, res, next) {
};

exports.protectedHead = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on decisionId route
var query = {};
Expand Down Expand Up @@ -82,7 +85,10 @@ exports.protectedHead = function(args, res, next) {
};

exports.protectedGet = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on decisionId route
var query = {};
Expand Down
15 changes: 12 additions & 3 deletions api/controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ exports.unProtectedPost = function(args, res, next) {
};

exports.protectedHead = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on docId route
var query = {};
Expand Down Expand Up @@ -153,7 +156,10 @@ exports.protectedHead = function(args, res, next) {
};

exports.protectedGet = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on docId route
var query = {};
Expand Down Expand Up @@ -229,7 +235,10 @@ exports.publicDownload = function(args, res, next) {
};

exports.protectedDownload = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on docId route
var query = {};
Expand Down
10 changes: 8 additions & 2 deletions api/controllers/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ exports.publicGet = function(args, res, next) {
});
};
exports.protectedGet = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

var query = {};
// Build match query if on featureId route
Expand Down Expand Up @@ -88,7 +91,10 @@ exports.protectedGet = function(args, res, next) {

exports.protectedDelete = function(args, res, next) {
defaultLog.info('Deleting a Feature(s)');
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

var Feature = mongoose.model('Feature');
var query = {};
Expand Down
5 changes: 4 additions & 1 deletion api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ exports.protectedOptions = function(args, res, rest) {
};

exports.protectedGet = function(args, res, next) {
defaultLog.info('args.swagger.params:', JSON.stringify(args.swagger.operation['x-security-scopes']));
defaultLog.info(
'args.swagger.operation.x-security-scopes:',
JSON.stringify(args.swagger.operation['x-security-scopes'])
);

// Build match query if on userId route
var query = {};
Expand Down
5 changes: 4 additions & 1 deletion api/helpers/models/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ module.exports = require('../models')('Application', {

// Note: Default on tag property is purely for display only, they have no real effect on the model.
// This must be done in the code.
tags: [[{ type: String, trim: true, default: '[["sysadmin"]]' }]] // updated by API
tags: [[{ type: String, trim: true, default: '[["sysadmin"]]' }]], // updated by API

// Used to enable client (applicant) $text search.
__index: { client: 'text' }
});
7 changes: 6 additions & 1 deletion api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ definitions:
- _addedBy
- _application
- tags
- name
- startDate
- endDate
- isDeleted
Expand Down Expand Up @@ -1038,6 +1037,11 @@ paths:
format: date-time
required: false
description: "Status History Effective Date that Applications must compare to"
- in: query
name: sortBy
type: string
required: false
description: "Application field to sort by"
responses:
"200":
description: "Success"
Expand Down Expand Up @@ -1637,6 +1641,7 @@ paths:
required: false
description: "Publish Date(s) that Applications must match"
type: string
format: date-time
responses:
"200":
description: "Success"
Expand Down
27 changes: 0 additions & 27 deletions database.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,6 @@
"host": "MONGODB_SERVICE_HOST"
},

"demo": {
"driver": "mongodb",
"database": { "ENV": "MONGODB_DATABASE" },
"user": { "ENV": "MONGODB_USERNAME" },
"password": { "ENV": "MONGODB_PASSWORD" },
"authSource": "admin",
"host": "DEMO_MONGODB_SERVICE_HOST"
},

"scale": {
"driver": "mongodb",
"database": { "ENV": "MONGODB_DATABASE" },
"user": { "ENV": "MONGODB_USERNAME" },
"password": { "ENV": "MONGODB_PASSWORD" },
"authSource": "admin",
"host": "MONGODB_SCALE_SERVICE_HOST"
},

"beta": {
"driver": "mongodb",
"database": { "ENV": "MONGODB_DATABASE" },
"user": { "ENV": "MONGODB_USERNAME" },
"password": { "ENV": "MONGODB_PASSWORD" },
"authSource": "admin",
"host": "MONGODB_BETA_SERVICE_HOST"
},

"master": {
"driver": "mongodb",
"database": { "ENV": "MONGODB_DATABASE" },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "app",
"scripts": {
"start": "node app",
"test": "echo Test suite should be run with `npm run tests` or npm `run tests-ci`",
"test": "echo Test suite should be run with `npm run tests` or `npm run tests-ci`",
"tests": "SET UPLOAD_DIRECTORY=./api/test/uploads/ & jest --runInBand",
"tests-debug": "node --inspect node_modules/.bin/jest --runInBand",
"lint": "eslint .",
Expand Down

0 comments on commit b4c9c9a

Please sign in to comment.