-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.ts
48 lines (43 loc) · 1.32 KB
/
routes.ts
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
import { Application, Request, Response } from 'express';
import { HealthStatusController, KafkaController } from './lib/controllers';
class Route {
path: string;
action: (request: Request, response: Response) => {};
verb: RestVerb;
constructor(verb: RestVerb, path: string, action: (request: Request, response: Response) => {}) {
this.path = path;
this.action = action;
this.verb = verb;
}
}
enum RestVerb {
show = 'get',
index = 'get',
create = 'post',
edit = 'patch',
update = "put",
delete = "delete"
}
export class Routes {
private app: Application;
routes: Array<Route> = [];
private controllers = {
HealthStatusController: new HealthStatusController(),
kafkaController: new KafkaController()
}
constructor(app: Application) {
this.app = app;
}
static call(app: any) {
const instance = new Routes(app);
instance.call();
}
call() {
this.routes.push(new Route(RestVerb.show, '/api/v1/status(||/0)', this.controllers.HealthStatusController.show));
this.routes.push(new Route(RestVerb.show, '/api/v1/status/1', this.controllers.HealthStatusController.show1));
this.routes.push(new Route(RestVerb.create, '/produce', this.controllers.kafkaController.create));
this.routes.forEach((route) => {
this.app[route.verb](route.path, route.action);
});
}
}