11import { LOCALE_KEY } from "@/constants" ;
22import { PagingDTO } from "@/dtos/paging.dto" ;
33import { LocaleService } from "@/i18n/ctx" ;
4+ import { RequestWithUser } from "@/interfaces/auth.interface" ;
45import { ChannelService } from "@/services/channels.service" ;
56import { catchAsync } from "@/utils/catch-async" ;
67import { plainToClass } from "class-transformer" ;
@@ -11,38 +12,40 @@ export class ChannelController {
1112 public channelService = Container . get ( ChannelService ) ;
1213 public localeService = Container . get < LocaleService > ( LOCALE_KEY ) ;
1314
14- public createChannel = catchAsync ( async ( req , res ) => {
15+ public createChannel = catchAsync ( async ( req : RequestWithUser , res ) => {
16+ req . body . userId = req . user ?. id ;
1517 await this . channelService . create ( req . body ) ;
1618 res . status ( StatusCodes . OK ) . json ( {
1719 message : this . localeService . i18n ( ) . CHANNEL . CREATE_SUCCESS ( ) ,
1820 } ) ;
1921 } ) ;
2022
21- public updateChannel = catchAsync ( async ( req , res ) => {
23+ public updateChannel = catchAsync ( async ( req : RequestWithUser , res ) => {
24+ req . body . userId = req . user ?. id ;
2225 await this . channelService . updateById ( req . params . id , req . body ) ;
2326 res . status ( StatusCodes . OK ) . json ( {
2427 message : this . localeService . i18n ( ) . CHANNEL . UPDATE_SUCCESS ( ) ,
2528 } ) ;
2629 } )
2730
28- public deleteChannel = catchAsync ( async ( req , res ) => {
29- await this . channelService . deleteById ( req . params . id ) ;
31+ public deleteChannel = catchAsync ( async ( req : RequestWithUser , res ) => {
32+ await this . channelService . deleteById ( req . params . id , req . user ?. id as string ) ;
3033 res . status ( StatusCodes . OK ) . json ( {
3134 message : this . localeService . i18n ( ) . CHANNEL . DELETE_CHANNEL_SUCCESS ( ) ,
3235 } ) ;
3336 } )
3437
35- public deleteMultipleChannel = catchAsync ( async ( req , res ) => {
36- await this . channelService . deleteByIds ( req . body . id ) ;
38+ public deleteMultipleChannel = catchAsync ( async ( req : RequestWithUser , res ) => {
39+ await this . channelService . deleteByIds ( req . body . id , req . user ?. id as string ) ;
3740 res . status ( StatusCodes . OK ) . json ( {
3841 message : this . localeService . i18n ( ) . CHANNEL . DELETE_MULTIPLE_CHANNELS_SUCCESS ( ) ,
3942 } ) ;
4043 } )
4144
42- public getChannelsPaging = catchAsync ( async ( req , res ) => {
45+ public getAllChannels = catchAsync ( async ( req : RequestWithUser , res ) => {
4346 const paging = plainToClass ( PagingDTO , req . query ) ;
4447
45- const data = await this . channelService . getChannelsPaging ( paging ) ;
48+ const data = await this . channelService . getAllChannels ( paging , req . user ?. id as string ) ;
4649 res . status ( StatusCodes . OK ) . json ( { data } ) ;
4750 } )
4851}
0 commit comments