0
0
NestJSframework~10 mins

CRUD with Prisma 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 create a new user using Prisma client.

NestJS
const user = await this.prisma.user.[1]({ data: { name: 'Alice', email: 'alice@example.com' } });
Drag options to blanks, or click blank then click option'
Acreate
BfindUnique
Cupdate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using findUnique instead of create will only search, not add data.
Using update or delete will modify or remove data, not create.
2fill in blank
medium

Complete the code to find a user by their unique email.

NestJS
const user = await this.prisma.user.[1]({ where: { email: 'bob@example.com' } });
Drag options to blanks, or click blank then click option'
Acreate
BfindUnique
Cdelete
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using create will add a new user instead of finding one.
Using update or delete will modify or remove data, not fetch.
3fill in blank
hard

Fix the error in updating a user's name by their ID.

NestJS
const updatedUser = await this.prisma.user.[1]({ where: { id: userId }, data: { name: newName } });
Drag options to blanks, or click blank then click option'
Acreate
BfindUnique
Cupdate
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using create will add a new user instead of updating.
Using findUnique only fetches data, does not update.
Using delete removes data instead of updating.
4fill in blank
hard

Fill both blanks to delete a user by their ID and return the deleted user.

NestJS
const deletedUser = await this.prisma.user.[1]({ where: { id: [2] } });
Drag options to blanks, or click blank then click option'
Adelete
Bupdate
CuserId
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using update or create will not delete the user.
Passing a wrong variable name instead of userId causes errors.
5fill in blank
hard

Fill all three blanks to update a user's email by their ID and return the updated user.

NestJS
const updatedUser = await this.prisma.user.[1]({ where: { id: [2] }, data: { email: [3] } });
Drag options to blanks, or click blank then click option'
Acreate
BuserId
C'newemail@example.com'
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using create instead of update adds a new user.
Forgetting quotes around the new email string causes syntax errors.
Using wrong variable names for ID causes runtime errors.