mirror of
https://git.meshkee.com/BaloutPastry/backend.git
synced 2026-08-11 22:31:00 +04:30
Initial commit of Balout Pastry NestJS API.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,256 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
enum UserRole {
|
||||
customer
|
||||
admin
|
||||
superAdmin
|
||||
}
|
||||
|
||||
enum SellUnit {
|
||||
unit
|
||||
kilo
|
||||
}
|
||||
|
||||
enum OrderStatus {
|
||||
pending
|
||||
confirmed
|
||||
preparing
|
||||
ready
|
||||
delivered
|
||||
cancelled
|
||||
}
|
||||
|
||||
enum DeliveryType {
|
||||
shipping
|
||||
pickup
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
title String
|
||||
firstName String
|
||||
lastName String
|
||||
category String?
|
||||
cellNumber String @unique
|
||||
passwordHash String
|
||||
role UserRole @default(customer)
|
||||
disabled Boolean @default(false)
|
||||
totalOrders Int @default(0)
|
||||
totalTransaction Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
refreshTokens RefreshToken[]
|
||||
addresses UserAddress[]
|
||||
orders Order[]
|
||||
|
||||
@@index([role])
|
||||
@@index([disabled])
|
||||
}
|
||||
|
||||
model UserAddress {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
name String
|
||||
district String
|
||||
address String
|
||||
landline String @default("")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model RefreshToken {
|
||||
id String @id @default(cuid())
|
||||
tokenHash String
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
expiresAt DateTime
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([userId])
|
||||
@@index([tokenHash])
|
||||
}
|
||||
|
||||
model Flavor {
|
||||
id String @id @default(cuid())
|
||||
nameFa String
|
||||
nameEn String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
categoryOptionBlocks CategoryOptionBlock[]
|
||||
productOptions ProductOption[]
|
||||
}
|
||||
|
||||
model Category {
|
||||
id String @id @default(cuid())
|
||||
nameFa String
|
||||
nameEn String
|
||||
parentId String?
|
||||
parent Category? @relation("CategoryTree", fields: [parentId], references: [id], onDelete: Restrict)
|
||||
children Category[] @relation("CategoryTree")
|
||||
sortOrder Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
optionBlocks CategoryOptionBlock[]
|
||||
products Product[]
|
||||
|
||||
@@index([parentId])
|
||||
}
|
||||
|
||||
model CategoryOptionBlock {
|
||||
id String @id @default(cuid())
|
||||
categoryId String
|
||||
flavorId String
|
||||
sortOrder Int @default(0)
|
||||
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
flavor Flavor @relation(fields: [flavorId], references: [id], onDelete: Restrict)
|
||||
entries CategoryOptionEntry[]
|
||||
|
||||
@@index([categoryId])
|
||||
@@index([flavorId])
|
||||
}
|
||||
|
||||
model CategoryOptionEntry {
|
||||
id String @id @default(cuid())
|
||||
blockId String
|
||||
amount String
|
||||
price Int
|
||||
sortOrder Int @default(0)
|
||||
block CategoryOptionBlock @relation(fields: [blockId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([blockId])
|
||||
}
|
||||
|
||||
model Product {
|
||||
id String @id @default(cuid())
|
||||
nameFa String
|
||||
nameEn String
|
||||
price Int @default(0)
|
||||
sellUnit SellUnit @default(unit)
|
||||
categoryId String
|
||||
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
|
||||
intro String @default("")
|
||||
description String @default("")
|
||||
mainImageUrl String?
|
||||
mainImageKey String?
|
||||
tags String[] @default([])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
gallery ProductGalleryImage[]
|
||||
options ProductOption[]
|
||||
orderItems OrderItem[]
|
||||
|
||||
@@index([categoryId])
|
||||
@@index([price])
|
||||
}
|
||||
|
||||
model ProductGalleryImage {
|
||||
id String @id @default(cuid())
|
||||
productId String
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
url String
|
||||
storageKey String
|
||||
sortOrder Int @default(0)
|
||||
|
||||
@@index([productId])
|
||||
}
|
||||
|
||||
model ProductOption {
|
||||
id String @id @default(cuid())
|
||||
productId String
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
flavorId String
|
||||
flavor Flavor @relation(fields: [flavorId], references: [id], onDelete: Restrict)
|
||||
amount String
|
||||
price Int
|
||||
|
||||
@@index([productId])
|
||||
@@index([flavorId])
|
||||
}
|
||||
|
||||
model ShippingException {
|
||||
id String @id @default(cuid())
|
||||
district String @unique
|
||||
price Int
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Branch {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
district String
|
||||
address String
|
||||
landline String @default("")
|
||||
cellNumber String @default("")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
orders Order[]
|
||||
}
|
||||
|
||||
model Order {
|
||||
id String @id @default(cuid())
|
||||
number Int @unique @default(autoincrement())
|
||||
customerId String
|
||||
customer User @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
||||
customerName String
|
||||
customerPhone String
|
||||
status OrderStatus @default(pending)
|
||||
deliveryType DeliveryType
|
||||
branchId String?
|
||||
branch Branch? @relation(fields: [branchId], references: [id], onDelete: SetNull)
|
||||
branchName String?
|
||||
shippingAddressId String?
|
||||
shippingName String?
|
||||
shippingDistrict String?
|
||||
shippingAddressLine String?
|
||||
shippingLandline String?
|
||||
note String @default("")
|
||||
itemCount Int
|
||||
totalPrice Int
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
items OrderItem[]
|
||||
|
||||
@@index([customerId])
|
||||
@@index([status])
|
||||
@@index([createdAt])
|
||||
@@index([branchId])
|
||||
}
|
||||
|
||||
model OrderItem {
|
||||
id String @id @default(cuid())
|
||||
orderId String
|
||||
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
||||
productId String?
|
||||
product Product? @relation(fields: [productId], references: [id], onDelete: SetNull)
|
||||
nameFa String
|
||||
quantity Int
|
||||
unitPrice Int
|
||||
sellUnit SellUnit
|
||||
sortOrder Int @default(0)
|
||||
options OrderItemOption[]
|
||||
|
||||
@@index([orderId])
|
||||
@@index([productId])
|
||||
}
|
||||
|
||||
model OrderItemOption {
|
||||
id String @id @default(cuid())
|
||||
orderItemId String
|
||||
orderItem OrderItem @relation(fields: [orderItemId], references: [id], onDelete: Cascade)
|
||||
name String
|
||||
price Int
|
||||
sortOrder Int @default(0)
|
||||
|
||||
@@index([orderItemId])
|
||||
}
|
||||
Reference in New Issue
Block a user