Update import statements to use path aliases throughout codebase

This commit is contained in:
GitHub Copilot
2025-05-06 11:53:33 +00:00
parent 984cd42f27
commit 069faac7bc
3 changed files with 38 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
import type { PrismaClient } from '@prisma/client';
import type { Prisma, PrismaClient } from '@prisma/client';
import { Decimal } from '@prisma/client/runtime/library';
import type { Account, Transaction } from '../types';
import type { Account, Transaction } from '@types';
import { prisma } from './prisma';
// Define the enums ourselves since Prisma isn't exporting them
@@ -37,7 +37,7 @@ export const accountService = {
async getAll(): Promise<Account[]> {
return prisma.account.findMany({
orderBy: { name: 'asc' },
});
}) as Promise<Account[]>;
},
/**
@@ -46,7 +46,7 @@ export const accountService = {
async getById(id: string): Promise<Account | null> {
return prisma.account.findUnique({
where: { id },
});
}) as Promise<Account | null>;
},
/**
@@ -64,7 +64,7 @@ export const accountService = {
}): Promise<Account> {
return prisma.account.create({
data,
});
}) as Promise<Account>;
},
/**
@@ -86,7 +86,7 @@ export const accountService = {
return prisma.account.update({
where: { id },
data,
});
}) as Promise<Account>;
},
/**
@@ -95,7 +95,7 @@ export const accountService = {
async delete(id: string): Promise<Account | null> {
return prisma.account.delete({
where: { id },
});
}) as Promise<Account>;
},
/**
@@ -115,7 +115,7 @@ export const accountService = {
increment: amount,
},
},
});
}) as Promise<Account>;
},
};
@@ -127,7 +127,7 @@ export const transactionService = {
async getAll(): Promise<Transaction[]> {
return prisma.transaction.findMany({
orderBy: { date: 'desc' },
});
}) as Promise<Transaction[]>;
},
/**
@@ -137,7 +137,7 @@ export const transactionService = {
return prisma.transaction.findMany({
where: { accountId },
orderBy: { date: 'desc' },
});
}) as Promise<Transaction[]>;
},
/**
@@ -146,7 +146,7 @@ export const transactionService = {
async getById(id: string): Promise<Transaction | null> {
return prisma.transaction.findUnique({
where: { id },
});
}) as Promise<Transaction | null>;
},
/**
@@ -164,14 +164,14 @@ export const transactionService = {
tags?: string;
}): Promise<Transaction> {
// Use a transaction to ensure data consistency
return prisma.$transaction(async (prismaClient: PrismaClient) => {
return prisma.$transaction<Transaction>(async (tx) => {
// Create the transaction
const transaction = await prismaClient.transaction.create({
const transaction = await tx.transaction.create({
data,
});
// Update the account balance
await prismaClient.account.update({
await tx.account.update({
where: { id: data.accountId },
data: {
balance: {
@@ -180,7 +180,7 @@ export const transactionService = {
},
});
return transaction;
return transaction as Transaction;
});
},
@@ -203,26 +203,26 @@ export const transactionService = {
): Promise<Transaction | null> {
// If amount is changing, we need to adjust the account balance
if (typeof data.amount !== 'undefined') {
return prisma.$transaction(async (prismaClient: PrismaClient) => {
return prisma.$transaction<Transaction | null>(async (tx) => {
// Get the current transaction to calculate difference
const currentTxn = await prismaClient.transaction.findUnique({
const currentTxn = await tx.transaction.findUnique({
where: { id },
});
if (!currentTxn) return null;
// Calculate amount difference - amount is guaranteed to be defined at this point
const amount = data.amount; // Store in a constant to help TypeScript understand
// Amount is guaranteed to be defined at this point since we checked above
const amount = data.amount as number; // Use type assertion instead of non-null assertion
const amountDifference = amount - Number(currentTxn.amount);
// Update transaction
const updatedTxn = await prismaClient.transaction.update({
const updatedTxn = await tx.transaction.update({
where: { id },
data,
});
// Update account balance
await prismaClient.account.update({
await tx.account.update({
where: { id: data.accountId || currentTxn.accountId },
data: {
balance: {
@@ -231,7 +231,7 @@ export const transactionService = {
},
});
return updatedTxn;
return updatedTxn as Transaction;
});
}
@@ -239,28 +239,28 @@ export const transactionService = {
return prisma.transaction.update({
where: { id },
data,
});
}) as Promise<Transaction>;
},
/**
* Delete a transaction and adjust account balance
*/
async delete(id: string): Promise<Transaction | null> {
return prisma.$transaction(async (prismaClient: PrismaClient) => {
return prisma.$transaction<Transaction | null>(async (tx) => {
// Get transaction before deleting
const transaction = await prismaClient.transaction.findUnique({
const transaction = await tx.transaction.findUnique({
where: { id },
});
if (!transaction) return null;
// Delete the transaction
const deletedTxn = await prismaClient.transaction.delete({
const deletedTxn = await tx.transaction.delete({
where: { id },
});
// Adjust the account balance (reverse the transaction amount)
await prismaClient.account.update({
await tx.account.update({
where: { id: transaction.accountId },
data: {
balance: {
@@ -269,7 +269,7 @@ export const transactionService = {
},
});
return deletedTxn;
return deletedTxn as Transaction;
});
},
};

View File

@@ -10,9 +10,9 @@
* - Set up proper CORS configuration
*/
import type { APIRoute } from 'astro';
import { accountService, transactionService } from '@data/db.service';
import type { Transaction, TransactionStatus, TransactionType } from '@types';
import type { APIRoute } from 'astro';
/**
* TODO: API Improvements

View File

@@ -1,7 +1,8 @@
import { AccountType, TransactionType, accountService, transactionService } from '@data/db.service';
import { prisma } from '@data/prisma';
import type { Account, Transaction } from '@types';
import supertest from 'supertest';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { accountService, transactionService } from '../data/db.service';
import { prisma } from '../data/prisma';
// Define a test server
const BASE_URL = 'http://localhost:4322';
@@ -34,7 +35,7 @@ describe('Database Integration Tests', () => {
bankName: 'Test Bank',
accountNumber: '123456',
name: 'Test Account',
type: 'CHECKING',
type: AccountType.CHECKING,
balance: 1000,
notes: 'Created for automated testing',
});
@@ -90,7 +91,7 @@ describe('Database Integration Tests', () => {
expect(response.body.length).toBeGreaterThan(0);
// Check if our test account is in the response
const foundAccount = response.body.find((account: any) => account.id === testAccountId);
const foundAccount = response.body.find((account: Account) => account.id === testAccountId);
expect(foundAccount).toBeDefined();
});
@@ -118,7 +119,7 @@ describe('Database Integration Tests', () => {
description: 'Test Transaction',
amount: -50.25,
category: 'Testing',
type: 'WITHDRAWAL',
type: TransactionType.WITHDRAWAL,
};
const response = await request
@@ -145,7 +146,9 @@ describe('Database Integration Tests', () => {
expect(Array.isArray(response.body)).toBe(true);
// Check if our test transaction is in the response
const foundTransaction = response.body.find((txn: any) => txn.id === testTransactionId);
const foundTransaction = response.body.find(
(txn: Transaction) => txn.id === testTransactionId,
);
expect(foundTransaction).toBeDefined();
expect(foundTransaction.description).toBe('Test Transaction');
});