UNPKG

@mee4dy/crud

Version:

Create a backend and frontend in 5 minutes! With our powerful full stack crud system, customize it to suit you.

1 lines 1.39 kB
{"version":3,"file":"use-middleware.decorator.cjs","sources":["../../../nestjs/decorators/use-middleware.decorator.ts"],"sourcesContent":["import { CallHandler, ExecutionContext, NestInterceptor, UseInterceptors, applyDecorators } from '@nestjs/common';\nimport { Observable } from 'rxjs';\n\nclass CrudInterceptor implements NestInterceptor {\n constructor(middleware) {\n this.middleware = middleware;\n }\n\n private middleware;\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<any> {\n const req = context.switchToHttp().getRequest();\n\n if (this.middleware) {\n this.middleware(req);\n }\n\n return next.handle();\n }\n}\n\nexport const UseMiddleware = (middleware: any) => {\n const crudInterceptor = new CrudInterceptor(middleware);\n const interceptorDecorator = UseInterceptors(crudInterceptor);\n\n return applyDecorators(interceptorDecorator);\n};\n"],"names":["CrudInterceptor","middleware","context","next","req","UseMiddleware","crudInterceptor","interceptorDecorator","UseInterceptors","applyDecorators"],"mappings":"kHAGA,MAAMA,CAA2C,CAC/C,YAAYC,EAAY,CACtB,KAAK,WAAaA,CAAA,CAKpB,UAAUC,EAA2BC,EAAoC,CACvE,MAAMC,EAAMF,EAAQ,aAAa,EAAE,WAAW,EAE9C,OAAI,KAAK,YACP,KAAK,WAAWE,CAAG,EAGdD,EAAK,OAAO,CAAA,CAEvB,CAEa,MAAAE,EAAiBJ,GAAoB,CAC1C,MAAAK,EAAkB,IAAIN,EAAgBC,CAAU,EAChDM,EAAuBC,kBAAgBF,CAAe,EAE5D,OAAOG,EAAAA,gBAAgBF,CAAoB,CAC7C"}