Last active
October 12, 2021 16:08
-
-
Save radzserg/1e32128e7910b06c09ee555d045a5d48 to your computer and use it in GitHub Desktop.
users_controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class UsersController { | |
public constructor( | |
private readonly usersRepository: UsersRepository, | |
private readonly logger: AppLogger | |
) {} | |
public async actionIndex(req: Request, res: Response) { | |
try { | |
const users = await this.usersRepository.findAll(); | |
res.send(users); | |
} catch (e) { | |
this.logger.error(e as Error); | |
throw new InternalServerError("Cannot get users"); | |
} | |
} | |
public async actionCreate(req: Request, res: Response) { | |
// @TBC | |
const user = await this.usersRepository.add({ id: 3, name: "Kate Lee" }); | |
res.send(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment