@@ -5,7 +5,7 @@ import { validate } from 'jsonschema';
55import { BadRequestException } from '../../exceptions' ;
66import 'express-async-errors' ;
77import { Logger } from '../../config/logger.config' ;
8- import { GroupInvite , GroupJid } from '../dto/group.dto' ;
8+ import { GetParticipant , GroupInvite , GroupJid } from '../dto/group.dto' ;
99
1010type DataValidate < T > = {
1111 request : Request ;
@@ -181,4 +181,47 @@ export abstract class RouterBroker {
181181
182182 return await execute ( instance , ref ) ;
183183 }
184+
185+ public async getParticipantsValidate < T > ( args : DataValidate < T > ) {
186+ const { request, ClassRef, schema, execute } = args ;
187+
188+ const getParticipants = request . query as unknown as GetParticipant ;
189+
190+ if ( ! getParticipants ?. getParticipants ) {
191+ throw new BadRequestException (
192+ 'The getParticipants needs to be informed in the query' ,
193+ ) ;
194+ }
195+
196+ const instance = request . params as unknown as InstanceDto ;
197+ const body = request . body ;
198+
199+ const ref = new ClassRef ( ) ;
200+
201+ Object . assign ( body , getParticipants ) ;
202+ Object . assign ( ref , body ) ;
203+
204+ const v = validate ( ref , schema ) ;
205+
206+ console . log ( v , '@checkei aqui' ) ;
207+
208+ if ( ! v . valid ) {
209+ const message : any [ ] = v . errors . map ( ( { property, stack, schema } ) => {
210+ let message : string ;
211+ if ( schema [ 'description' ] ) {
212+ message = schema [ 'description' ] ;
213+ } else {
214+ message = stack . replace ( 'instance.' , '' ) ;
215+ }
216+ return {
217+ property : property . replace ( 'instance.' , '' ) ,
218+ message,
219+ } ;
220+ } ) ;
221+ logger . error ( [ ...message ] ) ;
222+ throw new BadRequestException ( ...message ) ;
223+ }
224+
225+ return await execute ( instance , ref ) ;
226+ }
184227}
0 commit comments