MIF_E31220277/denta-api/prisma/schema.prisma

344 lines
11 KiB
Plaintext

generator client {
provider = "prisma-client-js"
output = "../prisma/generated/client"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
model User {
id String @id
name String? @unique @db.VarChar(50)
email String? @unique
emailVerified DateTime? @map("email_verified")
password String?
phone String? @db.VarChar(13)
address String?
image String?
role Role?
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
familyName String?
givenName String?
Account Account[]
FasilitatorProfile FasilitatorProfile?
KoasProfile KoasProfile?
Like Like[]
sender Notification[] @relation("Sender")
recipient Notification[] @relation("Recipient")
PasienProfile PasienProfile?
Post Post[]
Review Review[]
sessions Session[]
@@map("users")
}
model Account {
type String?
provider String
scope String?
access_token String? @db.Text
expires_at Int?
id_token String? @db.Text
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
token_type String?
userId String @map("user_id")
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@index([userId], map: "accounts_user_id_fkey")
@@map("accounts")
}
model Session {
id String @id @default(cuid())
expires DateTime
sessionToken String @map("session_token") @db.Text
userId String? @map("user_id")
accessToken String? @map("access_token") @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId], map: "sessions_user_id_fkey")
@@map("sessions")
}
model Otp {
id String @id @default(cuid())
email String
otp String @unique
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([email, otp])
@@map("otps")
}
model KoasProfile {
id String @id @default(cuid())
userId String @unique @map("user_id")
koasNumber String? @unique @map("koas_number")
age String?
gender String?
departement String?
university String?
bio String?
whatsappLink String? @map("whatsapp_link")
status StatusKoas @default(Pending)
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
universityId String?
experience Int? @default(0)
Appointment Appointment[]
University University? @relation(fields: [universityId], references: [id])
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Notification Notification[]
Post Post[]
Review Review[]
@@index([universityId], map: "koas-profile_universityId_fkey")
@@map("koas_profile")
}
model PasienProfile {
id String @id @default(cuid())
userId String @unique @map("user_id")
age String?
gender String?
bio String?
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
Appointment Appointment[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("pasien_profile")
}
model FasilitatorProfile {
id String @id @default(cuid())
userId String @unique @map("user_id")
university String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("fasilitator_profile")
}
model University {
id String @id @default(cuid())
name String
alias String
location String
latitude Float?
longitude Float?
image String?
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
koasProfile KoasProfile[]
@@map("universities")
}
model Post {
id String @id @default(cuid())
userId String @map("user_id")
koasId String @map("koas_id")
treatmentId String @map("treatment_id")
title String
desc String @db.VarChar(500)
patientRequirement Json? @map("patient_requirement")
status StatusPost @default(Pending)
published Boolean @default(false)
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
requiredParticipant Int @default(0) @map("required_participant")
images Json?
likes Like[]
koas KoasProfile @relation(fields: [koasId], references: [id], onDelete: Cascade)
treatment TreatmentType @relation(fields: [treatmentId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Review Review[]
Schedule Schedule[]
@@index([userId], map: "user_id")
@@index([koasId], map: "koas_id")
@@index([treatmentId], map: "treatment_id")
@@map("posts")
}
model Like {
id String @id @default(cuid())
postId String @map("post_id")
userId String @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
Post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([postId], map: "post_id")
@@index([userId], map: "user_id")
@@map("likes")
}
model Notification {
id String @id @default(cuid())
message String
createdAt DateTime @default(now())
koasId String?
senderId String?
status StatusNotification @default(Unread)
title String
updatedAt DateTime @updatedAt
userId String?
koasProfile KoasProfile? @relation(fields: [koasId], references: [id], onDelete: Cascade)
sender User? @relation("Sender", fields: [senderId], references: [id], onDelete: Cascade)
recipient User? @relation("Recipient", fields: [userId], references: [id], onDelete: Cascade)
@@index([koasId], map: "notifications_koasId_fkey")
@@index([senderId], map: "notifications_senderId_fkey")
@@index([userId], map: "notifications_userId_fkey")
@@map("notifications")
}
model TreatmentType {
id String @id @default(cuid())
name String
createdAt DateTime @default(now()) @map("created_at")
updateAt DateTime @updatedAt @map("updated_at")
alias String
image String?
Post Post[]
@@map("treatment_types")
}
model Schedule {
id String @id @default(cuid())
postId String @map("post_id")
createdAt DateTime @default(now()) @map("created_at")
dateEnd DateTime @map("date_end")
dateStart DateTime @map("date_start")
updateAt DateTime @updatedAt @map("updated_at")
Appointment Appointment[]
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
timeslot Timeslot[]
@@index([postId], map: "post_id")
@@map("schedules")
}
model Timeslot {
id String @id @default(cuid())
startTime String @map("start_time")
endTime String @map("end_time")
maxParticipants Int? @map("max_participants")
currentParticipants Int @default(0) @map("current_participants")
isAvailable Boolean @default(true) @map("is_available")
scheduleId String @map("schedule_id")
Appointment Appointment[]
schedule Schedule @relation(fields: [scheduleId], references: [id], onDelete: Cascade)
@@unique([scheduleId, startTime, endTime], name: "unique_timeslot")
@@map("timeslots")
}
model Review {
id String @id @default(cuid())
postId String @map("post_id")
pasienId String @map("user_id")
rating Decimal @default(0.000000000000000000000000000000)
comment String? @db.VarChar(500)
createdAt DateTime @default(now()) @map("created_at")
koasId String? @map("koas_id")
KoasProfile KoasProfile? @relation(fields: [koasId], references: [userId])
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [pasienId], references: [id], onDelete: Cascade)
@@index([postId], map: "post_id")
@@index([pasienId], map: "pasien_Id")
@@index([koasId], map: "koas_id")
@@map("reviews")
}
model Appointment {
id String @id @default(cuid())
pasienId String @map("pasien_id")
koasId String @map("koas_id")
scheduleId String @map("schedule_id")
timeslotId String @map("timeslot_id")
date String
status StatusAppointment @default(Pending)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
koas KoasProfile @relation(fields: [koasId], references: [id], onDelete: Cascade)
pasien PasienProfile @relation(fields: [pasienId], references: [id], onDelete: Cascade)
schedule Schedule @relation(fields: [scheduleId], references: [id], onDelete: Cascade)
timeslot Timeslot @relation(fields: [timeslotId], references: [id], onDelete: Cascade)
@@index([koasId], map: "appointment_koas_id_fkey")
@@index([pasienId], map: "appointment_pasien_id_fkey")
@@index([scheduleId], map: "appointment_schedule_id_fkey")
@@index([timeslotId], map: "appointment_timeslot_id_fkey")
@@map("appointments")
}
model verificationrequest {
id String @id
token String @unique(map: "VerificationRequest_token_key")
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime
email String
@@unique([email, token], map: "VerificationRequest_email_token_key")
}
enum Role {
Admin
Koas
Pasien
Fasilitator
@@map("roles")
}
enum StatusPost {
Pending
Open
Closed
@@map("status_post")
}
enum StatusKoas {
Rejected
Pending
Approved
@@map("status_koas")
}
enum StatusAppointment {
Canceled
Rejected
Pending
Confirmed
Ongoing
Completed
@@map("status_appointment")
}
enum StatusNotification {
Unread
Read
}