@@ -29,9 +29,12 @@ import {
2929 textMessageSchema ,
3030} from '@validate/validate.schema' ;
3131import { RequestHandler , Router } from 'express' ;
32+ import multer from 'multer' ;
3233
3334import { HttpStatus } from './index.router' ;
3435
36+ const upload = multer ( { storage : multer . memoryStorage ( ) } ) ;
37+
3538export class MessageRouter extends RouterBroker {
3639 constructor ( ...guards : RequestHandler [ ] ) {
3740 super ( ) ;
@@ -56,43 +59,51 @@ export class MessageRouter extends RouterBroker {
5659
5760 return res . status ( HttpStatus . CREATED ) . json ( response ) ;
5861 } )
59- . post ( this . routerPath ( 'sendMedia' ) , ...guards , async ( req , res ) => {
62+ . post ( this . routerPath ( 'sendMedia' ) , ...guards , upload . single ( 'file' ) , async ( req , res ) => {
63+ const bodyData = req . body ;
64+
6065 const response = await this . dataValidate < SendMediaDto > ( {
6166 request : req ,
6267 schema : mediaMessageSchema ,
6368 ClassRef : SendMediaDto ,
64- execute : ( instance , data ) => sendMessageController . sendMedia ( instance , data ) ,
69+ execute : ( instance ) => sendMessageController . sendMedia ( instance , bodyData , req . file as any ) ,
6570 } ) ;
6671
6772 return res . status ( HttpStatus . CREATED ) . json ( response ) ;
6873 } )
69- . post ( this . routerPath ( 'sendWhatsAppAudio' ) , ...guards , async ( req , res ) => {
74+ . post ( this . routerPath ( 'sendWhatsAppAudio' ) , ...guards , upload . single ( 'file' ) , async ( req , res ) => {
75+ const bodyData = req . body ;
76+
7077 const response = await this . dataValidate < SendAudioDto > ( {
7178 request : req ,
7279 schema : audioMessageSchema ,
7380 ClassRef : SendMediaDto ,
74- execute : ( instance , data ) => sendMessageController . sendWhatsAppAudio ( instance , data ) ,
81+ execute : ( instance ) => sendMessageController . sendWhatsAppAudio ( instance , bodyData , req . file as any ) ,
7582 } ) ;
7683
7784 return res . status ( HttpStatus . CREATED ) . json ( response ) ;
7885 } )
7986 // TODO: Revisar funcionamento do envio de Status
80- . post ( this . routerPath ( 'sendStatus' ) , ...guards , async ( req , res ) => {
87+ . post ( this . routerPath ( 'sendStatus' ) , ...guards , upload . single ( 'file' ) , async ( req , res ) => {
88+ const bodyData = req . body ;
89+
8190 const response = await this . dataValidate < SendStatusDto > ( {
8291 request : req ,
8392 schema : statusMessageSchema ,
8493 ClassRef : SendStatusDto ,
85- execute : ( instance , data ) => sendMessageController . sendStatus ( instance , data ) ,
94+ execute : ( instance ) => sendMessageController . sendStatus ( instance , bodyData , req . file as any ) ,
8695 } ) ;
8796
8897 return res . status ( HttpStatus . CREATED ) . json ( response ) ;
8998 } )
90- . post ( this . routerPath ( 'sendSticker' ) , ...guards , async ( req , res ) => {
99+ . post ( this . routerPath ( 'sendSticker' ) , ...guards , upload . single ( 'file' ) , async ( req , res ) => {
100+ const bodyData = req . body ;
101+
91102 const response = await this . dataValidate < SendStickerDto > ( {
92103 request : req ,
93104 schema : stickerMessageSchema ,
94105 ClassRef : SendStickerDto ,
95- execute : ( instance , data ) => sendMessageController . sendSticker ( instance , data ) ,
106+ execute : ( instance ) => sendMessageController . sendSticker ( instance , bodyData , req . file as any ) ,
96107 } ) ;
97108
98109 return res . status ( HttpStatus . CREATED ) . json ( response ) ;
0 commit comments