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

@ -8,10 +8,8 @@
import { ChannelName } from '@/channel/types'; import { ChannelName } from '@/channel/types';
export type SubscriberChannelData< export type SubscriberChannelData<C extends ChannelName = 'unknown-channel'> =
C extends ChannelName = null, C extends 'unknown-channel'
// K extends keyof SubscriberChannelDict[C] = keyof SubscriberChannelDict[C],
> = C extends null
? { name: ChannelName } ? { name: ChannelName }
: { : {
name: C; name: C;

View File

@ -117,6 +117,12 @@ export class ChatService {
try { try {
const msg = await this.messageService.create(received); const msg = await this.messageService.create(received);
const populatedMsg = await this.messageService.findOneAndPopulate(msg.id); 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.websocketGateway.broadcastMessageReceived(populatedMsg, subscriber);
this.eventEmitter.emit('hook:stats:entry', 'incoming', 'Incoming'); this.eventEmitter.emit('hook:stats:entry', 'incoming', 'Incoming');
this.eventEmitter.emit( this.eventEmitter.emit(
@ -288,7 +294,7 @@ export class ChatService {
@OnEvent('hook:subscriber:postCreate') @OnEvent('hook:subscriber:postCreate')
async onSubscriberCreate({ _id }: SubscriberDocument) { async onSubscriberCreate({ _id }: SubscriberDocument) {
const subscriber = await this.subscriberService.findOne(_id); 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') @OnEvent('hook:subscriber:postUpdate')
async onSubscriberUpdate({ _id }: SubscriberDocument) { async onSubscriberUpdate({ _id }: SubscriberDocument) {
const subscriber = await this.subscriberService.findOne(_id); const subscriber = await this.subscriberService.findOne(_id);
this.websocketGateway.broadcastSubscriberUpdate(subscriber); if (subscriber) this.websocketGateway.broadcastSubscriberUpdate(subscriber);
} }
} }