AjobK / Seaqull

Seaqull programming blog
http://www.seaqull.com
4 stars 0 forks source link

When viewing users that liked post, incorrect avatar and title is shown #257

Closed AjobK closed 3 years ago

jerohero commented 3 years ago

Used TypeORM's sub-relation feature (_profile.title, profile.avatarattachment) to fetch profile avatar and title. Banner can't be fetched yet as it's not present in this branch (and due to the current issues with the branches I can't update it). Noticed this feature wasn't used in other places in the API, such as the profile controller and instead relies on seperate DB requests. I feel like the method I used here is much better, but if it's too inconsistent I could change it.

    public async getPostLikesById(id: number): Promise<any> {
        if (!id) return null
        const repository = await DatabaseConnector.getRepository('PostLike')

        return await repository.find({
            where: { post: id },
            relations: ['post', 'profile', 'profile.avatar_attachment', 'profile.title']
        })
    }