From b94c0eb9a5aa82ff0e333038afa1ed97ca815a51 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Wed, 2 Oct 2024 06:39:03 +0100 Subject: [PATCH] fix: event consistent naming --- api/src/chat/repositories/label.repository.ts | 4 ++-- api/src/chat/repositories/subscriber.repository.ts | 12 ++++++------ api/src/chat/schemas/subscriber.schema.ts | 2 +- api/src/chat/schemas/types/subscriberContext.ts | 2 +- api/src/chat/services/block.service.ts | 2 +- api/src/chat/services/chat.service.ts | 4 ++-- api/src/cms/schemas/types/menu.ts | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api/src/chat/repositories/label.repository.ts b/api/src/chat/repositories/label.repository.ts index b698c0e..ede9f4f 100644 --- a/api/src/chat/repositories/label.repository.ts +++ b/api/src/chat/repositories/label.repository.ts @@ -43,7 +43,7 @@ export class LabelRepository extends BaseRepository< */ async postCreate(created: LabelDocument): Promise { this.eventEmitter.emit( - 'hook:chatbot:label:create', + 'hook:label:create', created, async (result: Record) => { await this.model.updateOne( @@ -82,6 +82,6 @@ export class LabelRepository extends BaseRepository< const labels = await this.find( typeof _criteria === 'string' ? { _id: _criteria } : _criteria, ); - this.eventEmitter.emit('hook:chatbot:label:delete', labels); + this.eventEmitter.emit('hook:label:delete', labels); } } diff --git a/api/src/chat/repositories/subscriber.repository.ts b/api/src/chat/repositories/subscriber.repository.ts index bc7fa48..ce9160a 100644 --- a/api/src/chat/repositories/subscriber.repository.ts +++ b/api/src/chat/repositories/subscriber.repository.ts @@ -45,16 +45,16 @@ export class SubscriberRepository extends BaseRepository< /** * Emits events related to the creation of a new subscriber. * - * @param _created - The newly created subscriber document. + * @param created - The newly created subscriber document. */ - async postCreate(_created: SubscriberDocument): Promise { + async postCreate(created: SubscriberDocument): Promise { this.eventEmitter.emit( 'hook:stats:entry', 'new_users', 'New users', - _created, + created, ); - this.eventEmitter.emit('hook:chatbot:subscriber:create', _created); + this.eventEmitter.emit('hook:subscriber:create', created); } /** @@ -81,7 +81,7 @@ export class SubscriberRepository extends BaseRepository< const subscriberUpdates: SubscriberUpdateDto = updates?.['$set']; this.eventEmitter.emit( - 'hook:chatbot:subscriber:update:before', + 'hook:subscriber:update:before', criteria, subscriberUpdates, ); @@ -122,7 +122,7 @@ export class SubscriberRepository extends BaseRepository< >, updated: Subscriber, ) { - this.eventEmitter.emit('hook:chatbot:subscriber:update:after', updated); + this.eventEmitter.emit('hook:subscriber:update:after', updated); } /** diff --git a/api/src/chat/schemas/subscriber.schema.ts b/api/src/chat/schemas/subscriber.schema.ts index 060962f..155f709 100644 --- a/api/src/chat/schemas/subscriber.schema.ts +++ b/api/src/chat/schemas/subscriber.schema.ts @@ -110,7 +110,7 @@ export class SubscriberStub extends BaseSchema { @Prop({ type: Object, - default: { vars: {} }, //TODO: add this to the migration + default: { vars: {} }, }) context?: SubscriberContext; } diff --git a/api/src/chat/schemas/types/subscriberContext.ts b/api/src/chat/schemas/types/subscriberContext.ts index 18108d3..5a6b3fb 100644 --- a/api/src/chat/schemas/types/subscriberContext.ts +++ b/api/src/chat/schemas/types/subscriberContext.ts @@ -1,3 +1,3 @@ export interface SubscriberContext { - [key: string]: any; + vars?: { [key: string]: any }; } diff --git a/api/src/chat/services/block.service.ts b/api/src/chat/services/block.service.ts index f1b02c9..585ec74 100644 --- a/api/src/chat/services/block.service.ts +++ b/api/src/chat/services/block.service.ts @@ -304,7 +304,7 @@ export class BlockService extends BaseService { subscriberContext: SubscriberContext, settings: Settings, ): string { - const vars = { ...subscriberContext.vars, ...context.vars }; + const vars = { ...(subscriberContext?.vars || {}), ...context.vars }; // Replace context tokens with their values Object.keys(vars).forEach((key) => { if (typeof vars[key] === 'string' && vars[key].indexOf(':') !== -1) { diff --git a/api/src/chat/services/chat.service.ts b/api/src/chat/services/chat.service.ts index b1c53b1..e13f49d 100644 --- a/api/src/chat/services/chat.service.ts +++ b/api/src/chat/services/chat.service.ts @@ -287,7 +287,7 @@ export class ChatService { * * @param subscriber - The end user (subscriber) */ - @OnEvent('hook:chatbot:subscriber:create') + @OnEvent('hook:subscriber:create') onSubscriberCreate(subscriber: Subscriber) { this.websocketGateway.broadcastSubscriberNew(subscriber); } @@ -297,7 +297,7 @@ export class ChatService { * * @param subscriber - The end user (subscriber) */ - @OnEvent('hook:chatbot:subscriber:update:after') + @OnEvent('hook:subscriber:update:after') onSubscriberUpdate(subscriber: Subscriber) { this.websocketGateway.broadcastSubscriberUpdate(subscriber); } diff --git a/api/src/cms/schemas/types/menu.ts b/api/src/cms/schemas/types/menu.ts index c04aaba..8bba557 100644 --- a/api/src/cms/schemas/types/menu.ts +++ b/api/src/cms/schemas/types/menu.ts @@ -6,7 +6,7 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ -import { MenuStub, Menu } from '../menu.schema'; +import { Menu, MenuStub } from '../menu.schema'; export enum MenuType { web_url = 'web_url',