#Prisma Omit

13 messages · Page 1 of 1 (latest)

ancient fractal
#

i have some confuse how to implement omit in here, if i use it as params it's work but every single endpoint i must be include omit params, can someone explain me how it work as not a params just query ?

hushed bane
#

I think that in your function signature, you say your return UserEntity, but if you omit password, it's not a UserEntity anymore, because the password is missing.

You have to create a DTO, and say your function returns this DTO.

ancient fractal
#

how about change that to another string like *******, that's safe or not ?

hushed bane
#

Why returning something useless ?

ancient fractal
#

ok my bad haha

hushed bane
#

No, you just create another type, with pseudo, email, name, etc. But no password.

ancient fractal
#

ok got it, thanks man

hushed bane
#

You can use Pick, or Partial, to reduce the boilerplate of having different DTO for the same entity.

ancient fractal
hushed bane
#
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, IsString } from 'class-validator';

export class CreateMovieDTO {
  @IsNotEmpty()
  @ApiProperty()
  title: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsNumberString()
  releaseYear: string;

  @ApiProperty()
  image?: string;

  @ApiProperty()
  @IsNumberString()
  producerId?: string;

  @ApiProperty()
  @IsNumberString()
  directorId?: string;

  @ApiProperty()
  @IsString()
  shortSynopsis?: string;

  @ApiProperty()
  @IsString()
  longSynopsis?: string;

  @ApiProperty()
  @IsString()
  teamComment?: string;

  @ApiProperty()
  @IsString()
  history?: string;
}

export class UpdateMovieDTO extends PartialType(CreateMovieDTO) {}
#

To create a movie, title and release year are mandatory.
To update a movie, no property is mandatory.

#

I have no exemple with Pick.
But you may think about a UserListDTO, a DTO that only contains "id", "name" and "avatarURL", the only fields needed to display a list of users.
In my case, ( and I highly recommand to do that ) you have to separate a UserDTO and, let's call it a MineUserDTO.
In the first case, a user retrieves the data from another user.
So you shouldn't give the email !