Update backend API configuration and schema for improved functionality
- Modified TypeScript configuration to disable strict mode and allow importing TypeScript extensions. - Updated Prisma schema to enhance the User model with a new debtAccounts field and refined asset/liability types. - Adjusted environment variable parsing for PORT to use coercion for better type handling. - Refactored various controllers and repositories to utilize type imports for better clarity and maintainability. - Enhanced service layers with new methods for retrieving assets by type and calculating invoice statistics. - Introduced new types for invoice statuses and asset types to ensure consistency across the application.
This commit is contained in:
@@ -10,22 +10,23 @@ datasource db {
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
password String
|
||||
name String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
password String
|
||||
name String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
assets Asset[]
|
||||
liabilities Liability[]
|
||||
snapshots NetWorthSnapshot[]
|
||||
clients Client[]
|
||||
invoices Invoice[]
|
||||
incomeSources IncomeSource[]
|
||||
expenses Expense[]
|
||||
transactions Transaction[]
|
||||
debtCategories DebtCategory[]
|
||||
assets Asset[]
|
||||
liabilities Liability[]
|
||||
snapshots NetWorthSnapshot[]
|
||||
clients Client[]
|
||||
invoices Invoice[]
|
||||
incomeSources IncomeSource[]
|
||||
expenses Expense[]
|
||||
transactions Transaction[]
|
||||
debtCategories DebtCategory[]
|
||||
debtAccounts DebtAccount[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -34,7 +35,7 @@ model Asset {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
type AssetType
|
||||
type String // 'cash' | 'investment' | 'property' | 'vehicle' | 'other'
|
||||
value Float
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
@@ -45,22 +46,14 @@ model Asset {
|
||||
@@map("assets")
|
||||
}
|
||||
|
||||
enum AssetType {
|
||||
CASH
|
||||
INVESTMENT
|
||||
PROPERTY
|
||||
VEHICLE
|
||||
OTHER
|
||||
}
|
||||
|
||||
model Liability {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
type LiabilityType
|
||||
type String // 'credit_card' | 'loan' | 'mortgage' | 'other'
|
||||
balance Float
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@ -68,13 +61,6 @@ model Liability {
|
||||
@@map("liabilities")
|
||||
}
|
||||
|
||||
enum LiabilityType {
|
||||
CREDIT_CARD
|
||||
LOAN
|
||||
MORTGAGE
|
||||
OTHER
|
||||
}
|
||||
|
||||
model NetWorthSnapshot {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
@@ -110,19 +96,19 @@ model Client {
|
||||
}
|
||||
|
||||
model Invoice {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
clientId String
|
||||
invoiceNumber String
|
||||
status InvoiceStatus @default(DRAFT)
|
||||
status String @default("draft") // 'draft' | 'sent' | 'paid' | 'overdue' | 'cancelled'
|
||||
issueDate DateTime
|
||||
dueDate DateTime
|
||||
subtotal Float
|
||||
tax Float @default(0)
|
||||
tax Float @default(0)
|
||||
total Float
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
client Client @relation(fields: [clientId], references: [id], onDelete: Restrict)
|
||||
@@ -134,16 +120,8 @@ model Invoice {
|
||||
@@map("invoices")
|
||||
}
|
||||
|
||||
enum InvoiceStatus {
|
||||
DRAFT
|
||||
SENT
|
||||
PAID
|
||||
OVERDUE
|
||||
CANCELLED
|
||||
}
|
||||
|
||||
model InvoiceLineItem {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
invoiceId String
|
||||
description String
|
||||
quantity Float
|
||||
@@ -161,7 +139,10 @@ model IncomeSource {
|
||||
userId String
|
||||
name String
|
||||
amount Float
|
||||
frequency String
|
||||
frequency String // 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'once'
|
||||
category String
|
||||
nextDate DateTime?
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -172,13 +153,17 @@ model IncomeSource {
|
||||
}
|
||||
|
||||
model Expense {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
amount Float
|
||||
category ExpenseCategory
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
amount Float
|
||||
frequency String // 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'once'
|
||||
category String
|
||||
nextDate DateTime?
|
||||
isActive Boolean @default(true)
|
||||
isEssential Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@ -186,19 +171,16 @@ model Expense {
|
||||
@@map("expenses")
|
||||
}
|
||||
|
||||
enum ExpenseCategory {
|
||||
ESSENTIAL
|
||||
DISCRETIONARY
|
||||
}
|
||||
|
||||
model Transaction {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
description String
|
||||
amount Float
|
||||
type String
|
||||
date DateTime
|
||||
createdAt DateTime @default(now())
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
type String // 'income' | 'expense'
|
||||
name String
|
||||
amount Float
|
||||
category String
|
||||
date DateTime
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@ -210,6 +192,8 @@ model DebtCategory {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
color String @default("#6b7280")
|
||||
isDefault Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -221,18 +205,26 @@ model DebtCategory {
|
||||
}
|
||||
|
||||
model DebtAccount {
|
||||
id String @id @default(uuid())
|
||||
categoryId String
|
||||
name String
|
||||
balance Float
|
||||
interestRate Float?
|
||||
minimumPayment Float?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
categoryId String
|
||||
name String
|
||||
institution String?
|
||||
accountNumber String? // Last 4 digits only
|
||||
originalBalance Float
|
||||
currentBalance Float
|
||||
interestRate Float?
|
||||
minimumPayment Float?
|
||||
dueDay Int? // 1-31
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
category DebtCategory @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
payments DebtPayment[]
|
||||
|
||||
@@index([userId])
|
||||
@@index([categoryId])
|
||||
@@map("debt_accounts")
|
||||
}
|
||||
@@ -242,6 +234,7 @@ model DebtPayment {
|
||||
accountId String
|
||||
amount Float
|
||||
date DateTime
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
account DebtAccount @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
||||
|
||||
Reference in New Issue
Block a user