Skip to content

feat(api): include profile image in journal queries #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export class JournalProfileDetails {
public readonly id!: number;
public readonly imageUrl?: string;
public readonly name?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Between, Repository } from "typeorm";

import { map, mapArray } from "src/core/mapper";
import { CurrentOrganizationService } from "src/core/organizations";
import { PhotoService } from "src/core/photos";
import { QueryService } from "src/core/query";

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

Expand All @@ -39,6 +41,11 @@ export class GetCurrentOrganizationJournalHandler
},
query,
required: {
relations: {
profile: {
profilePhoto: true,
},
},
where: {
createdAt: Between(query.from, query.to),
organizationId: currentOrganizationId,
Expand All @@ -55,6 +62,13 @@ export class GetCurrentOrganizationJournalHandler
payload: entry.payload,
profile: map(JournalProfileDetails, {
id: entry.profileId,
imageUrl:
entry.profile.profilePhoto?.objectId &&
this.photoService.getUrl(
entry.profile.profilePhoto,
"profile-photo",
),
name: entry.profile.name,
}),
})),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InjectRepository } from "@nestjs/typeorm";
import { Between, Repository } from "typeorm";

import { map, mapArray } from "src/core/mapper";
import { PhotoService } from "src/core/photos";
import { CurrentProfileService } from "src/core/profiles";
import { QueryService } from "src/core/query";

Expand All @@ -24,6 +25,7 @@ export class GetProfileJournalHandler
private readonly currentProfileService: CurrentProfileService,
@InjectRepository(JournalEntry)
private readonly journalEntries: Repository<JournalEntry>,
private readonly photoService: PhotoService,
private readonly queryService: QueryService<JournalEntry>,
) {}

Expand All @@ -39,6 +41,11 @@ export class GetProfileJournalHandler
},
query,
required: {
relations: {
profile: {
profilePhoto: true,
},
},
where: {
createdAt: Between(query.from, query.to),
profileId: currentProfileId,
Expand All @@ -55,6 +62,13 @@ export class GetProfileJournalHandler
payload: entry.payload,
profile: map(JournalProfileDetails, {
id: entry.profileId,
imageUrl:
entry.profile.profilePhoto?.objectId &&
this.photoService.getUrl(
entry.profile.profilePhoto,
"profile-photo",
),
name: entry.profile.name,
}),
})),
});
Expand Down
2 changes: 2 additions & 0 deletions services/api/src/core/journal/journal.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TypeOrmModule } from "@nestjs/typeorm";

import { AuthenticationModule } from "src/core/authentication/authentication.module";
import { OrganizationModule } from "src/core/organizations/organization.module";
import { PhotosModule } from "src/core/photos/photos.module";
import { ProfileModule } from "src/core/profiles/profile.module";
import { QueryModule } from "src/core/query/query.module";

Expand All @@ -19,6 +20,7 @@ import { JournalLogger } from "./journal.listener";
AuthenticationModule,
CqrsModule,
OrganizationModule,
PhotosModule,
ProfileModule,
TypeOrmModule.forFeature([JournalEntry]),
QueryModule,
Expand Down