Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRC-976: fix + enhancements to statusHistoryEffectiveDate (see details) #184

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
"request": "launch",
"name": "Launch API using Node",
"program": "${workspaceFolder}/app.js"
}
]
},
{
"type": "node",
"request": "launch",
"name": "Launch update script using Node",
"program": "${workspaceFolder}/seed/shapesMigration/updateShapes.js",
"args": [
"backend",
"xxx",
"http",
"localhost",
"3000",
"prc-admin-console",
"password",
"https://sso-dev.pathfinder.gov.bc.ca/auth/realms/prc/protocol/openid-connect/token"
]
}
]
}
13 changes: 9 additions & 4 deletions api/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,16 @@ var addStandardQueryFilters = function (query, args) {
}
}
// Allows filtering of apps that have had their last status change greater than this epoch time.
if (args.swagger.params.statusHistoryEffectiveDate && args.swagger.params.statusHistoryEffectiveDate !== undefined) {
if (args.swagger.params.statusHistoryEffectiveDate && args.swagger.params.statusHistoryEffectiveDate.value !== undefined) {
var queryString = qs.parse(args.swagger.params.statusHistoryEffectiveDate.value);
_.assignIn(query, {
$or: [ { statusHistoryEffectiveDate: null }, { statusHistoryEffectiveDate: { $gte: parseInt(queryString.gte, 10) } } ]
});
if (queryString.since) {
_.assignIn(query, {
$or: [
{ statusHistoryEffectiveDate: null },
{ statusHistoryEffectiveDate: { $gte: new Date(queryString.since) } }
]
});
}
}
return query;
}
2 changes: 1 addition & 1 deletion api/helpers/models/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
type : { type: String },

// Used to track when the latest status was effective.
statusHistoryEffectiveDate : { type: Number, default: null },
statusHistoryEffectiveDate : { type: Date },

// 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.
Expand Down
4 changes: 3 additions & 1 deletion api/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ exports.getApplicationByDispositionID = function (accessToken, disp) {
application.DISPOSITION_TRANSACTION_SID = disp;
application.parcels = [];
application.interestedParties = [];
application.statusHistoryEffectiveDate = (obj.statusHistory[0] != null) ? obj.statusHistory[0].effectiveDate : null;
application.statusHistoryEffectiveDate = (obj.statusHistory[0] != null) ?
new Date(obj.statusHistory[0].effectiveDate) : // convert Unix Epoch Time (ms)
null;

// WKT conversion to GEOJSON
for (let geo of obj.interestParcels) {
Expand Down
12 changes: 6 additions & 6 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,10 @@ paths:
description: "Get an Application that relates to size of areaHectares."
- in: query
name: statusHistoryEffectiveDate
collectionFormat: multi
type: number
type: string
format: date-time
required: false
description: "Get an Application where the last status change was since this epoch time."
description: "Get an Application filtered by last status change date."
- in: query
name: centroid
required: false
Expand Down Expand Up @@ -1171,10 +1171,10 @@ paths:
description: "Get an Application that relates to size of areaHectares."
- in: query
name: statusHistoryEffectiveDate
collectionFormat: multi
type: number
type: string
format: date-time
required: false
description: "Get an Application where the last status change was since this epoch time."
description: "Get an Application filtered by last status change date."
- in: query
name: centroid
required: false
Expand Down
2 changes: 1 addition & 1 deletion api/test/helpers/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ describe('utils', () => {
test('sets the statusHistoryEffectiveDate', done => {
Utils.getApplicationByDispositionID(accessToken, dispId)
.then(response => {
expect(response.statusHistoryEffectiveDate).toEqual(1527878179000);
expect(response.statusHistoryEffectiveDate).toEqual(new Date(1527878179000));

done();
});
Expand Down
29 changes: 16 additions & 13 deletions seed/shapesMigration/updateShapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ var getAllApplications = function (route) {
return new Promise(function (resolve, reject) {
console.log("calling:", uri + route + '?fields=tantalisID');
request({
url: uri + route + '?fields=tantalisID', headers: {
// only update the ones that aren't deleted
url: uri + route + '?fields=tantalisID&isDeleted=false', headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + jwt_login
}
Expand Down Expand Up @@ -145,6 +146,7 @@ var getAndSaveFeatures = function (accessToken, item) {
item.client += client.firstName + " " + client.lastName;
}
}
item.statusHistoryEffectiveDate = obj.statusHistoryEffectiveDate;

Promise.resolve()
.then(function () {
Expand Down Expand Up @@ -205,18 +207,19 @@ var deleteAllApplicationFeatures = function (item) {
var updateApplicationMeta = function (item) {
return new Promise(function (resolve, reject) {
var updatedAppObject = {};
updatedAppObject.businessUnit = item.RESPONSIBLE_BUSINESS_UNIT;
updatedAppObject.purpose = item.TENURE_PURPOSE;
updatedAppObject.subpurpose = item.TENURE_SUBPURPOSE;
updatedAppObject.status = item.TENURE_STATUS;
updatedAppObject.type = item.TENURE_TYPE;
updatedAppObject.tenureStage = item.TENURE_STAGE;
updatedAppObject.subtype = item.TENURE_SUBTYPE;
updatedAppObject.location = item.TENURE_LOCATION;
updatedAppObject.legalDescription = item.TENURE_LEGAL_DESCRIPTION;
updatedAppObject.centroid = item.centroid;
updatedAppObject.areaHectares = item.areaHectares;
updatedAppObject.client = item.client;
updatedAppObject.businessUnit = item.RESPONSIBLE_BUSINESS_UNIT;
updatedAppObject.purpose = item.TENURE_PURPOSE;
updatedAppObject.subpurpose = item.TENURE_SUBPURPOSE;
updatedAppObject.status = item.TENURE_STATUS;
updatedAppObject.type = item.TENURE_TYPE;
updatedAppObject.tenureStage = item.TENURE_STAGE;
updatedAppObject.subtype = item.TENURE_SUBTYPE;
updatedAppObject.location = item.TENURE_LOCATION;
updatedAppObject.legalDescription = item.TENURE_LEGAL_DESCRIPTION;
updatedAppObject.centroid = item.centroid;
updatedAppObject.areaHectares = item.areaHectares;
updatedAppObject.client = item.client;
updatedAppObject.statusHistoryEffectiveDate = item.statusHistoryEffectiveDate;
request.put({
url: uri + 'api/application/' + item._id,
headers: {
Expand Down