Skip to content
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

feat: include favorite projects in personal dashboard #8309

Merged
merged 1 commit into from
Sep 30, 2024
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
Expand Up @@ -81,6 +81,13 @@ const createProject = async (name: string, user: IUser) => {
return project;
};

const favoriteProject = async (projectName = 'default') => {
await app.request
.post(`/api/admin/projects/${projectName}/favorites`)
.set('Content-Type', 'application/json')
.expect(200);
};

test('should return personal dashboard with membered projects', async () => {
const { body: user1 } = await loginUser('[email protected]');
const projectA = await createProject('Project A', user1);
Expand Down Expand Up @@ -118,6 +125,36 @@ test('should return personal dashboard with membered projects', async () => {
{
name: projectC.name,
id: projectC.id,
health: 100,
memberCount: 1,
featureCount: 0,
},
],
});
});

test('should return personal dashboard with user favorited projects', async () => {
const { body: user1 } = await loginUser('[email protected]');
const projectA = await createProject('Project A', user1);

await loginUser('[email protected]');
await favoriteProject(projectA.id);

const { body } = await app.request.get(`/api/admin/personal-dashboard`);

expect(body).toMatchObject({
projects: [
{
name: 'Default',
id: 'default',
health: 100,
memberCount: 0,
featureCount: 0,
},
{
name: projectA.name,
id: projectA.id,
health: 100,
memberCount: 1,
featureCount: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ export class PersonalDashboardService {
}

async getPersonalProjects(userId: number): Promise<PersonalProject[]> {
// TODO: add favorite projects in addition to membership projects
const userProjectIds =
await this.projectReadModel.getProjectsByUser(userId);
const [userProjectIds, userFavoritedProjectIds] = await Promise.all([
this.projectReadModel.getProjectsByUser(userId),
this.projectReadModel.getProjectsFavoritedByUser(userId),
]);

const projects = await this.projectReadModel.getProjectsForAdminUi({
ids: userProjectIds,
ids: [...new Set([...userProjectIds, ...userFavoritedProjectIds])],
archived: false,
});

Expand Down
3 changes: 3 additions & 0 deletions src/lib/features/project/fake-project-read-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ export class FakeProjectReadModel implements IProjectReadModel {
getProjectsByUser(): Promise<string[]> {
return Promise.resolve([]);
}
getProjectsFavoritedByUser(): Promise<string[]> {
return Promise.resolve([]);
}
}
1 change: 1 addition & 0 deletions src/lib/features/project/project-read-model-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export interface IProjectReadModel {
featureName: string,
): Promise<{ project: string; createdAt: Date } | null>;
getProjectsByUser(userId: number): Promise<string[]>;
getProjectsFavoritedByUser(userId: number): Promise<string[]>;
}
12 changes: 12 additions & 0 deletions src/lib/features/project/project-read-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,16 @@ export class ProjectReadModel implements IProjectReadModel {
.pluck('project');
return projects;
}

async getProjectsFavoritedByUser(userId: number): Promise<string[]> {
const favoritedProjects = await this.db
.select('favorite_projects.project')
.from('favorite_projects')
.leftJoin('projects', 'favorite_projects.project', 'projects.id')
.where('favorite_projects.user_id', userId)
.andWhere('projects.archived_at', null)
.pluck('project');

return favoritedProjects;
}
}
Loading