Skip to content

Commit

Permalink
feat: move project owner read model to personal dashboard service
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Sep 25, 2024
1 parent 846e16f commit 3f20ed5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type PersonalProject = {
id: number;
type: 'custom' | 'project' | 'root' | 'custom-root';
}[];
};
export type PersonalProjectWithOwners = PersonalProject & {
owners: ProjectOwners;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Db } from '../../db/db';
import type { IProjectOwnersReadModel } from '../project/project-owners-read-model.type';
import type {
IPersonalDashboardReadModel,
PersonalFeature,
Expand All @@ -15,11 +14,8 @@ type IntermediateProjectResult = Omit<PersonalProject, 'roles'> & {
export class PersonalDashboardReadModel implements IPersonalDashboardReadModel {
private db: Db;

private projectOwnersReadModel: IProjectOwnersReadModel;

constructor(db: Db, ProjectOwnersReadModel: IProjectOwnersReadModel) {
constructor(db: Db) {
this.db = db;
this.projectOwnersReadModel = ProjectOwnersReadModel;
}

async getPersonalProjects(userId: number): Promise<PersonalProject[]> {
Expand Down Expand Up @@ -92,10 +88,7 @@ export class PersonalDashboardReadModel implements IPersonalDashboardReadModel {
},
);
projectList.sort((a, b) => a.name.localeCompare(b.name));
const withOwners =
await this.projectOwnersReadModel.addOwners(projectList);

return withOwners;
return projectList;
}

async getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
Expand Down
23 changes: 19 additions & 4 deletions src/lib/features/personal-dashboard/personal-dashboard-service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import type { IProjectOwnersReadModel } from '../project/project-owners-read-model.type';
import type {
IPersonalDashboardReadModel,
PersonalFeature,
PersonalProject,
PersonalProjectWithOwners,
} from './personal-dashboard-read-model-type';

export class PersonalDashboardService {
private personalDashboardReadModel: IPersonalDashboardReadModel;

constructor(personalDashboardReadModel: IPersonalDashboardReadModel) {
private projectOwnersReadModel: IProjectOwnersReadModel;

constructor(
personalDashboardReadModel: IPersonalDashboardReadModel,
projectOwnersReadModel: IProjectOwnersReadModel,
) {
this.personalDashboardReadModel = personalDashboardReadModel;
this.projectOwnersReadModel = projectOwnersReadModel;
}

getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
return this.personalDashboardReadModel.getPersonalFeatures(userId);
}

getPersonalProjects(userId: number): Promise<PersonalProject[]> {
return this.personalDashboardReadModel.getPersonalProjects(userId);
async getPersonalProjects(
userId: number,
): Promise<PersonalProjectWithOwners[]> {
const projects =
await this.personalDashboardReadModel.getPersonalProjects(userId);

const withOwners =
await this.projectOwnersReadModel.addOwners(projects);

return withOwners;
}
}
5 changes: 4 additions & 1 deletion src/lib/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import { PersonalDashboardService } from '../features/personal-dashboard/persona
import { PersonalDashboardReadModel } from '../features/personal-dashboard/personal-dashboard-read-model';
import { FakePersonalDashboardReadModel } from '../features/personal-dashboard/fake-personal-dashboard-read-model';
import { ProjectOwnersReadModel } from '../features/project/project-owners-read-model';
import { FakeProjectOwnersReadModel } from '../features/project/fake-project-owners-read-model';

export const createServices = (
stores: IUnleashStores,
Expand Down Expand Up @@ -407,8 +408,10 @@ export const createServices = (

const personalDashboardService = new PersonalDashboardService(
db
? new PersonalDashboardReadModel(db, new ProjectOwnersReadModel(db))
? new PersonalDashboardReadModel(db)
: new FakePersonalDashboardReadModel(),

db ? new ProjectOwnersReadModel(db) : new FakeProjectOwnersReadModel(),
);

return {
Expand Down

0 comments on commit 3f20ed5

Please sign in to comment.