From b042afb7dd3fdd33b57d5cc4991694430f9721dd Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 14 Aug 2024 11:01:17 +0200 Subject: [PATCH] feat: archived projects query improved (#7866) --- src/lib/features/project/project-service.e2e.test.ts | 7 +++++++ src/lib/features/project/project-store.ts | 9 +++++++-- src/lib/openapi/spec/project-schema.ts | 6 ++++++ src/lib/types/model.ts | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/lib/features/project/project-service.e2e.test.ts b/src/lib/features/project/project-service.e2e.test.ts index 723f4dd83a..6c69cfad12 100644 --- a/src/lib/features/project/project-service.e2e.test.ts +++ b/src/lib/features/project/project-service.e2e.test.ts @@ -306,6 +306,13 @@ test('should archive project', async () => { const projects = await projectService.getProjects(); expect(projects.find((p) => p.id === project.id)).toBeUndefined(); expect(projects.length).not.toBe(0); + + const archivedProjects = await projectService.getProjects({ + archived: true, + }); + expect(archivedProjects).toMatchObject([ + { id: 'test-archive', archivedAt: expect.any(Date) }, + ]); }); test('should revive project', async () => { diff --git a/src/lib/features/project/project-store.ts b/src/lib/features/project/project-store.ts index 5380d98e32..cbe28be6ac 100644 --- a/src/lib/features/project/project-store.ts +++ b/src/lib/features/project/project-store.ts @@ -140,8 +140,8 @@ class ProjectStore implements IProjectStore { } } - if (query) { - projects = projects.where(query); + if (query?.id) { + projects = projects.where(`${TABLE}.id`, query.id); } let selectColumns = [ @@ -156,6 +156,10 @@ class ProjectStore implements IProjectStore { 'project_stats.avg_time_to_prod_current_window', ] as (string | Raw)[]; + if (this.flagResolver.isEnabled('archiveProjects')) { + selectColumns.push(`${TABLE}.archived_at`); + } + let groupByColumns = [ 'projects.id', 'project_settings.default_stickiness', @@ -219,6 +223,7 @@ class ProjectStore implements IProjectStore { memberCount: Number(row.number_of_users) || 0, updatedAt: row.updated_at, createdAt: row.created_at, + archivedAt: row.archived_at, mode: row.project_mode || 'open', defaultStickiness: row.default_stickiness || 'default', avgTimeToProduction: row.avg_time_to_prod_current_window || 0, diff --git a/src/lib/openapi/spec/project-schema.ts b/src/lib/openapi/spec/project-schema.ts index 96ca1b3c35..49d053b77b 100644 --- a/src/lib/openapi/spec/project-schema.ts +++ b/src/lib/openapi/spec/project-schema.ts @@ -64,6 +64,12 @@ export const projectSchema = { description: 'When this project was last updated.', example: '2023-07-28T12:12:28Z', }, + archivedAt: { + type: 'string', + format: 'date-time', + description: 'When this project was archived.', + example: '2023-07-28T12:12:28Z', + }, favorite: { type: 'boolean', example: true, diff --git a/src/lib/types/model.ts b/src/lib/types/model.ts index fa11ff4c24..4899a80394 100644 --- a/src/lib/types/model.ts +++ b/src/lib/types/model.ts @@ -573,6 +573,7 @@ export interface IProjectWithCount extends IProject { memberCount: number; favorite?: boolean; avgTimeToProduction: number; + archivedAt?: Date; } export interface IClientSegment {