forked from EvolutionAPI/evolution-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.router.ts
More file actions
53 lines (43 loc) · 1.76 KB
/
label.router.ts
File metadata and controls
53 lines (43 loc) · 1.76 KB
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
import { RequestHandler, Router } from 'express';
import { Logger } from '../../config/logger.config';
import { handleLabelSchema } from '../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router';
import { HandleLabelDto, LabelDto } from '../dto/label.dto';
import { labelController } from '../server.module';
import { HttpStatus } from './index.router';
const logger = new Logger('LabelRouter');
export class LabelRouter extends RouterBroker {
constructor(...guards: RequestHandler[]) {
super();
this.router
.get(this.routerPath('findLabels'), ...guards, async (req, res) => {
logger.verbose('request received in findLabels');
logger.verbose('request body: ');
logger.verbose(req.body);
logger.verbose('request query: ');
logger.verbose(req.query);
const response = await this.dataValidate<LabelDto>({
request: req,
schema: null,
ClassRef: LabelDto,
execute: (instance) => labelController.fetchLabels(instance),
});
return res.status(HttpStatus.OK).json(response);
})
.put(this.routerPath('handleLabel'), ...guards, async (req, res) => {
logger.verbose('request received in handleLabel');
logger.verbose('request body: ');
logger.verbose(req.body);
logger.verbose('request query: ');
logger.verbose(req.query);
const response = await this.dataValidate<HandleLabelDto>({
request: req,
schema: handleLabelSchema,
ClassRef: HandleLabelDto,
execute: (instance, data) => labelController.handleLabel(instance, data),
});
return res.status(HttpStatus.OK).json(response);
});
}
public readonly router = Router();
}