import { Router } from '@classes' ; import { Guard } from '@middlewares/guard.middleware' ; import { Validator } from '@middlewares/validator.middleware' ; import { Uploader } from '@middlewares/uploader.middleware' ; import { MediaController } from '@controllers/media.controller' ; import { ROLE , MIME_TYPE } from '@enums' ; import { list } from '@utils/enum.util' ; import { listMedias , insertMedia , getMedia , replaceMedia , updateMedia , removeMedia } from '@validations/media.validation' ; export class MediaRouter extends Router { constructor ( ) { super ( ) ; } description define ( ) { this . router . route ( '/' ) . get ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Validator . check ( listMedias ) , MediaController . list ) . post ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Uploader . upload ( { wildcards : list ( MIME_TYPE ) } ) , Validator . check ( insertMedia ) , MediaController . create ) ; this . router . route ( '/:mediaId' ) . get ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Validator . check ( getMedia ) , MediaController . get ) . put ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Validator . check ( replaceMedia ) , MediaController . get , Uploader . upload ( { wildcards : list ( MIME_TYPE ) } ) , Validator . check ( insertMedia ) , MediaController . update ) . patch ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Validator . check ( updateMedia ) , MediaController . get , Uploader . upload ( { wildcards : list ( MIME_TYPE ) } ) , MediaController . update ) . delete ( Guard . authorize ( [ ROLE . admin , ROLE . user ] ) , Validator . check ( removeMedia ) , MediaController . get , MediaController . remove ) ; } }