#Prisma Omit
13 messages · Page 1 of 1 (latest)
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.
so make dto file for filtering that ?
how about change that to another string like *******, that's safe or not ?
Why returning something useless ?
ok my bad haha
No, you just create another type, with pseudo, email, name, etc. But no password.
ok got it, thanks man
You can use Pick, or Partial, to reduce the boilerplate of having different DTO for the same entity.
how to combine that between dto and prisma model with partial ?
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 !