105 | import {
106 | NextFunction, Request, Response, Router,
107 | } from 'express';
108 | import { IRoute } from '../interfaces';
109 | import { ResourceExampleControler } from '../controller';
110 | import { isDefinedParamMiddleware, validationMiddleware } from '../middlewares';
111 | import { ExampleDTO } from '../dtos';
112 |
113 | /**
114 | *
115 | * Managament the routes of resource
116 | * @category Routes
117 | * @class ExampleRouter
118 | * @implements {IRoute}
119 | */
120 | class ExampleRouter implements IRoute {
121 | public router = Router();
122 |
123 | public pathIdParam = '/:id';
124 |
125 | constructor() {
126 | this.createRoutes();
127 | }
128 |
129 | createRoutes(): void {
130 | this.router.get(
131 | this.pathIdParam,
132 | isDefinedParamMiddleware(),
133 | (req: Request, res: Response, next: NextFunction) => ResourceExampleControler
134 | .getById(req, res, next),
135 | );
136 | this.router.get('/', (req: Request, res: Response, next: NextFunction) => ResourceExampleControler
137 | .list(req, res, next));
138 | this.router.post(
139 | '/',
140 | validationMiddleware(ExampleDTO),
141 | (req: Request, res: Response, next: NextFunction) => ResourceExampleControler
142 | .create(req, res, next),
143 | );
144 | this.router.put(
145 | this.pathIdParam,
146 | isDefinedParamMiddleware(),
147 | validationMiddleware(ExampleDTO, true),
148 | (req: Request, res: Response, next: NextFunction) => ResourceExampleControler
149 | .updateById(req, res, next),
150 | );
151 | this.router.delete(
152 | this.pathIdParam,
153 | isDefinedParamMiddleware(),
154 | (req: Request, res: Response, next: NextFunction) => ResourceExampleControler
155 | .removeById(req, res, next),
156 | );
157 | }
158 | }
159 | export default new ExampleRouter().router;
160 |
161 |
162 |