From 3daef1d00c08b495090aada4d950af48fc8fdb70 Mon Sep 17 00:00:00 2001 From: sjaanus Date: Thu, 27 Oct 2022 09:53:47 +0200 Subject: [PATCH] Suggest change - update status and get per project (#2266) Set change status --- src/lib/db/suggest-change-store.ts | 21 +++++++++++++++---- src/lib/types/model.ts | 19 ++++++----------- src/lib/types/stores/suggest-change-store.ts | 11 +++++++++- .../fixtures/fake-suggest-change-store.ts | 15 ++++++++++++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/lib/db/suggest-change-store.ts b/src/lib/db/suggest-change-store.ts index 9cfe3d0689..4553ab2b49 100644 --- a/src/lib/db/suggest-change-store.ts +++ b/src/lib/db/suggest-change-store.ts @@ -7,6 +7,7 @@ import { ISuggestChange, ISuggestChangeset, SuggestChangeAction, + SuggestChangesetState, } from '../types/model'; const T = { @@ -151,9 +152,11 @@ export class SuggestChangeStore implements ISuggestChangeStore { }; getForProject = async (project: string): Promise => { - const rows = await this.buildSuggestChangeSetChangesQuery().where({ - project, - }); + const rows = await this.buildSuggestChangeSetChangesQuery() + .where({ + project, + }) + .whereNot('state', SuggestChangesetState.DRAFT); return this.mapRows(rows); }; @@ -163,7 +166,7 @@ export class SuggestChangeStore implements ISuggestChangeStore { ): Promise => { const rows = await this.buildSuggestChangeSetChangesQuery().where({ 'changeSet.created_by': userId, - state: 'Draft', + state: SuggestChangesetState.DRAFT, project: project, }); const changesets = this.mapRows(rows); @@ -250,4 +253,14 @@ export class SuggestChangeStore implements ISuggestChangeStore { }; destroy(): void {} + + async updateState( + id: number, + state: SuggestChangesetState, + ): Promise { + await this.db(T.SUGGEST_CHANGE_SET) + .update('state', state) + .where({ id }); + return this.get(id); + } } diff --git a/src/lib/types/model.ts b/src/lib/types/model.ts index a3479c516f..606685f51c 100644 --- a/src/lib/types/model.ts +++ b/src/lib/types/model.ts @@ -385,13 +385,12 @@ export interface ISuggestChange { createdAt?: Date; } -export enum SuggestChangesetEvent { - CREATED = 'CREATED', - UPDATED = 'UPDATED', - SUBMITTED = 'SUBMITTED', - APPROVED = 'APPROVED', - REJECTED = 'REJECTED', - CLOSED = 'CLOSED', +export enum SuggestChangesetState { + DRAFT = 'Draft', + APPROVED = 'Approved', + IN_REVIEW = 'In review', + APPLIED = 'Applied', + CANCELLED = 'Cancelled', } export enum SuggestChangeAction { @@ -401,12 +400,6 @@ export enum SuggestChangeAction { DELETE_STRATEGY = 'strategyDelete', } -export enum SuggestChangeEvent { - UPDATE_ENABLED = 'updateFeatureEnabledEvent', - ADD_STRATEGY = 'addStrategyEvent', - UPDATE_STRATEGY = 'updateStrategyEvent', - DELETE_STRATEGY = 'deleteStrategyEvent', -} export interface ISuggestChangeEventData { feature: string; data: unknown; diff --git a/src/lib/types/stores/suggest-change-store.ts b/src/lib/types/stores/suggest-change-store.ts index 21ce66c5db..025bfa131c 100644 --- a/src/lib/types/stores/suggest-change-store.ts +++ b/src/lib/types/stores/suggest-change-store.ts @@ -1,5 +1,9 @@ import { Store } from './store'; -import { ISuggestChange, ISuggestChangeset } from '../model'; +import { + ISuggestChange, + ISuggestChangeset, + SuggestChangesetState, +} from '../model'; import { PartialSome } from '../partial'; export interface ISuggestChangeStore extends Store { @@ -19,6 +23,11 @@ export interface ISuggestChangeStore extends Store { get(id: number): Promise; + updateState( + id: number, + state: SuggestChangesetState, + ): Promise; + getAll(): Promise; getForProject(project: string): Promise; diff --git a/src/test/fixtures/fake-suggest-change-store.ts b/src/test/fixtures/fake-suggest-change-store.ts index 3d9f31d413..8a348dddbe 100644 --- a/src/test/fixtures/fake-suggest-change-store.ts +++ b/src/test/fixtures/fake-suggest-change-store.ts @@ -1,5 +1,9 @@ import { ISuggestChangeStore } from '../../lib/types/stores/suggest-change-store'; -import { ISuggestChange, ISuggestChangeset } from '../../lib/types/model'; +import { + ISuggestChange, + ISuggestChangeset, + SuggestChangesetState, +} from '../../lib/types/model'; import { PartialSome } from '../../lib/types/partial'; export default class FakeSuggestChangeStore implements ISuggestChangeStore { @@ -86,4 +90,13 @@ export default class FakeSuggestChangeStore implements ISuggestChangeStore { exists(key: number): Promise { return Promise.resolve(Boolean(key)); } + + updateState( + id: number, + state: SuggestChangesetState, + ): Promise { + const changeSet = this.suggestChanges.find((s) => s.id === id); + changeSet.state = state; + return Promise.resolve(undefined); + } }