forked from AMPATH/etl-rest-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-request-processing.js
executable file
·37 lines (33 loc) · 1014 Bytes
/
pre-request-processing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var moment = require('moment');
var _ = require('underscore');
var dao = require('./etl-dao');
var moduleDefinition = {
resolveLocationIdsToLocationUuids: resolveLocationIdsToLocationUuids
};
module.exports = moduleDefinition;
function resolveLocationIdsToLocationUuids(request, callback) {
var asyncRequests = 0; //this should be the number of async requests needed before they are triggered
var onResolvedPromise = function (promise) {
asyncRequests--;
if (asyncRequests <= 0) {
//voting process to ensure all pre-processing of request async operations are complete
callback();
}
};
if (request.query.locationUuids) {
asyncRequests++;
}
if (asyncRequests === 0) callback();
if (request.query.locationUuids) {
dao.getIdsByUuidAsyc(
'amrs.location',
'location_id',
'uuid',
request.query.locationUuids,
function (results) {
request.query.locations = results;
}
).onResolved = onResolvedPromise;
}
}