0
0
NextJSframework~10 mins

Repository pattern for data access in NextJS - 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 the repository class correctly.

NextJS
import [1] from '@/repositories/UserRepository';
Drag options to blanks, or click blank then click option'
AuserRepository
BUserRepository
CUser_repo
DrepositoryUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing in the import name.
Using a different variable name than the exported class.
2fill in blank
medium

Complete the code to create a new instance of the repository.

NextJS
const userRepo = new [1]();
Drag options to blanks, or click blank then click option'
AUserRepository
BuserRepository
CRepositoryUser
Duser_repo
Attempts:
3 left
💡 Hint
Common Mistakes
Using a lowercase or incorrect class name.
Trying to instantiate a variable instead of a class.
3fill in blank
hard

Fix the error in the method call to fetch all users.

NextJS
const users = await userRepo.[1]();
Drag options to blanks, or click blank then click option'
AgetUsers
BfetchUsers
CfindAll
DgetAllUsers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in the repository.
Using a method name that implies fetching but is not defined.
4fill in blank
hard

Fill both blanks to define a repository method that finds a user by ID.

NextJS
async findById([1]) {
  return await this.[2].findOne({ where: { id } });
}
Drag options to blanks, or click blank then click option'
Aid
BuserId
Crepository
Ddb
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that does not match the query.
Using the wrong repository instance name.
5fill in blank
hard

Fill all three blanks to create a new user using the repository pattern.

NextJS
async createUser([1]) {
  const newUser = this.[2].create([3]);
  await this.repository.save(newUser);
  return newUser;
}
Drag options to blanks, or click blank then click option'
AuserData
Brepository
Ddb
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names for user data.
Using a wrong repository instance name.