From ef7127ee4487c57f743a948827be9a8be8dd4047 Mon Sep 17 00:00:00 2001 From: Artem Derevnjuk Date: Wed, 24 Aug 2022 12:14:51 +0300 Subject: [PATCH] fix(users): prevent NPE while retrieving unknown user (#24) --- src/users/users.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/users/users.service.ts b/src/users/users.service.ts index ae0aa67..ef3287e 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -31,7 +31,7 @@ export class UsersService { * you can fix the actual issue: * ```ts * public findOne(id: number): Promise { - * return this.orm.em.findOne({ id }); + * return this.orm.em.findOne(User, { id }); * } * ``` * @@ -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; * } * ``` */ @@ -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 {