Skip to content

Commit

Permalink
fix(users): prevent NPE while retrieving unknown user (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
derevnjuk authored Aug 24, 2022
1 parent d7aba1d commit ef7127e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class UsersService {
* you can fix the actual issue:
* ```ts
* public findOne(id: number): Promise<User | null> {
* return this.orm.em.findOne({ id });
* return this.orm.em.findOne(User, { id });
* }
* ```
*
Expand All @@ -42,7 +42,7 @@ export class UsersService {
* .getConnection()
* .execute(`select * from "user" where "id" = ?`, [id]);
*
* return this.orm.em.map(User, user);
* return user ? this.orm.em.map(User, user) : null;
* }
* ```
*/
Expand All @@ -51,7 +51,7 @@ export class UsersService {
.getConnection()
.execute(`select * from "user" where "id" = ${id}`);

return this.orm.em.map(User, user);
return user ? this.orm.em.map(User, user) : null;
}

public async remove(id: number): Promise<void> {
Expand Down

0 comments on commit ef7127e

Please sign in to comment.