Skip to content

Commit 53e22da

Browse files
committed
feat(api): include profile image in journal queries
1 parent d1b6a15 commit 53e22da

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export class JournalProfileDetails {
22
public readonly id!: number;
3+
public readonly imageUrl?: string;
4+
public readonly name?: string;
35
}

services/api/src/core/journal/application/handlers/query-handlers/get-current-organization-journal.handler.ts

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Between, Repository } from "typeorm";
44

55
import { map, mapArray } from "src/core/mapper";
66
import { CurrentOrganizationService } from "src/core/organizations";
7+
import { PhotoService } from "src/core/photos";
78
import { QueryService } from "src/core/query";
89

910
import { JournalEntry } from "../../../infrastructure/entities/journal-entry.entity";
@@ -24,6 +25,7 @@ export class GetCurrentOrganizationJournalHandler
2425
private readonly currentOrganizationService: CurrentOrganizationService,
2526
@InjectRepository(JournalEntry)
2627
private readonly journalEntries: Repository<JournalEntry>,
28+
private readonly photoService: PhotoService,
2729
private readonly queryService: QueryService<JournalEntry>,
2830
) {}
2931

@@ -39,6 +41,11 @@ export class GetCurrentOrganizationJournalHandler
3941
},
4042
query,
4143
required: {
44+
relations: {
45+
profile: {
46+
profilePhoto: true,
47+
},
48+
},
4249
where: {
4350
createdAt: Between(query.from, query.to),
4451
organizationId: currentOrganizationId,
@@ -55,6 +62,13 @@ export class GetCurrentOrganizationJournalHandler
5562
payload: entry.payload,
5663
profile: map(JournalProfileDetails, {
5764
id: entry.profileId,
65+
imageUrl:
66+
entry.profile.profilePhoto?.objectId &&
67+
this.photoService.getUrl(
68+
entry.profile.profilePhoto,
69+
"profile-photo",
70+
),
71+
name: entry.profile.name,
5872
}),
5973
})),
6074
});

services/api/src/core/journal/application/handlers/query-handlers/get-profile-journal.handler.ts

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { InjectRepository } from "@nestjs/typeorm";
33
import { Between, Repository } from "typeorm";
44

55
import { map, mapArray } from "src/core/mapper";
6+
import { PhotoService } from "src/core/photos";
67
import { CurrentProfileService } from "src/core/profiles";
78
import { QueryService } from "src/core/query";
89

@@ -24,6 +25,7 @@ export class GetProfileJournalHandler
2425
private readonly currentProfileService: CurrentProfileService,
2526
@InjectRepository(JournalEntry)
2627
private readonly journalEntries: Repository<JournalEntry>,
28+
private readonly photoService: PhotoService,
2729
private readonly queryService: QueryService<JournalEntry>,
2830
) {}
2931

@@ -39,6 +41,11 @@ export class GetProfileJournalHandler
3941
},
4042
query,
4143
required: {
44+
relations: {
45+
profile: {
46+
profilePhoto: true,
47+
},
48+
},
4249
where: {
4350
createdAt: Between(query.from, query.to),
4451
profileId: currentProfileId,
@@ -55,6 +62,13 @@ export class GetProfileJournalHandler
5562
payload: entry.payload,
5663
profile: map(JournalProfileDetails, {
5764
id: entry.profileId,
65+
imageUrl:
66+
entry.profile.profilePhoto?.objectId &&
67+
this.photoService.getUrl(
68+
entry.profile.profilePhoto,
69+
"profile-photo",
70+
),
71+
name: entry.profile.name,
5872
}),
5973
})),
6074
});

services/api/src/core/journal/journal.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TypeOrmModule } from "@nestjs/typeorm";
44

55
import { AuthenticationModule } from "src/core/authentication/authentication.module";
66
import { OrganizationModule } from "src/core/organizations/organization.module";
7+
import { PhotosModule } from "src/core/photos/photos.module";
78
import { ProfileModule } from "src/core/profiles/profile.module";
89
import { QueryModule } from "src/core/query/query.module";
910

@@ -19,6 +20,7 @@ import { JournalLogger } from "./journal.listener";
1920
AuthenticationModule,
2021
CqrsModule,
2122
OrganizationModule,
23+
PhotosModule,
2224
ProfileModule,
2325
TypeOrmModule.forFeature([JournalEntry]),
2426
QueryModule,

0 commit comments

Comments
 (0)