Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The create method is used to add a new record in Prisma.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The findUnique method fetches a single record by a unique field like email.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The update method changes existing records based on a unique identifier.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The delete method removes a record by unique criteria, here by userId.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use update to change the email of a user identified by userId with the new email string.