feat: implement payment service with error handling and validation
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
This commit is contained in:
@@ -9,6 +9,22 @@ generator client {
|
||||
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")
|
||||
@@ -31,4 +47,62 @@ model TelegramUser {
|
||||
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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user