Add new payment service with repository, error handling, and validation Add exceptions package with database and validation utilities Update database package with new schema and zod types Add turbo start script for development
109 lines
2.8 KiB
Plaintext
109 lines
2.8 KiB
Plaintext
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
output = "../generated/prisma"
|
|
}
|
|
|
|
generator zod {
|
|
provider = "zod-prisma-types"
|
|
output = "../generated/zod"
|
|
writeBarrelFiles = false // default is true
|
|
createInputTypes = false // default is true
|
|
createModelTypes = true // default is true
|
|
addInputTypeValidation = false // default is true
|
|
addIncludeType = false // default is true
|
|
addSelectType = false // default is true
|
|
validateWhereUniqueInput = false // default is true
|
|
}
|
|
|
|
generator json {
|
|
provider = "prisma-json-types-generator"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model TelegramSession {
|
|
id String @id
|
|
data Json
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model TelegramUser {
|
|
id String @id
|
|
username String?
|
|
isBlocked Boolean @default(false)
|
|
firstName String?
|
|
lastName String?
|
|
languageCode String?
|
|
isPremium Boolean?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
payments Payment[]
|
|
subscription Subscription?
|
|
}
|
|
|
|
model Payment {
|
|
id String @id @default(cuid())
|
|
telegramUserId String
|
|
amount Decimal @db.Decimal(10, 2)
|
|
currency String
|
|
status PaymentStatus @default(PENDING)
|
|
provider String
|
|
providerId String?
|
|
metadata Json?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
telegramUser TelegramUser @relation(fields: [telegramUserId], references: [id])
|
|
}
|
|
|
|
enum PaymentStatus {
|
|
PENDING
|
|
COMPLETED
|
|
FAILED
|
|
REFUNDED
|
|
}
|
|
|
|
model Plan {
|
|
id String @id @default(uuid())
|
|
code String @unique()
|
|
name String
|
|
description String?
|
|
durationDays Int
|
|
dailyGenerations Int
|
|
price Int
|
|
currency String
|
|
|
|
subscriptions Subscription[]
|
|
|
|
@@index([code])
|
|
}
|
|
|
|
model Subscription {
|
|
id String @id @default(uuid())
|
|
telegramUserId String @unique
|
|
planId String
|
|
|
|
startedAt DateTime @default(now())
|
|
expiresAt DateTime
|
|
canceledAt DateTime?
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
plan Plan @relation(fields: [planId], references: [id], onDelete: Cascade)
|
|
telegramUser TelegramUser @relation(fields: [telegramUserId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([telegramUserId])
|
|
@@index([planId])
|
|
}
|