Skip to content

Commit

Permalink
fix: use onboarding status to check project existence
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Oct 4, 2024
1 parent 2d5fb02 commit 3a99496
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { OnboardingReadModel } from '../onboarding/onboarding-read-model';
import { FakeOnboardingReadModel } from '../onboarding/fake-onboarding-read-model';
import { AccessStore } from '../../db/access-store';
import FakeAccessStore from '../../../test/fixtures/fake-access-store';
import ProjectStore from '../project/project-store';
import FakeProjectStore from '../../../test/fixtures/fake-project-store';

export const createPersonalDashboardService = (
db: Db,
Expand All @@ -39,12 +37,6 @@ export const createPersonalDashboardService = (
new PrivateProjectChecker(stores, config),
new AccountStore(db, config.getLogger),
new AccessStore(db, config.eventBus, config.getLogger),
new ProjectStore(
db,
config.eventBus,
config.getLogger,
config.flagResolver,
),
);
};

Expand All @@ -62,6 +54,5 @@ export const createFakePersonalDashboardService = (config: IUnleashConfig) => {
new FakePrivateProjectChecker(),
new FakeAccountStore(),
new FakeAccessStore(),
new FakeProjectStore(),
);
};
52 changes: 23 additions & 29 deletions src/lib/features/personal-dashboard/personal-dashboard-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
import type { IProjectReadModel } from '../project/project-read-model-type';
import type { IPrivateProjectChecker } from '../private-project/privateProjectCheckerType';
import type {
IProjectStore,
IAccessStore,
IAccountStore,
IEvent,
Expand Down Expand Up @@ -43,8 +42,6 @@ export class PersonalDashboardService {

private accessStore: IAccessStore;

private projectStore: IProjectStore;

constructor(
personalDashboardReadModel: IPersonalDashboardReadModel,
projectOwnersReadModel: IProjectOwnersReadModel,
Expand All @@ -55,7 +52,6 @@ export class PersonalDashboardService {
privateProjectChecker: IPrivateProjectChecker,
accountStore: IAccountStore,
accessStore: IAccessStore,
projectStore: IProjectStore,
) {
this.personalDashboardReadModel = personalDashboardReadModel;
this.projectOwnersReadModel = projectOwnersReadModel;
Expand All @@ -66,7 +62,6 @@ export class PersonalDashboardService {
this.privateProjectChecker = privateProjectChecker;
this.accountStore = accountStore;
this.accessStore = accessStore;
this.projectStore = projectStore;
}

getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
Expand Down Expand Up @@ -111,7 +106,12 @@ export class PersonalDashboardService {
userId: number,
projectId: string,
): Promise<PersonalDashboardProjectDetailsSchema> {
if (!(await this.projectStore.hasProject(projectId))) {
const onboardingStatus =
await this.onboardingReadModel.getOnboardingStatusForProject(
projectId,
);

if (!onboardingStatus) {
throw new NotFoundError(
`No project with id "${projectId}" exists.`,
);
Expand All @@ -134,29 +134,23 @@ export class PersonalDashboardService {
type: role.type as PersonalDashboardProjectDetailsSchema['roles'][number]['type'],
}));

const [latestEvents, onboardingStatus, owners, roles, healthScores] =
await Promise.all([
this.eventStore
.searchEvents({ limit: 4, offset: 0 }, [
{
field: 'project',
operator: 'IS',
values: [projectId],
},
])
.then(formatEvents),
this.onboardingReadModel.getOnboardingStatusForProject(
projectId,
),
this.projectOwnersReadModel.getProjectOwners(projectId),
this.accessStore
.getAllProjectRolesForUser(userId, projectId)
.then(filterRoles),
this.personalDashboardReadModel.getLatestHealthScores(
projectId,
8,
),
]);
const [latestEvents, owners, roles, healthScores] = await Promise.all([
this.eventStore
.searchEvents({ limit: 4, offset: 0 }, [
{
field: 'project',
operator: 'IS',
values: [projectId],
},
])
.then(formatEvents),
this.onboardingReadModel.getOnboardingStatusForProject(projectId),
this.projectOwnersReadModel.getProjectOwners(projectId),
this.accessStore
.getAllProjectRolesForUser(userId, projectId)
.then(filterRoles),
this.personalDashboardReadModel.getLatestHealthScores(projectId, 8),
]);

let avgHealthCurrentWindow: number | null = null;
let avgHealthPastWindow: number | null = null;
Expand Down

0 comments on commit 3a99496

Please sign in to comment.