Skip to content

Commit

Permalink
feat: return projects
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Sep 24, 2024
1 parent 6feb281 commit 2a754ae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,42 @@ test('should return personal dashboard with membered projects', async () => {
user1,
);

// Add user 1 as an owner of project C
await app.services.projectService.addAccess(
projectC.id,
[4],
[],
[user1.id],
user2,
);

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

expect(body).toMatchObject({
projects: [
{
name: 'Default',
id: 'default',
roles: [
{
name: 'Editor',
id: 2,
type: 'root',
},
],
},
{
name: projectA.name,
id: projectA.id,
owners: [{ id: user1.id, name: user1.email, imageUrl: '' }],
roles: ['member'],
roles: [
{
name: 'Member',
id: 5,
type: 'project',
},
],
},
{
name: projectC.name,
id: projectC.id,
owners: [
{ id: user2.id, name: user2.email, imageUrl: '' },
{ id: user1.id, name: user1.email, imageUrl: '' },
roles: [
{
name: 'Owner',
id: 4,
type: 'project',
},
],
roles: ['owner'],
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ export type PersonalFeature = { name: string; type: string; project: string };
export type PersonalProject = {
name: string;
id: string;
roles: { name: string; id: number; type: 'custom' | 'project' }[];
roles: {
name: string;
id: number;
type: 'custom' | 'project' | 'root' | 'custom-root';
}[];
};

export interface IPersonalDashboardReadModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ export class PersonalDashboardReadModel implements IPersonalDashboardReadModel {
.join('role_user', 'projects.id', 'role_user.project')
.join('roles', 'role_user.role_id', 'roles.id')
.where('role_user.user_id', userId)
.whereNull('project.archived_at')
.whereNull('projects.archived_at')
.select(
'projects.name',
'projects.id',
'roles.id as roleId',
'roles.name as roleName',
'roles.type as roleType',
)
.orderBy('projects.name', 'desc')
.limit(100);

console.log(result);

return result.reduce((acc, row) => {
const dict = result.reduce((acc, row) => {
if (acc[row.id]) {
acc[row.id].roles.push({
id: row.roleId,
Expand All @@ -58,6 +55,10 @@ export class PersonalDashboardReadModel implements IPersonalDashboardReadModel {
}
return acc;
}, {});

const projectList: PersonalProject[] = Object.values(dict);
projectList.sort((a, b) => a.name.localeCompare(b.name));
return projectList;
}

async getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/openapi/spec/personal-dashboard-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export const personalDashboardSchema = {
},
type: {
type: 'string',
enum: ['custom', 'project'],
enum: [
'custom',
'project',
'root',
'custom-root',
],
example: 'project',
description: 'The type of the role',
},
Expand Down

0 comments on commit 2a754ae

Please sign in to comment.