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:
2025-12-08 02:57:38 -05:00
parent cd93dcbfd2
commit 700832550c
27 changed files with 277 additions and 163 deletions

View File

@@ -1,17 +1,20 @@
import {IncomeSource, Expense, Transaction, Prisma} from '@prisma/client';
import type {IncomeSource, Expense, Transaction, Prisma} from '@prisma/client';
import {DatabaseConnection} from '../config/database';
import {IUserScopedRepository} from './interfaces/IRepository';
const prisma = DatabaseConnection.getInstance();
/**
* Repository for IncomeSource data access
*/
export class IncomeSourceRepository implements IUserScopedRepository<IncomeSource> {
export class IncomeSourceRepository {
async findById(id: string): Promise<IncomeSource | null> {
return prisma.incomeSource.findUnique({where: {id}});
}
async findByIdAndUser(id: string, userId: string): Promise<IncomeSource | null> {
return prisma.incomeSource.findFirst({where: {id, userId}});
}
async findAllByUser(userId: string): Promise<IncomeSource[]> {
return prisma.incomeSource.findMany({
where: {userId},
@@ -43,11 +46,15 @@ export class IncomeSourceRepository implements IUserScopedRepository<IncomeSourc
/**
* Repository for Expense data access
*/
export class ExpenseRepository implements IUserScopedRepository<Expense> {
export class ExpenseRepository {
async findById(id: string): Promise<Expense | null> {
return prisma.expense.findUnique({where: {id}});
}
async findByIdAndUser(id: string, userId: string): Promise<Expense | null> {
return prisma.expense.findFirst({where: {id, userId}});
}
async findAllByUser(userId: string): Promise<Expense[]> {
return prisma.expense.findMany({
where: {userId},
@@ -88,11 +95,15 @@ export class ExpenseRepository implements IUserScopedRepository<Expense> {
/**
* Repository for Transaction data access
*/
export class TransactionRepository implements IUserScopedRepository<Transaction> {
export class TransactionRepository {
async findById(id: string): Promise<Transaction | null> {
return prisma.transaction.findUnique({where: {id}});
}
async findByIdAndUser(id: string, userId: string): Promise<Transaction | null> {
return prisma.transaction.findFirst({where: {id, userId}});
}
async findAllByUser(userId: string): Promise<Transaction[]> {
return prisma.transaction.findMany({
where: {userId},
@@ -104,6 +115,10 @@ export class TransactionRepository implements IUserScopedRepository<Transaction>
return prisma.transaction.create({data});
}
async update(id: string, data: Prisma.TransactionUpdateInput): Promise<Transaction> {
return prisma.transaction.update({where: {id}, data});
}
async delete(id: string): Promise<void> {
await prisma.transaction.delete({where: {id}});
}
@@ -133,11 +148,11 @@ export class TransactionRepository implements IUserScopedRepository<Transaction>
const transactions = await this.getByDateRange(userId, startDate, endDate);
const totalIncome = transactions
.filter(t => t.type === 'INCOME')
.filter(t => t.type === 'income')
.reduce((sum, t) => sum + t.amount, 0);
const totalExpenses = transactions
.filter(t => t.type === 'EXPENSE')
.filter(t => t.type === 'expense')
.reduce((sum, t) => sum + t.amount, 0);
return {