Creating a control panel infrastructure

This commit is contained in:
2026-07-23 19:41:21 +03:30
parent 7fbc47766c
commit ddf36f8470
18 changed files with 3377 additions and 35 deletions
+62
View File
@@ -18,6 +18,12 @@ enum UserRole {
viewer
}
enum SmsLedgerType {
charge
debit
adjust
}
model User {
id String @id @default(cuid())
email String @unique
@@ -49,6 +55,9 @@ model Tenant {
appUrl String? @map("app_url")
adminUrl String? @map("admin_url")
remoteApiToken String? @map("remote_api_token")
/// Legacy cache from older sync attempts — SuperAdmin SMS account is now source of truth
smsSettingsCache Json? @map("sms_settings_cache")
smsSyncedAt DateTime? @map("sms_synced_at")
/// Full Khanegi UI JSON (theme, navigation, pages). Hamkar: unused for now.
appUiConfig Json? @map("app_ui_config")
isActive Boolean @default(true) @map("is_active")
@@ -56,12 +65,65 @@ model Tenant {
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
auditLogs AuditLog[]
smsAccount SmsAccount?
@@index([product])
@@index([isActive])
@@map("tenants")
}
/// SuperAdmin-owned SMS wallet + gateway config per sold version.
/// Does NOT replace Hamkar/Khanegi internal SMS panels yet.
model SmsAccount {
id String @id @default(cuid())
tenantId String @unique @map("tenant_id")
balanceRials Int @default(0) @map("balance_rials")
pricePerPartRials Int @default(2500) @map("price_per_part_rials")
isBlocked Boolean @default(false) @map("is_blocked")
/// below this => red/critical
alertCriticalRials Int @default(10000) @map("alert_critical_rials")
/// at/below this (and above critical) => yellow; above => green
alertWarningRials Int @default(100000) @map("alert_warning_rials")
gatewayProvider String? @map("gateway_provider")
melipayamakUser String? @map("melipayamak_user")
melipayamakPassword String? @map("melipayamak_password")
melipayamakFrom String? @map("melipayamak_from")
panelUsername String? @map("panel_username")
panelPassword String? @map("panel_password")
panelFrom String? @map("panel_from")
extraSettings Json? @map("extra_settings")
todayMessages Int @default(0) @map("today_messages")
todayParts Int @default(0) @map("today_parts")
todayCostRials Int @default(0) @map("today_cost_rials")
monthMessages Int @default(0) @map("month_messages")
monthParts Int @default(0) @map("month_parts")
monthCostRials Int @default(0) @map("month_cost_rials")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
ledgers SmsLedger[]
@@map("sms_accounts")
}
model SmsLedger {
id String @id @default(cuid())
smsAccountId String @map("sms_account_id")
type SmsLedgerType
amountRials Int @map("amount_rials")
parts Int?
note String?
createdById String? @map("created_by_id")
createdAt DateTime @default(now()) @map("created_at")
smsAccount SmsAccount @relation(fields: [smsAccountId], references: [id], onDelete: Cascade)
@@index([smsAccountId])
@@index([createdAt])
@@map("sms_ledgers")
}
model AuditLog {
id String @id @default(cuid())
action String