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.
This commit is contained in:
2024-11-30 16:49:35 +07:00
parent 1e9d3cfbb4
commit c432b71735

View File

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