Skip to content

Commit

Permalink
feat: populate user posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Frost committed May 6, 2024
1 parent 84672d8 commit 491f7af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit 491f7af

Please sign in to comment.