From c432b7173515ec210dcdcc50d356262bea902c8e Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Sat, 30 Nov 2024 16:49:35 +0700 Subject: [PATCH] feat: add logging and notification creation in NotificationService - Implement logging for notification sending process. - Create a new message entry in the database when a notification is sent, specifying recipient, content, type, and context. This enhances the notification handling capabilities of the service. --- src/Notification/notification.service.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Notification/notification.service.ts b/src/Notification/notification.service.ts index 9c35d41..c2be108 100644 --- a/src/Notification/notification.service.ts +++ b/src/Notification/notification.service.ts @@ -2,7 +2,8 @@ import { Injectable } from '@nestjs/common' import { PubSubEvent } from 'src/common/pubsub/pubsub-event' import { PrismaService } from 'src/Prisma/prisma.service' import { PubSubService } from 'src/PubSub/pubsub.service' - +import { Logger } from '@nestjs/common' +import { MessageContextType, MessageType } from '@prisma/client' @Injectable() export class NotificationService { constructor( @@ -11,6 +12,15 @@ export class NotificationService { ) {} async sendNotification(userId: string, title: string, content: string) { + Logger.log(`Send notification to ${userId}`, 'NotificationService') + await this.prisma.message.create({ + data: { + recipientId: userId, + content, + type: MessageType.TEXT, + context: MessageContextType.NOTIFICATION, + }, + }) await this.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${userId}`, { title, content,