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:
parent
09bf93f9dd
commit
3daef1d00c
@ -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({
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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[]>;
|
||||
|
15
src/test/fixtures/fake-suggest-change-store.ts
vendored
15
src/test/fixtures/fake-suggest-change-store.ts
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user