mirror of
https://github.com/hexastack/hexabot
synced 2025-04-16 21:56:00 +00:00
feat(api): rename events
This commit is contained in:
parent
3c8deb854e
commit
14df503041
@ -835,7 +835,7 @@ export default class OfflineHandler extends ChannelHandler {
|
||||
|
||||
const type = event.getEventType();
|
||||
if (type) {
|
||||
this.eventEmitter.emit('hook:chatbot:' + type, event);
|
||||
this.eventEmitter.emit(`hook:chatbot:${type}`, event);
|
||||
} else {
|
||||
this.logger.error(
|
||||
'Offline Channel Handler : Webhook received unknown event ',
|
||||
|
@ -50,7 +50,7 @@ export class NlpEntityRepository extends BaseRepository<
|
||||
): Promise<void> {
|
||||
if (!_created.builtin) {
|
||||
// Bypass builtin entities (probably fixtures)
|
||||
this.eventEmitter.emit('hook:nlp:entity:create', _created);
|
||||
this.eventEmitter.emit('hook:nlpEntity:create', _created);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ export class NlpEntityRepository extends BaseRepository<
|
||||
): Promise<void> {
|
||||
if (!updated?.builtin) {
|
||||
// Bypass builtin entities (probably fixtures)
|
||||
this.eventEmitter.emit('hook:nlp:entity:update', updated);
|
||||
this.eventEmitter.emit('hook:nlpEntity:update', updated);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ export class NlpEntityRepository extends BaseRepository<
|
||||
entities
|
||||
.filter((e) => !e.builtin)
|
||||
.map((e) => {
|
||||
this.eventEmitter.emit('hook:nlp:entity:delete', e);
|
||||
this.eventEmitter.emit('hook:nlpEntity:delete', e);
|
||||
});
|
||||
} else {
|
||||
throw new Error('Attempted to delete NLP entity using unknown criteria');
|
||||
|
@ -17,7 +17,6 @@ import { NlpSampleEntityRepository } from './nlp-sample-entity.repository';
|
||||
import {
|
||||
NLP_VALUE_POPULATE,
|
||||
NlpValue,
|
||||
NlpValueDocument,
|
||||
NlpValueFull,
|
||||
NlpValuePopulate,
|
||||
} from '../schemas/nlp-value.schema';
|
||||
@ -41,10 +40,10 @@ export class NlpValueRepository extends BaseRepository<
|
||||
*
|
||||
* @param created - The newly created NLP value document.
|
||||
*/
|
||||
async postCreate(created: NlpValueDocument): Promise<void> {
|
||||
async postCreate(created: NlpValue): Promise<void> {
|
||||
if (!created.builtin) {
|
||||
// Bypass builtin entities (probably fixtures)
|
||||
this.eventEmitter.emit('hook:nlp:value:create', created);
|
||||
this.eventEmitter.emit('hook:nlpValue:create', created);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +65,7 @@ export class NlpValueRepository extends BaseRepository<
|
||||
): Promise<void> {
|
||||
if (!updated?.builtin) {
|
||||
// Bypass builtin entities (probably fixtures)
|
||||
this.eventEmitter.emit('hook:nlp:value:update', updated);
|
||||
this.eventEmitter.emit('hook:nlpValue:update', updated);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +95,7 @@ export class NlpValueRepository extends BaseRepository<
|
||||
entities
|
||||
.filter((e) => !e.builtin)
|
||||
.map((e) => {
|
||||
this.eventEmitter.emit('hook:nlp:value:delete', e);
|
||||
this.eventEmitter.emit('hook:nlpValue:delete', e);
|
||||
});
|
||||
} else if (criteria.entity) {
|
||||
// Do nothing : cascading deletes coming from Nlp Sample Entity
|
||||
|
@ -100,7 +100,7 @@ export class NlpService {
|
||||
/**
|
||||
* Handles the event triggered when NLP settings are updated. Re-initializes the NLP service.
|
||||
*/
|
||||
@OnEvent('hook:settings:nlp_settings:*')
|
||||
@OnEvent('hook:nlp:settings')
|
||||
async handleSettingsUpdate() {
|
||||
this.initNLP();
|
||||
}
|
||||
@ -111,7 +111,7 @@ export class NlpService {
|
||||
* @param entity - The NLP entity to be created.
|
||||
* @returns The updated entity after synchronization.
|
||||
*/
|
||||
@OnEvent('hook:nlp:entity:create')
|
||||
@OnEvent('hook:nlpEntity:create')
|
||||
async handleEntityCreate(entity: NlpEntity) {
|
||||
// Synchonize new entity with NLP
|
||||
try {
|
||||
@ -131,7 +131,7 @@ export class NlpService {
|
||||
*
|
||||
* @param entity - The NLP entity to be updated.
|
||||
*/
|
||||
@OnEvent('hook:nlp:entity:update')
|
||||
@OnEvent('hook:nlpEntity:update')
|
||||
async handleEntityUpdate(entity: NlpEntity) {
|
||||
// Synchonize new entity with NLP provider
|
||||
try {
|
||||
@ -147,7 +147,7 @@ export class NlpService {
|
||||
*
|
||||
* @param entity - The NLP entity to be deleted.
|
||||
*/
|
||||
@OnEvent('hook:nlp:entity:delete')
|
||||
@OnEvent('hook:nlpEntity:delete')
|
||||
async handleEntityDelete(entity: NlpEntity) {
|
||||
// Synchonize new entity with NLP provider
|
||||
try {
|
||||
@ -165,7 +165,7 @@ export class NlpService {
|
||||
*
|
||||
* @returns The updated value after synchronization.
|
||||
*/
|
||||
@OnEvent('hook:nlp:value:create')
|
||||
@OnEvent('hook:nlpValue:create')
|
||||
async handleValueCreate(value: NlpValue) {
|
||||
// Synchonize new value with NLP provider
|
||||
try {
|
||||
@ -185,7 +185,7 @@ export class NlpService {
|
||||
*
|
||||
* @param value - The NLP value to be updated.
|
||||
*/
|
||||
@OnEvent('hook:nlp:value:update')
|
||||
@OnEvent('hook:nlpValue:update')
|
||||
async handleValueUpdate(value: NlpValue) {
|
||||
// Synchonize new value with NLP provider
|
||||
try {
|
||||
@ -201,7 +201,7 @@ export class NlpService {
|
||||
*
|
||||
* @param value - The NLP value to be deleted.
|
||||
*/
|
||||
@OnEvent('hook:nlp:value:delete')
|
||||
@OnEvent('hook:nlpValue:delete')
|
||||
async handleValueDelete(value: NlpValue) {
|
||||
// Synchonize new value with NLP provider
|
||||
try {
|
||||
|
@ -9,7 +9,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Document, Model, Query, Types } from 'mongoose';
|
||||
import { Document, Model, Types } from 'mongoose';
|
||||
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||
@ -58,30 +58,4 @@ 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,
|
||||
) {
|
||||
// Sync global settings var
|
||||
this.eventEmitter.emit(
|
||||
'hook:settings:' + setting.group + ':' + setting.label,
|
||||
setting,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -107,10 +107,10 @@ export class SettingService extends BaseService<Setting> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler for setting updates. Listens to 'hook:settings:*:*' events
|
||||
* Event handler for setting updates. Listens to 'hook:setting:*' events
|
||||
* and invalidates the cache for settings when triggered.
|
||||
*/
|
||||
@OnEvent('hook:settings:*:*')
|
||||
@OnEvent('hook:setting:*')
|
||||
async handleSettingUpdateEvent() {
|
||||
this.cacheManager.del(SETTING_CACHE_KEY);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user