Skip to content

Commit

Permalink
feat: personal dashboard project details API stub (#8282)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Sep 26, 2024
1 parent d161fb4 commit 4107e84
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,15 @@ test('should return projects where users are part of a group', async () => {
],
});
});

test('should return personal dashboard project details', async () => {
await loginUser('[email protected]');
const { body } = await app.request.get(
`/api/admin/personal-dashboard/default`,
);

expect(body).toMatchObject({
owners: [{}],
roles: [{}],
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Controller from '../../routes/controller';
import type { Response } from 'express';
import type { IAuthRequest } from '../../routes/unleash-types';
import type { PersonalDashboardService } from './personal-dashboard-service';

const PATH = '';
import {
personalDashboardProjectDetailsSchema,
type PersonalDashboardProjectDetailsSchema,
} from '../../openapi/spec/personal-dashboard-project-details-schema';

export default class PersonalDashboardController extends Controller {
private openApiService: OpenApiService;
Expand All @@ -34,7 +36,7 @@ export default class PersonalDashboardController extends Controller {

this.route({
method: 'get',
path: PATH,
path: '',
handler: this.getPersonalDashboard,
permission: NONE,
middleware: [
Expand All @@ -51,6 +53,28 @@ export default class PersonalDashboardController extends Controller {
}),
],
});

this.route({
method: 'get',
path: '/:projectId',
handler: this.getPersonalDashboardProjectDetails,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Unstable'],
summary: 'Get personal project details',
description:
'Return personal dashboard project events, owners, user roles and onboarding status',
operationId: 'getPersonalDashboardProjectDetails',
responses: {
200: createResponseSchema(
'personalDashboardProjectDetailsSchema',
),
...getStandardResponses(401, 403, 404),
},
}),
],
});
}

async getPersonalDashboard(
Expand All @@ -73,4 +97,21 @@ export default class PersonalDashboardController extends Controller {
{ projects, flags },
);
}

async getPersonalDashboardProjectDetails(
req: IAuthRequest<{ projectId: string }>,
res: Response<PersonalDashboardProjectDetailsSchema>,
): Promise<void> {
const user = req.user;

this.openApiService.respondWithValidation(
200,
res,
personalDashboardProjectDetailsSchema.$id,
{
owners: [{ ownerType: 'user', name: 'placeholder' }],
roles: [{ name: 'placeholder', id: 0, type: 'project' }],
},
);
}
}
1 change: 1 addition & 0 deletions src/lib/openapi/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export * from './patch-schema';
export * from './patches-schema';
export * from './pats-schema';
export * from './permission-schema';
export * from './personal-dashboard-project-details-schema';
export * from './personal-dashboard-schema';
export * from './playground-constraint-schema';
export * from './playground-feature-schema';
Expand Down
49 changes: 49 additions & 0 deletions src/lib/openapi/spec/personal-dashboard-project-details-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { FromSchema } from 'json-schema-to-ts';
import { projectSchema } from './project-schema';

export const personalDashboardProjectDetailsSchema = {
$id: '#/components/schemas/personalDashboardProjectDetailsSchema',
type: 'object',
description: 'Project details in personal dashboard',
additionalProperties: false,
required: ['owners', 'roles'],
properties: {
owners: projectSchema.properties.owners,
roles: {
type: 'array',
description: 'The list of roles that the user has in this project.',
minItems: 1,
items: {
type: 'object',
description: 'An Unleash role.',
additionalProperties: false,
required: ['name', 'id', 'type'],
properties: {
name: {
type: 'string',
example: 'Owner',
description: 'The name of the role',
},
id: {
type: 'integer',
example: 4,
description: 'The id of the role',
},
type: {
type: 'string',
enum: ['custom', 'project', 'root', 'custom-root'],
example: 'project',
description: 'The type of the role',
},
},
},
},
},
components: {
schemas: {},
},
} as const;

export type PersonalDashboardProjectDetailsSchema = FromSchema<
typeof personalDashboardProjectDetailsSchema
>;
37 changes: 0 additions & 37 deletions src/lib/openapi/spec/personal-dashboard-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { FromSchema } from 'json-schema-to-ts';
import { projectSchema } from './project-schema';

export const personalDashboardSchema = {
$id: '#/components/schemas/personalDashboardSchema',
Expand Down Expand Up @@ -47,42 +46,6 @@ export const personalDashboardSchema = {
example: 10,
description: 'The number of features this project has',
},
owners: projectSchema.properties.owners,
roles: {
type: 'array',
description:
'The list of roles that the user has in this project.',
minItems: 1,
items: {
type: 'object',
description: 'An Unleash role.',
additionalProperties: false,
required: ['name', 'id', 'type'],
properties: {
name: {
type: 'string',
example: 'Owner',
description: 'The name of the role',
},
id: {
type: 'integer',
example: 4,
description: 'The id of the role',
},
type: {
type: 'string',
enum: [
'custom',
'project',
'root',
'custom-root',
],
example: 'project',
description: 'The type of the role',
},
},
},
},
},
},
description:
Expand Down

0 comments on commit 4107e84

Please sign in to comment.