diff --git a/src/notifications/entities/notification.entity.ts b/src/notifications/entities/notification.entity.ts index 9d8fbe8..06e7643 100644 --- a/src/notifications/entities/notification.entity.ts +++ b/src/notifications/entities/notification.entity.ts @@ -1,22 +1,9 @@ -import { - Entity, - PrimaryGeneratedColumn, - Column, - CreateDateColumn, - UpdateDateColumn, - ManyToOne, - JoinColumn, - Index, -} from 'typeorm'; -import { User } from 'src/auth/entities/user.entity'; +import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm'; + export enum NotificationType { - JOB_APPLICATION = 'job_application', - MESSAGE = 'message', - JOB_MATCH = 'job_match', - PAYMENT = 'payment', - SYSTEM = 'system', GENERAL = 'general', - JOB_STATUS_UPDATE = 'JOB_STATUS_UPDATE', + ALERT = 'alert', + INFO = 'info', } @Entity('notifications') @@ -26,41 +13,18 @@ export class Notification { @PrimaryGeneratedColumn('uuid') id: string; - @Column({ type: 'varchar', length: 255 }) - title: string; + @Column({ type: 'uuid' }) + userId: string; @Column({ type: 'text' }) message: string; - @Column({ - type: 'enum', - enum: NotificationType, - default: NotificationType.GENERAL, - }) + @Column({ type: 'enum', enum: NotificationType, default: NotificationType.GENERAL }) type: NotificationType; @Column({ type: 'boolean', default: false }) isRead: boolean; - @Column({ type: 'uuid' }) - userId: string; - - @ManyToOne(() => User, (user) => user.notifications, { - onDelete: 'CASCADE', - eager: false, - }) - @JoinColumn({ name: 'userId' }) - user: User; - - @Column({ type: 'uuid', nullable: true }) - relatedEntityId: string; - - @Column({ type: 'varchar', length: 100, nullable: true }) - relatedEntityType: string; - - @Column({ type: 'json', nullable: true }) - metadata: Record; - @CreateDateColumn() createdAt: Date; diff --git a/src/notifications/notifications.module.ts b/src/notifications/notifications.module.ts index f7253cf..7ebd88b 100644 --- a/src/notifications/notifications.module.ts +++ b/src/notifications/notifications.module.ts @@ -1,19 +1,10 @@ -import { Module, forwardRef } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; -import { NotificationsController } from './notifications.controller'; import { NotificationsService } from './notifications.service'; import { Notification } from './entities/notification.entity'; -import { AuthModule } from '../auth/auth.module'; -import { FeedModule } from 'src/feed/feed.module'; -import { ApplicationsModule } from 'src/applications/applications.module'; @Module({ - imports: [ - ApplicationsModule, - TypeOrmModule.forFeature([Notification]), - forwardRef(() => AuthModule), - ], - controllers: [NotificationsController], + imports: [TypeOrmModule.forFeature([Notification])], providers: [NotificationsService], exports: [NotificationsService], }) diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index 8c5a436..505f60c 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -215,4 +215,17 @@ export class NotificationsService { where: { userId, isRead: false }, }); } + + async createNotification(userId: string, message: string, type: NotificationType = NotificationType.GENERAL): Promise { + const notification = this.notificationRepository.create({ userId, message, type }); + return this.notificationRepository.save(notification); + } + + async getUserNotifications(userId: string, limit = 20): Promise { + return this.notificationRepository.find({ + where: { userId }, + order: { createdAt: 'DESC' }, + take: limit, + }); + } }