import { Router } from '@classes' ; import { UserController } from '@controllers/user.controller' ; import { Guard } from '@middlewares/guard.middleware' ; import { Uploader } from '@middlewares/uploader.middleware' ; import { Validator } from '@middlewares/validator.middleware' ; import { IMAGE_MIME_TYPE , ROLE } from '@enums' ; import { listUsers , getUser , createUser , replaceUser , updateUser , removeUser } from '@validations/user.validation' ; import { list } from '@utils/enum.util' ; export class UserRouter extends Router { constructor ( ) { super ( ) ; } description define ( ) { this . router . route ( '/' ) . get ( Guard . authorize ( [ ROLE . admin ] ) , Validator . check ( listUsers ) , UserController . list ) . post ( Guard . authorize ( [ ROLE . admin ] ) , Validator . check ( createUser ) , UserController . create ) ; this . router . route ( '/profile' ) . get ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , UserController . loggedIn ) ; this . router . route ( '/:userId(\\d+)' ) . get ( Guard . authorize ( [ ROLE . admin ] ) , Validator . check ( getUser ) , UserController . get ) . put ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Uploader . upload ( { wildcards : list ( IMAGE_MIME_TYPE ) } ) , Validator . check ( replaceUser ) , UserController . update ) . patch ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Uploader . upload ( { wildcards : list ( IMAGE_MIME_TYPE ) } ) , Validator . check ( updateUser ) , UserController . update ) . delete ( Guard . authorize ( [ ROLE . admin ] ) , Validator . check ( removeUser ) , UserController . remove ) ; } }