Skip to content

Commit

Permalink
fix: add createdAt in projects API response (#3929)
Browse files Browse the repository at this point in the history
This PR adds the "createdAt" field to the /api/projects response, so
that we are compliant with the schema.
  • Loading branch information
ivarconr committed Jun 9, 2023
1 parent 27093de commit 1bc130b
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/db/project-store.ts
Expand Up @@ -107,7 +107,7 @@ class ProjectStore implements IProjectStore {
}
let selectColumns = [
this.db.raw(
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features',
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, projects.created_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features',
),
] as (string | Raw<any>)[];

Expand Down Expand Up @@ -164,6 +164,7 @@ class ProjectStore implements IProjectStore {
featureCount: Number(row.number_of_features) || 0,
memberCount: Number(row.number_of_users) || 0,
updatedAt: row.updated_at,
createdAt: row.created_at,
mode: 'open',
defaultStickiness: 'default',
};
Expand Down
7 changes: 7 additions & 0 deletions src/lib/openapi/spec/health-overview-schema.ts
Expand Up @@ -91,6 +91,13 @@ export const healthOverviewSchema = {
description: 'When the project was last updated.',
example: '2023-04-19T08:15:14.000Z',
},
createdAt: {
type: 'string',
format: 'date-time',
nullable: true,
description: 'When the project was last updated.',
example: '2023-04-19T08:15:14.000Z',
},
favorite: {
type: 'boolean',
description:
Expand Down
6 changes: 6 additions & 0 deletions src/lib/openapi/spec/project-overview-schema.ts
Expand Up @@ -98,6 +98,12 @@ export const projectOverviewSchema = {
nullable: true,
example: '2023-02-10T08:36:35.262Z',
},
createdAt: {
type: 'string',
format: 'date-time',
nullable: true,
example: '2023-02-10T08:36:35.262Z',
},
favorite: {
type: 'boolean',
example: true,
Expand Down
1 change: 1 addition & 0 deletions src/lib/services/project-service.ts
Expand Up @@ -840,6 +840,7 @@ export default class ProjectService {
health: project.health || 0,
favorite: favorite,
updatedAt: project.updatedAt,
createdAt: project.createdAt,
environments,
features,
members,
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/model.ts
Expand Up @@ -193,6 +193,7 @@ export interface IProjectOverview {
health: number;
favorite?: boolean;
updatedAt?: Date;
createdAt: Date | undefined;
stats?: IProjectStats;
mode: ProjectMode;

Expand Down
16 changes: 16 additions & 0 deletions src/test/e2e/api/admin/project/projects.e2e.test.ts
Expand Up @@ -42,3 +42,19 @@ test('Should ONLY return default project', async () => {
expect(body.projects).toHaveLength(1);
expect(body.projects[0].id).toBe('default');
});

test('response should include created_at', async () => {
const { body } = await app.request
.get('/api/admin/projects')
.expect('Content-Type', /json/)
.expect(200);
expect(body.projects[0].createdAt).toBeDefined();
});

test('response for default project should include created_at', async () => {
const { body } = await app.request
.get('/api/admin/projects/default')
.expect('Content-Type', /json/)
.expect(200);
expect(body.createdAt).toBeDefined();
});
20 changes: 20 additions & 0 deletions src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap
Expand Up @@ -2758,6 +2758,13 @@ The provider you choose for your addon dictates what properties the \`parameters
"additionalProperties": false,
"description": "An overview of a project's stats and its health as described in the documentation on [technical debt](https://docs.getunleash.io/reference/technical-debt)",
"properties": {
"createdAt": {
"description": "When the project was last updated.",
"example": "2023-04-19T08:15:14.000Z",
"format": "date-time",
"nullable": true,
"type": "string",
},
"defaultStickiness": {
"description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy",
"example": "userId",
Expand Down Expand Up @@ -2851,6 +2858,13 @@ The provider you choose for your addon dictates what properties the \`parameters
"example": 2,
"type": "number",
},
"createdAt": {
"description": "When the project was last updated.",
"example": "2023-04-19T08:15:14.000Z",
"format": "date-time",
"nullable": true,
"type": "string",
},
"defaultStickiness": {
"description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy",
"example": "userId",
Expand Down Expand Up @@ -3780,6 +3794,12 @@ The provider you choose for your addon dictates what properties the \`parameters
"additionalProperties": false,
"description": "A high-level overview of a project. It contains information such as project statistics, the name of the project, what members and what features it contains, etc.",
"properties": {
"createdAt": {
"example": "2023-02-10T08:36:35.262Z",
"format": "date-time",
"nullable": true,
"type": "string",
},
"defaultStickiness": {
"description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy",
"example": "userId",
Expand Down

0 comments on commit 1bc130b

Please sign in to comment.