-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
133 lines (115 loc) · 4.6 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const GlobalObjects = require('./GlobalObjects');
var globalObjects = new GlobalObjects();
module.exports = globalObjects;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// GRPC SETUP
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const PROTO_PATH = __dirname + '/proto/ubc.proto';
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { keepCase: true, longs: String, enums: String, defaults: false, oneofs: true });
const ubc_package = grpc.loadPackageDefinition(packageDefinition).ubc_package;
async function bindGetBoxerWithStandingAndMatches(call, callback) {
await sleep(50);
console.log('\n⚪ GetBoxerWithStandingAndMatches:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardGetBoxerWithStandingAndMatches(call.request);
await sleep(50);
console.log('🟢 GetBoxerWithStandingAndMatches:: ', JSON.stringify(r));
callback(null, r);
}
async function bindGetBoxer(call, callback) {
await sleep(50);
console.log('\n⚪ GetBoxer:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardGetBoxer(call.request);
await sleep(50);
console.log('🟢 GetBoxer:: ', JSON.stringify(r));
callback(null, r);
}
async function bindGetMultipleBoxers(call, callback) {
await sleep(50);
console.log('\n⚪ GetMultipleBoxers:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardGetMultipleBoxers(call.request);
await sleep(50);
console.log('🟢 GetMultipleBoxers:: ', JSON.stringify(r));
callback(null, r);
}
async function bindEditBoxer(call, callback) {
await sleep(50);
console.log('\n⚪ EditBoxer:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardEditBoxer(call.request);
await sleep(50);
console.log('🟢 EditBoxer:: ', JSON.stringify(r));
callback(null, r);
}
async function bindAddBoxer(call, callback) {
await sleep(50);
console.log('\n⚪ AddBoxer:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardAddBoxer(call.request);
await sleep(50);
console.log('🟢 AddBoxer:: ', JSON.stringify(r));
callback(null, r);
}
async function bindRemoveBoxer(call, callback) {
await sleep(50);
console.log('\n⚪ RemoveBoxer:: ', JSON.stringify(call.request));
let r = await globalObjects.controller.guardRemoveBoxer(call.request);
await sleep(50);
console.log('🟢 RemoveBoxer:: ', JSON.stringify(r));
callback(null, r);
}
async function bindMock(call, callback) {
await globalObjects.controller.mock();
callback(null, null);
}
async function bindSetupAddBoxer(call, callback) {
await globalObjects.controller.guardSetupAddBoxer(call.request);
callback(null, {code: 200})
}
async function bindSetupAddLatestBoxer(call, callback) {
await globalObjects.controller.guardSetupAddLatestBoxer(call.request);
callback(null, {code: 200})
}
async function bindSetupClearBoxers(call, callback) {
await globalObjects.controller.guardSetupClearBoxers();
callback(null, {code: 200})
}
async function bindSetupAddStandingAndMatches(call, callback) {
await globalObjects.controller.mediator.standingsServiceGateway.setupAddStandingAndMatches(call.request.standingAndMatches);
callback(null, {code: 200})
}
async function bindSetupAddToken(call, callback) {
await globalObjects.controller.mediator.authServiceGateway.setupToken(call.request.token);
callback(null, {code: 200})
}
async function bindSetupAddMatches(call, callback) {
await globalObjects.controller.mediator.matchServiceGateway.setupAddMatches(call.request.matches);
callback(null, {code: 200})
}
async function bindEnterIntegratedTestingEnvironment(call, callback) {
await globalObjects.controller.enterIntegratedTestingEnvironment();
callback(null, null);
}
function main() {
console.log("Server running...");
server = new grpc.Server();
server.addService(ubc_package.BoxerService.service, {
GetBoxer: bindGetBoxer,
GetMultipleBoxers: bindGetMultipleBoxers,
GetBoxerWithStandingAndMatches: bindGetBoxerWithStandingAndMatches,
EditBoxer: bindEditBoxer,
AddBoxer: bindAddBoxer,
RemoveBoxer: bindRemoveBoxer,
Mock: bindMock,
SetupAddBoxer: bindSetupAddBoxer,
SetupAddLatestBoxer: bindSetupAddLatestBoxer,
SetupAddStandingAndMatches: bindSetupAddStandingAndMatches,
SetupAddToken: bindSetupAddToken,
SetupAddMatches: bindSetupAddMatches,
SetupClearBoxers: bindSetupClearBoxers,
EnterIntegratedTestingEnvironment: bindEnterIntegratedTestingEnvironment
});
server.bind("0.0.0.0:50052", grpc.ServerCredentials.createInsecure());
server.start();
}
main();