Complete the code to import PrismaClient correctly in a NestJS service.
import { [1] } from '@prisma/client';
PrismaClient is the main class provided by Prisma to interact with the database in a type-safe way.
Complete the code to create a new PrismaClient instance in the service constructor.
constructor() {
this.prisma = new [1]();
}Creating a new instance of PrismaClient allows the service to access the database with type safety.
Fix the error in the method to fetch all users using Prisma's type-safe API.
async getAllUsers() {
return await this.prisma.user.[1]();
}The correct Prisma method to fetch multiple records is findMany(), which returns a typed array of users.
Fill both blanks to define a type-safe method that finds a user by ID.
async getUserById(id: number) {
return await this.prisma.user.[1]({ where: { id: [2] } });
}findUnique is used to find a single record by a unique field like id, ensuring type safety.
Fill all three blanks to create a type-safe method that updates a user's email by ID.
async updateUserEmail(id: number, email: string) {
return await this.prisma.user.[1]({
where: { id: [2] },
data: { email: [3] }
});
}The update method updates a record. The where clause uses the id field, and the data object sets the new email. This ensures type-safe updates.