mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
Make domain type and schema match
This commit is contained in:
parent
922ec7126f
commit
079f46c0db
@ -15,29 +15,29 @@ const T = {
|
|||||||
SUGGEST_CHANGE_SET: 'suggest_change_set',
|
SUGGEST_CHANGE_SET: 'suggest_change_set',
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ISuggestChangesetInsert {
|
interface ISuggestChangesetRow {
|
||||||
id: number;
|
id: number;
|
||||||
|
state: SuggestChangesetState;
|
||||||
environment: string;
|
environment: string;
|
||||||
state?: string;
|
project: string;
|
||||||
project?: string;
|
created_at: Date;
|
||||||
created_by?: number;
|
created_by: number;
|
||||||
created_at?: Date;
|
changeSetUsername: string;
|
||||||
|
changeSetAvatar: string;
|
||||||
|
changeId: number;
|
||||||
|
changeFeature: string;
|
||||||
|
changeAction: SuggestChangeAction;
|
||||||
|
changePayload: any;
|
||||||
|
changeCreatedAt: Date;
|
||||||
|
changeCreatedBy: number;
|
||||||
|
changeCreatedByUsername: string;
|
||||||
|
changeCreatedByAvatar: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISuggestChangeInsert {
|
const suggestChangeRowReducer = (
|
||||||
id: number;
|
acc: Record<number, ISuggestChangeset>,
|
||||||
action: SuggestChangeAction;
|
suggestChangeRow: ISuggestChangesetRow,
|
||||||
feature: string;
|
): Record<number, ISuggestChangeset> => {
|
||||||
payload?: unknown;
|
|
||||||
created_by?: number;
|
|
||||||
created_at?: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ISuggestChangesetRow extends ISuggestChangesetInsert {
|
|
||||||
changes?: ISuggestChange[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const suggestChangeRowReducer = (acc, suggestChangeRow) => {
|
|
||||||
const {
|
const {
|
||||||
changeId,
|
changeId,
|
||||||
changeAction,
|
changeAction,
|
||||||
@ -199,7 +199,7 @@ export class SuggestChangeStore implements ISuggestChangeStore {
|
|||||||
userId: number,
|
userId: number,
|
||||||
): Promise<ISuggestChangeset> => {
|
): Promise<ISuggestChangeset> => {
|
||||||
const [{ id }] = await this.db(T.SUGGEST_CHANGE_SET)
|
const [{ id }] = await this.db(T.SUGGEST_CHANGE_SET)
|
||||||
.insert<ISuggestChangesetInsert>({
|
.insert({
|
||||||
environment: suggestChangeSet.environment,
|
environment: suggestChangeSet.environment,
|
||||||
state: suggestChangeSet.state,
|
state: suggestChangeSet.state,
|
||||||
project: suggestChangeSet.project,
|
project: suggestChangeSet.project,
|
||||||
@ -207,22 +207,25 @@ export class SuggestChangeStore implements ISuggestChangeStore {
|
|||||||
})
|
})
|
||||||
.returning('id');
|
.returning('id');
|
||||||
|
|
||||||
suggestChangeSet.changes.forEach((change) => {
|
suggestChangeSet.features.forEach((feature) => {
|
||||||
this.addChangeToSet(change, id, userId);
|
feature.changes.forEach((change) => {
|
||||||
|
this.addChangeToSet(change, feature.name, id, userId);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.get(id);
|
return this.get(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
addChangeToSet = async (
|
addChangeToSet = async (
|
||||||
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
|
change: ISuggestChange,
|
||||||
|
feature: string,
|
||||||
changeSetID: number,
|
changeSetID: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
await this.db(T.SUGGEST_CHANGE)
|
await this.db(T.SUGGEST_CHANGE)
|
||||||
.insert<ISuggestChangeInsert>({
|
.insert({
|
||||||
action: change.action,
|
action: change.action,
|
||||||
feature: change.feature,
|
feature: feature,
|
||||||
payload: change.payload,
|
payload: change.payload,
|
||||||
suggest_change_set_id: changeSetID,
|
suggest_change_set_id: changeSetID,
|
||||||
created_by: userId,
|
created_by: userId,
|
||||||
@ -247,8 +250,10 @@ export class SuggestChangeStore implements ISuggestChangeStore {
|
|||||||
return result.rows[0].present;
|
return result.rows[0].present;
|
||||||
};
|
};
|
||||||
|
|
||||||
mapRows = (rows?: any[]): ISuggestChangeset[] => {
|
mapRows = (rows?: ISuggestChangesetRow[]): ISuggestChangeset[] => {
|
||||||
const suggestChangeSets = rows.reduce(suggestChangeRowReducer, {});
|
const suggestChangeSets = rows.reduce<
|
||||||
|
Record<number, ISuggestChangeset>
|
||||||
|
>(suggestChangeRowReducer, {});
|
||||||
return Object.values(suggestChangeSets);
|
return Object.values(suggestChangeSets);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -373,13 +373,17 @@ export interface ISuggestChangeset {
|
|||||||
environment: string;
|
environment: string;
|
||||||
createdBy: Pick<User, 'id' | 'username' | 'imageUrl'>;
|
createdBy: Pick<User, 'id' | 'username' | 'imageUrl'>;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
features: ISuggestChangeFeature[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISuggestChangeFeature {
|
||||||
|
name: string;
|
||||||
changes: ISuggestChange[];
|
changes: ISuggestChange[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISuggestChange {
|
export interface ISuggestChange {
|
||||||
id?: number;
|
id?: number;
|
||||||
action: SuggestChangeAction;
|
action: SuggestChangeAction;
|
||||||
feature: string;
|
|
||||||
payload: any;
|
payload: any;
|
||||||
createdBy?: Pick<User, 'id' | 'username' | 'imageUrl'>;
|
createdBy?: Pick<User, 'id' | 'username' | 'imageUrl'>;
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
|
@ -17,6 +17,7 @@ export interface ISuggestChangeStore extends Store<ISuggestChangeset, number> {
|
|||||||
|
|
||||||
addChangeToSet(
|
addChangeToSet(
|
||||||
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
|
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
|
||||||
|
feature: string,
|
||||||
changeSetID: number,
|
changeSetID: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
12
src/test/fixtures/fake-suggest-change-store.ts
vendored
12
src/test/fixtures/fake-suggest-change-store.ts
vendored
@ -25,13 +25,19 @@ export default class FakeSuggestChangeStore implements ISuggestChangeStore {
|
|||||||
|
|
||||||
addChangeToSet(
|
addChangeToSet(
|
||||||
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
|
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
|
||||||
|
feature: string,
|
||||||
changeSetID: number,
|
changeSetID: number,
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const changeSet = this.suggestChanges.find((s) => s.id === changeSetID);
|
const changeSet = this.suggestChanges.find((s) => s.id === changeSetID);
|
||||||
changeSet.changes.push({
|
changeSet.features.push({
|
||||||
createdBy: { id: userId, username: '', imageUrl: '' },
|
name: feature,
|
||||||
...change,
|
changes: [
|
||||||
|
{
|
||||||
|
createdBy: { id: userId, username: '', imageUrl: '' },
|
||||||
|
...change,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user