From eefd8f21a914fcbdda2d131cfda87cd0acc4a776 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 4 May 2026 15:38:50 +0700 Subject: [PATCH] feat(notification): add entity --- src/entity/notification.ts | 88 ++++++++++++++++++++++++++++++++++++++ src/schema/public.ts | 1 + 2 files changed, 89 insertions(+) create mode 100644 src/entity/notification.ts diff --git a/src/entity/notification.ts b/src/entity/notification.ts new file mode 100644 index 0000000..8069cbd --- /dev/null +++ b/src/entity/notification.ts @@ -0,0 +1,88 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + ManyToOne, + JoinColumn, + CreateDateColumn, + Index, +} from "typeorm"; + +import { User } from "./users"; + +@Index("idx_notification_recipient_id", ["recipient_id"]) +@Index("idx_notification_sender_id", ["sender_id"]) +@Entity("notifications") +export class Notification { + @PrimaryGeneratedColumn("uuid") + id: string; + + @ManyToOne(() => User, { nullable: false, onDelete: "CASCADE" }) + @JoinColumn({ name: "recipient_id" }) + recipient: User; + + @Column({ + nullable: false, + length: 64, + }) + type: string; + + @Column({ + type: "text", + nullable: false, + }) + message: string; + + @Column({ + type: "jsonb", + nullable: true, + }) + data: Record | null; + + @ManyToOne(() => User, { nullable: true, onDelete: "SET NULL" }) + @JoinColumn({ name: "sender_id" }) + sender: User | null; + + @Column({ + type: "boolean", + default: false, + }) + is_read: boolean; + + @Column({ + type: "timestamp", + nullable: true, + }) + read_at: Date | null; + + @Column({ + type: "varchar", + length: 10, + nullable: true, + }) + priority: string | null; + + @Column({ + type: "text", + nullable: true, + }) + action_url: string | null; + + @Column({ + type: "timestamp", + nullable: true, + }) + expires_at: Date | null; + + @Column({ + type: "uuid", + nullable: true, + }) + batch_id: string | null; + + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true, length: 256 }) + created_by: string; +} diff --git a/src/schema/public.ts b/src/schema/public.ts index 3c3247a..89fea2b 100644 --- a/src/schema/public.ts +++ b/src/schema/public.ts @@ -53,6 +53,7 @@ export * from "../entity/subdistrict"; export * from "../entity/ward"; export * from "../entity/responsible_party_consent"; export * from "../entity/foster_care_history"; +export * from "../entity/notification"; export * from "../types/public"; export * from "../types/action";