fix: adapt chat Module to strict null checks

This commit is contained in:
yassinedorbozgithub
2025-01-13 19:14:41 +01:00
parent 9b8a605bf8
commit 11ef58d048
2 changed files with 17 additions and 13 deletions

View File

@@ -117,6 +117,12 @@ export class ChatService {
try {
const msg = await this.messageService.create(received);
const populatedMsg = await this.messageService.findOneAndPopulate(msg.id);
if (!populatedMsg) {
this.logger.warn('Unable to find populated message.', event);
throw new Error(`Unable to find Message by ID ${msg.id} not found`);
}
this.websocketGateway.broadcastMessageReceived(populatedMsg, subscriber);
this.eventEmitter.emit('hook:stats:entry', 'incoming', 'Incoming');
this.eventEmitter.emit(
@@ -288,7 +294,7 @@ export class ChatService {
@OnEvent('hook:subscriber:postCreate')
async onSubscriberCreate({ _id }: SubscriberDocument) {
const subscriber = await this.subscriberService.findOne(_id);
this.websocketGateway.broadcastSubscriberNew(subscriber);
if (subscriber) this.websocketGateway.broadcastSubscriberNew(subscriber);
}
/**
@@ -299,6 +305,6 @@ export class ChatService {
@OnEvent('hook:subscriber:postUpdate')
async onSubscriberUpdate({ _id }: SubscriberDocument) {
const subscriber = await this.subscriberService.findOne(_id);
this.websocketGateway.broadcastSubscriberUpdate(subscriber);
if (subscriber) this.websocketGateway.broadcastSubscriberUpdate(subscriber);
}
}