Skip to content

Commit

Permalink
Suggest change - update status and get per project (#2266)
Browse files Browse the repository at this point in the history
Set change status
  • Loading branch information
sjaanus committed Oct 27, 2022
1 parent 09bf93f commit 3daef1d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
21 changes: 17 additions & 4 deletions src/lib/db/suggest-change-store.ts
Expand Up @@ -7,6 +7,7 @@ import {
ISuggestChange,
ISuggestChangeset,
SuggestChangeAction,
SuggestChangesetState,
} from '../types/model';

const T = {
Expand Down Expand Up @@ -151,9 +152,11 @@ export class SuggestChangeStore implements ISuggestChangeStore {
};

getForProject = async (project: string): Promise<ISuggestChangeset[]> => {
const rows = await this.buildSuggestChangeSetChangesQuery().where({
project,
});
const rows = await this.buildSuggestChangeSetChangesQuery()
.where({
project,
})
.whereNot('state', SuggestChangesetState.DRAFT);
return this.mapRows(rows);
};

Expand All @@ -163,7 +166,7 @@ export class SuggestChangeStore implements ISuggestChangeStore {
): Promise<ISuggestChangeset[]> => {
const rows = await this.buildSuggestChangeSetChangesQuery().where({
'changeSet.created_by': userId,
state: 'Draft',
state: SuggestChangesetState.DRAFT,
project: project,
});
const changesets = this.mapRows(rows);
Expand Down Expand Up @@ -250,4 +253,14 @@ export class SuggestChangeStore implements ISuggestChangeStore {
};

destroy(): void {}

async updateState(
id: number,
state: SuggestChangesetState,
): Promise<ISuggestChangeset> {
await this.db(T.SUGGEST_CHANGE_SET)
.update('state', state)
.where({ id });
return this.get(id);
}
}
19 changes: 6 additions & 13 deletions src/lib/types/model.ts
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion 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<ISuggestChangeset, number> {
Expand All @@ -19,6 +23,11 @@ export interface ISuggestChangeStore extends Store<ISuggestChangeset, number> {

get(id: number): Promise<ISuggestChangeset>;

updateState(
id: number,
state: SuggestChangesetState,
): Promise<ISuggestChangeset>;

getAll(): Promise<ISuggestChangeset[]>;

getForProject(project: string): Promise<ISuggestChangeset[]>;
Expand Down
15 changes: 14 additions & 1 deletion 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 {
Expand Down Expand Up @@ -86,4 +90,13 @@ export default class FakeSuggestChangeStore implements ISuggestChangeStore {
exists(key: number): Promise<boolean> {
return Promise.resolve(Boolean(key));
}

updateState(
id: number,
state: SuggestChangesetState,
): Promise<ISuggestChangeset> {
const changeSet = this.suggestChanges.find((s) => s.id === id);
changeSet.state = state;
return Promise.resolve(undefined);
}
}

0 comments on commit 3daef1d

Please sign in to comment.