From 491f7afc7737abf2a773573126a7af8c363205de Mon Sep 17 00:00:00 2001 From: Benjamin Frost Date: Mon, 6 May 2024 23:37:41 +0200 Subject: [PATCH] feat: populate user posts --- src/users/users.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/users/users.service.ts b/src/users/users.service.ts index b030ade..5873da0 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -20,7 +20,17 @@ export class UsersService { } findOne(id: number) { - return this.userRepository.findOneOrFail({ id }); + return this.userRepository.findOneOrFail( + { id }, + { + populate: [ + 'posts', + 'posts.likedBy', + 'posts.comments', + 'posts.comments.author', + ], + }, + ); } findOneByUsername(username: string) { @@ -33,6 +43,7 @@ export class UsersService { file?: Express.Multer.File, ) { const user = await this.userRepository.findOneOrFail({ id }); + // @ts-expect-error wrap causes error in type system wrap(user).assign(updateUserDto); if (file) user.imageUrl = `/uploads/${file.filename}`; await this.em.flush();