samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.85k stars 95 forks source link

TypeBody only supports typia.assert not assertEquals #371

Closed saroro1 closed 1 year ago

saroro1 commented 1 year ago
// user.enity.ts

export class User {
  @PrimaryGeneratedColumn()
  id: number;
   @Column({ unique: true, length: 30 })
  email: string;
}
// update-user.ts

export class UpdateUserDto extends PartialType(CreateUserDto) {
    /**
   *
   @format email
   */
  email?: string;
}
//user.controller.ts

  @TypedRoute.Post('/modify')
  async updateUser(
    @TypedBody() updateUser: UpdateUserDto,
    @Req() req: Request & Record<'user', JwtPayload>,
  ) {
    await this.userService.modifyUser(req.user.id, updateUser);
  }

When sending request with json body {"id" : "asdgsd", "email" : "john@gmail.com"}, It occurs error because nestia only checks whether body contains specific keys or not.

Could you add strict mode to prevent from wrong body like upper case?

samchon commented 1 year ago

Good idea

samchon commented 1 year ago

Upgrade to @nestia/core@1.3.3, and configure "validate" property of plugin to be "assertEquals"