1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-18 13:48:58 +02:00

fix: settings change events now use preData and publish the change, not just the id

This commit is contained in:
sighphyre 2023-11-27 16:00:09 +02:00
parent 713d69fc7a
commit 82c34f44b2
No known key found for this signature in database
GPG Key ID: 272209E090ED6733
2 changed files with 17 additions and 8 deletions

View File

@ -43,21 +43,24 @@ export default class SettingService {
}
async insert(id: string, value: object, createdBy: string): Promise<void> {
const exists = await this.settingStore.exists(id);
if (exists) {
const existingSettings = await this.settingStore.get<object>(id);
if (existingSettings) {
await this.settingStore.updateRow(id, value);
await this.eventService.storeEvent(
new SettingUpdatedEvent({
createdBy,
data: { id },
}),
new SettingUpdatedEvent(
{
createdBy,
data: value,
},
existingSettings,
),
);
} else {
await this.settingStore.insert(id, value);
await this.eventService.storeEvent(
new SettingCreatedEvent({
createdBy,
data: { id },
data: value,
}),
);
}

View File

@ -973,12 +973,18 @@ export class SettingDeletedEvent extends BaseEvent {
export class SettingUpdatedEvent extends BaseEvent {
readonly data: any;
readonly preData: any;
/**
* @param createdBy accepts a string for backward compatibility. Prefer using IUser for standardization
*/
constructor(eventData: { createdBy: string | IUser; data: any }) {
constructor(
eventData: { createdBy: string | IUser; data: any },
preData: any,
) {
super(SETTING_UPDATED, eventData.createdBy);
this.data = eventData.data;
this.preData = preData;
}
}