Complete the code to import PrismaService in a NestJS module.
import { Module } from '@nestjs/common'; import { [1] } from './prisma.service'; @Module({ providers: [PrismaService], exports: [PrismaService], }) export class PrismaModule {}
You need to import PrismaService to use it in your module.
Complete the PrismaService class to extend the correct Prisma client.
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; import { [1] } from '@prisma/client'; @Injectable() export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { async onModuleInit() { await this.$connect(); } async onModuleDestroy() { await this.$disconnect(); } }
The PrismaService class extends PrismaClient to access database methods.
Fix the error in injecting PrismaService into a controller constructor.
import { Controller, Get } from '@nestjs/common'; import { PrismaService } from './prisma.service'; @Controller('users') export class UserController { constructor(private readonly [1]: PrismaService) {} @Get() async findAll() { return this.prisma.user.findMany(); } }
The injected PrismaService instance is usually named prisma to call its methods.
Fill both blanks to create a Prisma query that finds users with age greater than 18.
async findAdults() {
return this.prisma.user.findMany({
where: { age: { [1]: [2] } }
});
}gt means greater than, and 18 is the age limit. Here, gte is incorrect because it means greater than or equal, but the question asks for strictly greater.
Fill all three blanks to create a Prisma query that updates a user's email by id.
async updateEmail([1]: number, [2]: string) { return this.prisma.user.update({ where: { id: [1] }, data: { email: [2] } }); }
The function takes userId and newEmail as parameters. The where clause uses userId to find the user, and data updates the email to newEmail.