diff --git a/src/pages/api/accounts/[id]/index.ts b/src/pages/api/accounts/[id]/index.ts index 1dd3600..38a6234 100644 --- a/src/pages/api/accounts/[id]/index.ts +++ b/src/pages/api/accounts/[id]/index.ts @@ -1,5 +1,5 @@ +import { accountService } from '@data/db.service'; import type { APIRoute } from 'astro'; -import { accountService } from '../../../../data/db.service'; export const GET: APIRoute = async ({ params }) => { try { diff --git a/src/pages/api/accounts/[id]/transactions/index.ts b/src/pages/api/accounts/[id]/transactions/index.ts index 1332828..c99d20e 100644 --- a/src/pages/api/accounts/[id]/transactions/index.ts +++ b/src/pages/api/accounts/[id]/transactions/index.ts @@ -1,5 +1,5 @@ +import { transactionService } from '@data/db.service'; import type { APIRoute } from 'astro'; -import { transactionService } from '../../../../../data/db.service'; export const GET: APIRoute = async ({ params }) => { try { diff --git a/src/pages/api/accounts/index.ts b/src/pages/api/accounts/index.ts index 07b6dc4..21c4910 100644 --- a/src/pages/api/accounts/index.ts +++ b/src/pages/api/accounts/index.ts @@ -1,6 +1,6 @@ +import { AccountStatus, AccountType, accountService } from '@data/db.service'; +import type { Account } from '@types'; import type { APIRoute } from 'astro'; -import { AccountStatus, AccountType, accountService } from '../../../data/db.service'; -import type { Account } from '../../../types'; export const GET: APIRoute = async () => { try { diff --git a/src/pages/api/transactions/[id]/index.ts b/src/pages/api/transactions/[id]/index.ts index a64ede5..ec6fa32 100644 --- a/src/pages/api/transactions/[id]/index.ts +++ b/src/pages/api/transactions/[id]/index.ts @@ -1,6 +1,7 @@ +import { transactionService } from '@data/db.service'; +import type { Transaction } from '@types'; +import type { TransactionStatus, TransactionType } from '@types'; import type { APIRoute } from 'astro'; -import { transactionService } from '../../../../data/db.service'; -import type { Transaction } from '../../../../types'; export const GET: APIRoute = async ({ params }) => { try { @@ -55,10 +56,39 @@ export const PUT: APIRoute = async ({ request, params }) => { }); } + // Create a properly typed update object + const updatedData: Partial<{ + accountId: string; + date: Date; + description: string; + amount: number; + category: string | undefined; + status: TransactionStatus | undefined; + type: TransactionType | undefined; + notes: string | undefined; + tags: string | undefined; + }> = {}; + + // Copy the properties we want to update + if (updates.accountId !== undefined) updatedData.accountId = updates.accountId; + if (updates.description !== undefined) updatedData.description = updates.description; + if (updates.amount !== undefined) updatedData.amount = Number(updates.amount); + if (updates.category !== undefined) updatedData.category = updates.category; + if (updates.notes !== undefined) updatedData.notes = updates.notes; + if (updates.tags !== undefined) updatedData.tags = updates.tags; + // Convert date to Date object if it's a string - const updatedData: any = { ...updates }; - if (typeof updates.date === 'string') { - updatedData.date = new Date(updates.date); + if (updates.date !== undefined) { + updatedData.date = typeof updates.date === 'string' ? new Date(updates.date) : updates.date; + } + + // Cast status and type to enum types if provided + if (updates.status !== undefined) { + updatedData.status = updates.status as TransactionStatus; + } + + if (updates.type !== undefined) { + updatedData.type = updates.type as TransactionType; } // Update the transaction using the service diff --git a/src/pages/api/transactions/index.ts b/src/pages/api/transactions/index.ts index 4b4e2c3..8f499ba 100644 --- a/src/pages/api/transactions/index.ts +++ b/src/pages/api/transactions/index.ts @@ -10,9 +10,10 @@ * - Set up proper CORS configuration */ +import { accountService, transactionService } from '@data/db.service'; +import type { Transaction } from '@types'; +import type { TransactionStatus, TransactionType } from '@types'; import type { APIRoute } from 'astro'; -import { accountService, transactionService } from '../../../data/db.service'; -import type { Transaction } from '../../../types'; /** * TODO: API Improvements @@ -61,10 +62,10 @@ export const POST: APIRoute = async ({ request }) => { accountId: transaction.accountId, date: transactionDate, description: transaction.description, - amount: transaction.amount, + amount: Number(transaction.amount), category: transaction.category, - status: transaction.status as any, - type: transaction.type as any, + status: transaction.status as TransactionStatus, + type: transaction.type as TransactionType, notes: transaction.notes, tags: transaction.tags, }); diff --git a/tsconfig.json b/tsconfig.json index 92a18df..8130b47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,18 @@ "exclude": ["dist"], "compilerOptions": { "jsx": "react-jsx", - "jsxImportSource": "react" + "jsxImportSource": "react", + "baseUrl": ".", + "paths": { + "@/*": ["src/*"], + "@components/*": ["src/components/*"], + "@layouts/*": ["src/layouts/*"], + "@data/*": ["src/data/*"], + "@pages/*": ["src/pages/*"], + "@styles/*": ["src/styles/*"], + "@stores/*": ["src/stores/*"], + "@utils/*": ["src/utils.ts"], + "@types": ["src/types.ts"] + } } }