fix(api): revert settings

This commit is contained in:
yassinedorbozgithub 2024-10-09 08:25:49 +01:00
parent 0018c681f3
commit 560d922437

View File

@ -9,7 +9,7 @@
import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { InjectModel } from '@nestjs/mongoose';
import { Document, Model, Types } from 'mongoose';
import { Document, Model, Query, Types } from 'mongoose';
import { I18nService } from '@/i18n/services/i18n.service';
import { BaseRepository } from '@/utils/generics/base-repository';
@ -58,4 +58,29 @@ export class SettingRepository extends BaseRepository<Setting> {
throw new Error('Setting Model : Value must be a boolean!');
}
}
/**
* Emits an event after a `Setting` has been updated.
*
* This method is used to synchronize global settings by emitting an event
* based on the `group` and `label` of the `Setting`.
*
* @param _query The Mongoose query object used to find and update the document.
* @param setting The updated `Setting` object.
*/
async postUpdate(
_query: Query<
Document<Setting, any, any>,
Document<Setting, any, any>,
unknown,
Setting,
'findOneAndUpdate'
>,
setting: Setting,
) {
const group = setting.group as any;
const label = setting.label as string;
// Sync global settings var
this.eventEmitter.emit(`hook:${group}:${label}`, setting as any);
}
}