Merge pull request #125 from Hexastack/fix/event-consistent-naming

fix: event consistent naming
This commit is contained in:
Mohamed Marrouchi 2024-10-02 06:58:04 +01:00 committed by GitHub
commit 38e0f6a1f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 14 deletions

View File

@ -43,7 +43,7 @@ export class LabelRepository extends BaseRepository<
*/
async postCreate(created: LabelDocument): Promise<void> {
this.eventEmitter.emit(
'hook:chatbot:label:create',
'hook:label:create',
created,
async (result: Record<string, any>) => {
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);
}
}

View File

@ -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<void> {
async postCreate(created: SubscriberDocument): Promise<void> {
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);
}
/**

View File

@ -110,7 +110,7 @@ export class SubscriberStub extends BaseSchema {
@Prop({
type: Object,
default: { vars: {} }, //TODO: add this to the migration
default: { vars: {} },
})
context?: SubscriberContext;
}

View File

@ -1,3 +1,3 @@
export interface SubscriberContext {
[key: string]: any;
vars?: { [key: string]: any };
}

View File

@ -304,7 +304,7 @@ export class BlockService extends BaseService<Block, BlockPopulate, BlockFull> {
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) {

View File

@ -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);
}

View File

@ -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',