feature: version one notification feature implemented.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "UserNotificationType" AS ENUM (
|
||||
'CASE_SENT',
|
||||
'CLINIC_COMMENT',
|
||||
'LAB_COMMENT',
|
||||
'LAB_COMMENT_CLINIC',
|
||||
'CASE_IMPORTANT',
|
||||
'TASK_COMPLETED',
|
||||
'TASK_ASSIGNED',
|
||||
'CONNECTION_REQUEST',
|
||||
'STAFF_INVITE'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "user_notifications" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"type" "UserNotificationType" NOT NULL,
|
||||
"actorUserId" TEXT,
|
||||
"payload" JSONB,
|
||||
"href" TEXT NOT NULL,
|
||||
"readAt" TIMESTAMP(3),
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "user_notifications_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "user_notifications_userId_organizationId_createdAt_idx"
|
||||
ON "user_notifications"("userId", "organizationId", "createdAt");
|
||||
|
||||
CREATE INDEX "user_notifications_userId_organizationId_readAt_idx"
|
||||
ON "user_notifications"("userId", "organizationId", "readAt");
|
||||
|
||||
ALTER TABLE "user_notifications"
|
||||
ADD CONSTRAINT "user_notifications_userId_fkey"
|
||||
FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "user_notifications"
|
||||
ADD CONSTRAINT "user_notifications_actorUserId_fkey"
|
||||
FOREIGN KEY ("actorUserId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -30,6 +30,8 @@ model User {
|
||||
labCaseComments LabCaseComment[]
|
||||
labCaseActivities LabCaseActivity[]
|
||||
phoneVerificationCodes PhoneVerificationCode[]
|
||||
userNotifications UserNotification[]
|
||||
actedUserNotifications UserNotification[] @relation("UserNotificationActor")
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -435,6 +437,38 @@ enum LabCaseTabReadTarget {
|
||||
TREATMENT
|
||||
}
|
||||
|
||||
enum UserNotificationType {
|
||||
CASE_SENT
|
||||
CLINIC_COMMENT
|
||||
LAB_COMMENT
|
||||
LAB_COMMENT_CLINIC
|
||||
CASE_IMPORTANT
|
||||
TASK_COMPLETED
|
||||
TASK_ASSIGNED
|
||||
CONNECTION_REQUEST
|
||||
STAFF_INVITE
|
||||
}
|
||||
|
||||
/// Fan-out inbox row per recipient. Independent of LabCaseActivity tab badges.
|
||||
model UserNotification {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
organizationId String
|
||||
type UserNotificationType
|
||||
actorUserId String?
|
||||
payload Json?
|
||||
href String
|
||||
readAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
actorUser User? @relation("UserNotificationActor", fields: [actorUserId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([userId, organizationId, createdAt])
|
||||
@@index([userId, organizationId, readAt])
|
||||
@@map("user_notifications")
|
||||
}
|
||||
|
||||
model LabCaseActivity {
|
||||
id String @id @default(uuid())
|
||||
labCaseId String
|
||||
|
||||
Reference in New Issue
Block a user