Slide 52
Slide 52 text
@injectable()
export class UsersGetMediator {
constructor(
private readonly auth: AuthService,
private readonly permissionVerifier: PermissionVerifier,
private readonly errorHandler: ErrorHandler,
private readonly usersRepo: UsersRepository,
) {}
async handle(req: Request, res: Response) {
if (!(await this.auth.isAuthenticated(req))) {
return this.errorHandler.unauthorized(res);
}
if (!(await this.permissionVerifier.canReadUsers(req.user.id))) {
return this.errorHandler.forbidden(res);
}
const users = await this.usersRepo.getAll();
const body: UsersGetResponse = {
users: users.serialize(),
};
res.send(body).end();
}
}