1+ import { LOCALE_KEY } from "@/constants" ;
2+ import { PagingDTO } from "@/dtos/paging.dto" ;
3+ import { LocaleService } from "@/i18n/ctx" ;
14import { ChannelService } from "@/services/channels.service" ;
25import { catchAsync } from "@/utils/catch-async" ;
6+ import { plainToClass } from "class-transformer" ;
7+ import { validateOrReject } from "class-validator" ;
38import { StatusCodes } from "http-status-codes" ;
49import Container from "typedi" ;
510
611export class ChannelController {
712 public channelService = Container . get ( ChannelService ) ;
13+ public localeService = Container . get < LocaleService > ( LOCALE_KEY ) ;
814
915 public createChannel = catchAsync ( async ( req , res ) => {
10- const data = await this . channelService . create ( req . body ) ;
16+ await this . channelService . create ( req . body ) ;
1117 res . status ( StatusCodes . OK ) . json ( {
12- message : 'Tạo channel thành công' ,
13- data,
18+ message : this . localeService . i18n ( ) . CHANNEL . CREATE_SUCCESS ( ) ,
1419 } ) ;
1520 } ) ;
1621
22+ public updateChannel = catchAsync ( async ( req , res ) => {
23+ await this . channelService . updateById ( req . params . id , req . body ) ;
24+ res . status ( StatusCodes . OK ) . json ( {
25+ message : this . localeService . i18n ( ) . CHANNEL . UPDATE_SUCCESS ( ) ,
26+ } ) ;
27+ } )
28+
29+ public deleteChannel = catchAsync ( async ( req , res ) => {
30+ await this . channelService . deleteById ( req . params . id ) ;
31+ res . status ( StatusCodes . OK ) . json ( {
32+ message : this . localeService . i18n ( ) . CHANNEL . DELETE_CHANNEL_SUCCESS ( ) ,
33+ } ) ;
34+ } )
35+
36+ public deleteMultipleChannel = catchAsync ( async ( req , res ) => {
37+ await this . channelService . deleteByIds ( req . body . id ) ;
38+ res . status ( StatusCodes . OK ) . json ( {
39+ message : this . localeService . i18n ( ) . CHANNEL . DELETE_MULTIPLE_CHANNELS_SUCCESS ( ) ,
40+ } ) ;
41+ } )
42+
43+ public getChannelsPaging = catchAsync ( async ( req , res ) => {
44+ const paging = plainToClass ( PagingDTO , req . query ) ;
45+ await validateOrReject ( paging ) ;
46+
47+ const result = await this . channelService . getChannelsPaging ( paging ) ;
48+ res . status ( StatusCodes . OK ) . json ( { result } ) ;
49+ } )
1750}
0 commit comments