0
0
NestJSframework~10 mins

Prisma setup in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import PrismaService in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { [1] } from './prisma.service';

@Module({
  providers: [PrismaService],
  exports: [PrismaService],
})
export class PrismaModule {}
Drag options to blanks, or click blank then click option'
APrismaService
BPrismaModule
CPrismaClient
DPrismaController
Attempts:
3 left
💡 Hint
Common Mistakes
Importing PrismaClient directly instead of PrismaService.
Using PrismaModule instead of PrismaService.
2fill in blank
medium

Complete the PrismaService class to extend the correct Prisma client.

NestJS
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();
  }
}
Drag options to blanks, or click blank then click option'
APrismaModule
BPrismaService
CPrismaController
DPrismaClient
Attempts:
3 left
💡 Hint
Common Mistakes
Extending PrismaService instead of PrismaClient.
Importing wrong class from @prisma/client.
3fill in blank
hard

Fix the error in injecting PrismaService into a controller constructor.

NestJS
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();
  }
}
Drag options to blanks, or click blank then click option'
APrismaService
Bprisma
CuserService
Dservice
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as variable name causing confusion.
Using unrelated variable names like userService.
4fill in blank
hard

Fill both blanks to create a Prisma query that finds users with age greater than 18.

NestJS
async findAdults() {
  return this.prisma.user.findMany({
    where: { age: { [1]: [2] } }
  });
}
Drag options to blanks, or click blank then click option'
Agt
Bgte
Clt
D18
Attempts:
3 left
💡 Hint
Common Mistakes
Using lt or lte which mean less than.
Using gte which includes 18, not strictly greater.
5fill in blank
hard

Fill all three blanks to create a Prisma query that updates a user's email by id.

NestJS
async updateEmail([1]: number, [2]: string) {
  return this.prisma.user.update({
    where: { id: [1] },
    data: { email: [2] }
  });
}
Drag options to blanks, or click blank then click option'
AuserId
BnewEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in parameters and query.
Forgetting to update the email field.