Omit type for creating

However, I can use delete user.password. Is there a way to omit the password when creating a new user?
.tsx
async create(dto: CreateUserDto) {
const user = await this.prismaService.instance.user.create({
data: {
...dto,
},
});

return user;
}
.tsx
async create(dto: CreateUserDto) {
const user = await this.prismaService.instance.user.create({
data: {
...dto,
},
});

return user;
}
3 Replies
RaphaelEtim
RaphaelEtim4d ago
Hi @Myat Min Aung [WE] You can use the omit option to exclude specific fields from the query result, including when creating a new user. You need to enable the omitApi preview feature in your Prisma schema and run prisma generate after enabling the omitApi preview feature to update your Prisma Client.
generator client {
provider = "prisma-client-js"
previewFeatures = ["omitApi"]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["omitApi"]
}
Then, update your create method to use the omit option:
async create(dto: CreateUserDto) {
const user = await this.prismaService.instance.user.create({
data: {
...dto,
},
omit: {
password: true
}
});

return user;
}
async create(dto: CreateUserDto) {
const user = await this.prismaService.instance.user.create({
data: {
...dto,
},
omit: {
password: true
}
});

return user;
}
https://www.prisma.io/docs/orm/prisma-client/queries/excluding-fields
Excluding fields | Prisma Documentation
This page explains how to exclude sensitive fields from Prisma Client
Myat Min Aung [WE]
Thanks for the guidance; I appreciate it.
RaphaelEtim
RaphaelEtim4d ago
You're welcome 🙏
Want results from more Discord servers?
Add your server