Complete the code to inject a provider into a controller.
constructor(private readonly [1]: UsersService) {}The provider instance is injected using a private readonly property with camelCase naming.
Complete the code to call a method from the provider inside a controller method.
return this.usersService.[1](id);
The controller calls the provider method that fetches a user by ID.
Fix the error in the provider method signature to properly return a Promise.
async getUser(id: string): [1] {Async methods in NestJS providers should return a Promise of the expected type.
Fill both blanks to create a provider method that filters users by age.
getUsersByAge([1]: number): User[] { return this.users.filter(user => user.[2] === age); }
The method parameter and the user property to compare must both be 'age' to filter correctly.
Fill all three blanks to create a provider method that returns a dictionary of user names keyed by their IDs for users older than 18.
getAdultUserNames(): Record<string, string> {
return this.users.reduce((acc, user) => {
if (user.[1] > [2]) {
acc[user.[3]] = user.name;
}
return acc;
}, {});
}The method checks if user age is greater than 18 and uses user id as the key in the result object.