Complete the code to import the service layer module correctly.
const userService = require('[1]');
The service layer module is usually imported from a local file path like './services/userService'.
Complete the code to call the service method that fetches all users.
app.get('/users', async (req, res) => { const users = await userService.[1](); res.json(users); });
The service layer method to fetch all users is typically named 'getAllUsers'.
Fix the error in the service method call to get a user by ID.
const user = await userService.getUserById([1]);To get a user by ID, the service method needs the ID from the request parameters: 'req.params.id'.
Fill both blanks to create a service method that updates a user and returns the updated user.
async function updateUser([1], [2]) { const updatedUser = await UserModel.findByIdAndUpdate(id, data, { new: true }); return updatedUser; }
The updateUser method takes 'id' and 'data' as parameters to update the user and return the new data.
Fill all three blanks to create a service method that deletes a user by ID and returns a confirmation message.
async function deleteUser([1]) { await UserModel.findByIdAndDelete([2]); return { message: `User with ID [3] deleted.` }; }
The deleteUser method uses 'id' as the parameter and in the delete call, and the message uses template syntax '${id}' to show the deleted user ID.