diff --git a/src/access.controller.ts b/src/access.controller.ts index cec00d4..1d6ee2f 100644 --- a/src/access.controller.ts +++ b/src/access.controller.ts @@ -8,17 +8,23 @@ export class AccessController { constructor(private readonly userService: UserService) {} @Post('/login') - public login(name: string, password: string): void { + public login(name: string, password: string): {userId: number} { this.logger.debug("Received login request"); const user = this.userService.getUserByName(name); if (user.password !== password) { throw new UnauthorizedException(); } + return { + userId: user.id + }; } @Post('/register') - public new(name: string, password: string): void { + public new(name: string, password: string): {userId: number} { this.logger.debug("Received register request"); - this.userService.createUser(name, password); + const user = this.userService.createUser(name, password); + return { + userId: user.id + }; } } diff --git a/src/user.service.ts b/src/user.service.ts index 0b4cf86..1920663 100644 --- a/src/user.service.ts +++ b/src/user.service.ts @@ -23,17 +23,20 @@ export class UserService { return user; } - public createUser(name: string, password: string): void { + public createUser(name: string, password: string): User { try { this.getUserByName(name); throw new NotFoundException(); } catch (e) { if (!(e instanceof NotFoundException)) throw e; } - this.users.push({ + + const user: User = { id: this.users.length, name, password, - }); + }; + this.users.push(user); + return user; } }