-
Notifications
You must be signed in to change notification settings - Fork 0
/
providers.js
50 lines (41 loc) · 1.68 KB
/
providers.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
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
// S4S Discovery Data Server Providers web service
// File: providers.js
const version = '20180411';
// Required modules
const EventEmitter = require('events').EventEmitter;
const util = require('./utility');
// Configuration (Kluge: config is read by all modules)
const config = require('./config');
// Setup for 'ready' event
module.exports = new EventEmitter();
// Send module 'ready' event to parent -- setTimeout() provides a "yield" so that wait is setup before emit
setTimeout(function () {
module.exports.emit('ready');
});
//---------------------------------------------------------------------------------
// The 'providers' call (GET /providers)
module.exports.providers = function (req, res, next) {
if (req == undefined) {
// Return documentation
return {pre: {desc: 'providers service', version: version},
desc: 'Get the array of available provider names.',
return: 'The JSON array of providers:<div style="margin-left:30px;"><pre style="margin-top:0px;">'
+ JSON.stringify(config.providerNames(), null, 3) + '</div></pre>'};
} else {
util.sendJson(req, res, config.providerNames());
return next();
}
};
// The 'providers for participant' call (GET /providers/:id)
module.exports.providersForParticipant = function (req, res, next) {
if (req == undefined) {
// Return documentation
return {desc: 'Get the array of providers for participant :id',
params: [{name: 'id', desc: 'the participant id'}],
return: 'The JSON array of providers.'};
} else {
util.sendJson(req, res, config.providersForParticipant(req.params.id));
return next();
}
};