Skip to content

Commit

Permalink
feat(learner): include user interests for getLearnerById
Browse files Browse the repository at this point in the history
  • Loading branch information
elskow committed Dec 3, 2024
1 parent 0bdfaba commit 2ee6978
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/module/learner/learner.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class LearnerRepository {
}

public async getLearnerById(learnerId: string) {
const result = await this.db
const [learner] = await this.db
.select({
id: learners.id,
name: learners.name,
Expand All @@ -74,7 +74,19 @@ export class LearnerRepository {
.where(eq(learners.id, learnerId))
.limit(1);

return result[0];
if (!learner) return null;

const userInterests = await this.db
.select({
categoryId: interests.categoryId,
})
.from(interests)
.where(eq(interests.learnerId, learnerId));

return {
...learner,
interests: userInterests.map((i) => i.categoryId),
};
}

public async getLearners() {
Expand Down

0 comments on commit 2ee6978

Please sign in to comment.