- Updated biome.json to include "graphql.d.ts" in the ignored files list. - Updated subproject commit reference in epess-database to the latest version. - Removed unused script from package.json and streamlined module file extensions in tsconfig.json. - Consolidated exclude patterns in tsconfig.build.json for clarity. - Refactored imports across multiple schema files for consistency and improved readability. - Enhanced various schema files by ensuring proper import order and removing redundant code. - Improved error handling and data integrity checks in several service and schema files.
30 lines
944 B
TypeScript
30 lines
944 B
TypeScript
import { Injectable } from '@nestjs/common'
|
|
import { Logger } from '@nestjs/common'
|
|
import { MessageContextType, MessageType } from '@prisma/client'
|
|
import { PrismaService } from 'src/Prisma/prisma.service'
|
|
import { PubSubService } from 'src/PubSub/pubsub.service'
|
|
import { PubSubEvent } from 'src/common/pubsub/pubsub-event'
|
|
@Injectable()
|
|
export class NotificationService {
|
|
constructor(
|
|
private readonly prisma: PrismaService,
|
|
private readonly pubSub: PubSubService,
|
|
) {}
|
|
|
|
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,
|
|
})
|
|
}
|
|
}
|