1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Suggest change - update status and get per project (#2266)

Set change status
This commit is contained in:
sjaanus 2022-10-27 09:53:47 +02:00 committed by GitHub
parent 09bf93f9dd
commit 3daef1d00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 19 deletions

View File

@ -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<ISuggestChangeset[]> => {
const rows = await this.buildSuggestChangeSetChangesQuery().where({
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<ISuggestChangeset[]> => {
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<ISuggestChangeset> {
await this.db(T.SUGGEST_CHANGE_SET)
.update('state', state)
.where({ id });
return this.get(id);
}
}

View File

@ -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;

View File

@ -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> {
@ -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[]>;

View File

@ -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<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);
}
}