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:
@@ -2,7 +2,8 @@ import { Injectable } from '@nestjs/common'
|
|||||||
import { PubSubEvent } from 'src/common/pubsub/pubsub-event'
|
import { PubSubEvent } from 'src/common/pubsub/pubsub-event'
|
||||||
import { PrismaService } from 'src/Prisma/prisma.service'
|
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||||
import { PubSubService } from 'src/PubSub/pubsub.service'
|
import { PubSubService } from 'src/PubSub/pubsub.service'
|
||||||
|
import { Logger } from '@nestjs/common'
|
||||||
|
import { MessageContextType, MessageType } from '@prisma/client'
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -11,6 +12,15 @@ export class NotificationService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async sendNotification(userId: string, title: string, content: string) {
|
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}`, {
|
await this.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${userId}`, {
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
|
|||||||
Reference in New Issue
Block a user