@nestjs/core#APP_PIPE TypeScript Examples

The following examples show how to use @nestjs/core#APP_PIPE. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.module.ts    From postgres-nest-react-typescript-boilerplate with GNU General Public License v3.0 6 votes vote down vote up
@Module({
  imports: [TypeOrmModule.forRoot(), TodoModule, UserModule],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_FILTER,
      useClass: HttpErrorFilter,
    },
    {
      provide: APP_PIPE,
      useClass: ValidationPipe,
    },
  ],
})
export class AppModule {}
Example #2
Source File: joi-pipe.module.ts    From nestjs-joi with MIT License 6 votes vote down vote up
static forRoot(options: JoiPipeModuleOptions = {}): DynamicModule {
    const providers: Provider[] = [
      {
        provide: APP_PIPE,
        useClass: JoiPipe,
      },
    ];

    if (options.pipeOpts) {
      providers.push({
        provide: JOIPIPE_OPTIONS,
        useValue: options.pipeOpts,
      });
    }

    return {
      module: JoiPipeModule,
      global: true,
      providers,
    };
  }
Example #3
Source File: joi-pipe.module.spec.ts    From nestjs-joi with MIT License 5 votes vote down vote up
describe('JoiPipeModule', () => {
  describe('constructor', () => {
    it('should define the correct class metadata', async () => {
      const imports = Reflect.getMetadata('imports', JoiPipeModule);
      const providers = Reflect.getMetadata('providers', JoiPipeModule);
      const exports = Reflect.getMetadata('exports', JoiPipeModule);
      const controllers = Reflect.getMetadata('controllers', JoiPipeModule);
      const globalSetting = Reflect.getMetadata('__module:global__', JoiPipeModule);

      expect(imports).toEqual([]);
      expect(providers).toEqual([
        {
          provide: APP_PIPE,
          useClass: JoiPipe,
        },
      ]);
      expect(controllers).toEqual([]);
      expect(exports).toEqual([]);
      expect(globalSetting).toEqual(true);
    });
  });

  describe('forRoot()', () => {
    it('should return a correct DynamicModule definition without options', async () => {
      const dynamicModuleDef = JoiPipeModule.forRoot();

      expect(dynamicModuleDef).toEqual({
        module: JoiPipeModule,
        providers: [
          {
            provide: APP_PIPE,
            useClass: JoiPipe,
          },
        ],
        global: true,
      });
    });

    it('should create a provider definition for options when options are specified', async () => {
      const options = {
        pipeOpts: { usePipeValidationException: true },
      };
      const dynamicModuleDef = JoiPipeModule.forRoot(options);

      expect(dynamicModuleDef).toEqual({
        module: JoiPipeModule,
        providers: [
          {
            provide: APP_PIPE,
            useClass: JoiPipe,
          },
          {
            provide: JOIPIPE_OPTIONS,
            useValue: options.pipeOpts,
          },
        ],
        global: true,
      });
    });
  });
});