0
0
NestJSframework~10 mins

Why Prisma offers type-safe database access in NestJS - Test Your Understanding

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

Complete the code to import PrismaClient correctly in a NestJS service.

NestJS
import { [1] } from '@prisma/client';
Drag options to blanks, or click blank then click option'
AClient
BDatabaseClient
CPrismaService
DPrismaClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name that does not exist in '@prisma/client'.
Confusing PrismaClient with service classes.
2fill in blank
medium

Complete the code to create a new PrismaClient instance in the service constructor.

NestJS
constructor() {
  this.prisma = new [1]();
}
Drag options to blanks, or click blank then click option'
AClient
BDatabaseClient
CPrismaClient
DPrismaService
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name that is not imported or does not exist.
Forgetting to instantiate the client with 'new'.
3fill in blank
hard

Fix the error in the method to fetch all users using Prisma's type-safe API.

NestJS
async getAllUsers() {
  return await this.prisma.user.[1]();
}
Drag options to blanks, or click blank then click option'
AfindAll
BfindMany
CgetAll
DfetchAll
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent Prisma methods like 'findAll' or 'getAll'.
Confusing Prisma methods with other ORM methods.
4fill in blank
hard

Fill both blanks to define a type-safe method that finds a user by ID.

NestJS
async getUserById(id: number) {
  return await this.prisma.user.[1]({ where: { id: [2] } });
}
Drag options to blanks, or click blank then click option'
AfindUnique
BfindMany
Cid
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'findMany' when only one record is expected.
Using a wrong field name in the where clause.
5fill in blank
hard

Fill all three blanks to create a type-safe method that updates a user's email by ID.

NestJS
async updateUserEmail(id: number, email: string) {
  return await this.prisma.user.[1]({
    where: { id: [2] },
    data: { email: [3] }
  });
}
Drag options to blanks, or click blank then click option'
Aupdate
Bid
Cemail
DfindUnique
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'findUnique' instead of 'update' for updating data.
Mixing up field names in the where or data objects.