1- import { LOCALE_KEY } from "@/constants"
2- import { LocaleService } from "@/i18n/ctx"
3- import { RequestWithUser } from "@/interfaces/auth.interface"
4- import { IntentService } from "@/services/intent.service"
5- import { catchAsync } from "@/utils/catch-async"
6- import { StatusCodes } from "http-status-codes"
7- import Container from "typedi"
1+ import { LOCALE_KEY } from '@/constants'
2+ import { PagingDTO } from '@/dtos/paging.dto'
3+ import { LocaleService } from '@/i18n/ctx'
4+ import { RequestWithUser } from '@/interfaces/auth.interface'
5+ import { IntentService } from '@/services/intent.service'
6+ import { catchAsync } from '@/utils/catch-async'
7+ import { plainToClass } from 'class-transformer'
8+ import { StatusCodes } from 'http-status-codes'
9+ import Container from 'typedi'
810
911export class IntentController {
10- public intentService = Container . get ( IntentService )
11- public localeService = Container . get < LocaleService > ( LOCALE_KEY )
12-
13- public createIntent = catchAsync ( async ( req : RequestWithUser , res ) => {
14- req . body . userId = req . user ?. id
15- const data = await this . intentService . create ( req . body )
16- res . status ( StatusCodes . OK ) . json ( {
17- message : this . localeService . i18n ( ) . INTENT . CREATE_SUCCESS ( ) ,
18- data,
19- } )
12+ public intentService = Container . get ( IntentService )
13+ public localeService = Container . get < LocaleService > ( LOCALE_KEY )
14+
15+ public createIntent = catchAsync ( async ( req : RequestWithUser , res ) => {
16+ const data = await this . intentService . create ( {
17+ fields : req . body ,
18+ userId : req . user ?. id as string ,
19+ } )
20+ res . status ( StatusCodes . OK ) . json ( {
21+ message : this . localeService . i18n ( ) . INTENT . CREATE_SUCCESS ( ) ,
22+ data,
23+ } )
24+ } )
25+
26+ public predictIntent = catchAsync ( async ( req : RequestWithUser , res ) => {
27+ req . body . userId = req . user ?. id
28+ const data = await this . intentService . PredictTrainIntent ( req . body )
29+ res . status ( StatusCodes . OK ) . json ( {
30+ message : this . localeService . i18n ( ) . INTENT . PREDICT_SUCCESS ( ) ,
31+ data,
32+ } )
33+ } )
34+
35+ public getById = catchAsync ( async ( req , res ) => {
36+ const data = await this . intentService . getById ( req . params . id )
37+ res . status ( StatusCodes . OK ) . json ( { data } )
38+ } )
39+
40+ public updateIntent = catchAsync ( async ( req : RequestWithUser , res ) => {
41+ const data = await this . intentService . updateById ( {
42+ id : req . params . id ,
43+ fields : req . body ,
44+ userId : req . user ?. id as string ,
45+ } )
46+
47+ res . status ( StatusCodes . OK ) . json ( {
48+ message : this . localeService . i18n ( ) . INTENT . UPDATE_SUCCESS ( ) ,
49+ data,
50+ } )
51+ } )
52+
53+ public getAllIntents = catchAsync ( async ( req : RequestWithUser , res ) => {
54+ const paging = plainToClass ( PagingDTO , req . query )
55+ const data = await this . intentService . getAllIntents (
56+ paging ,
57+ req . user ?. id as string ,
58+ )
59+ res . status ( StatusCodes . OK ) . json ( { data } )
60+ } )
61+
62+ public deleteIntent = catchAsync ( async ( req , res ) => {
63+ const data = await this . intentService . deleteById ( req . params . id )
64+ res . status ( StatusCodes . OK ) . json ( {
65+ message : this . localeService . i18n ( ) . INTENT . DELETE_SUCCESS ( ) ,
66+ data,
2067 } )
21- }
68+ } )
69+ }
0 commit comments