0
0
NestJSframework~20 mins

CRUD with Prisma in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Prisma CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Prisma create operation?
Given the following NestJS Prisma service code, what will be the output when creating a new user with name 'Alice' and email 'alice@example.com'?
NestJS
async createUser() {
  const user = await this.prisma.user.create({
    data: { name: 'Alice', email: 'alice@example.com' }
  });
  return user;
}
AReturns null because no user was found
B{"id": 1, "name": "Alice", "email": "alice@example.com"}
CThrows a runtime error because 'id' is missing in data
D{"name": "Alice", "email": "alice@example.com"}
Attempts:
2 left
💡 Hint
Prisma automatically generates the 'id' field if it is set as an auto-increment primary key.
state_output
intermediate
2:00remaining
What is the result of this Prisma update operation?
Consider this update method in a NestJS Prisma service. What will be the returned value after updating the user with id 5 to have name 'Bob'?
NestJS
async updateUser() {
  const updatedUser = await this.prisma.user.update({
    where: { id: 5 },
    data: { name: 'Bob' }
  });
  return updatedUser;
}
A{"id": 5, "name": "Bob", "email": "previous_email@example.com"}
Bnull because user with id 5 does not exist
C{"name": "Bob"}
DThrows a PrismaClientKnownRequestError because user with id 5 does not exist
Attempts:
2 left
💡 Hint
Prisma throws an error if you try to update a record that does not exist.
🔧 Debug
advanced
2:00remaining
Why does this Prisma delete operation fail?
This NestJS Prisma service method tries to delete a user by id but fails with a runtime error. What is the cause?
NestJS
async deleteUser(id: number) {
  await this.prisma.user.delete({
    where: { userId: id }
  });
}
AThe field 'userId' does not exist in the Prisma schema; it should be 'id'.
BThe method is missing an await keyword before the delete call.
CThe delete method requires a 'data' property, not 'where'.
DPrisma delete cannot delete by id, only by unique email.
Attempts:
2 left
💡 Hint
Check the exact field names in your Prisma schema for the User model.
📝 Syntax
advanced
2:00remaining
Which option correctly fetches all users with Prisma in NestJS?
Select the correct Prisma query to fetch all users from the database.
Aconst users = await this.prisma.user.getMany();
Bconst users = await this.prisma.user.findAll();
Cconst users = await this.prisma.user.findMany();
Dconst users = await this.prisma.user.fetchAll();
Attempts:
2 left
💡 Hint
Check the Prisma Client API for fetching multiple records.
🧠 Conceptual
expert
2:00remaining
What happens if you call Prisma update with no matching record?
In NestJS Prisma, what is the behavior when you call prisma.user.update with a where clause that matches no records?
APrisma throws a PrismaClientKnownRequestError indicating no record found.
BPrisma returns null without error.
CPrisma creates a new record with the update data.
DPrisma silently ignores the update and returns the previous data.
Attempts:
2 left
💡 Hint
Consider how Prisma handles updates on non-existent records.