From 984cd42f272ba466e255f9d26eeb8c228be03159 Mon Sep 17 00:00:00 2001 From: GitHub Copilot Date: Tue, 6 May 2025 11:38:37 +0000 Subject: [PATCH] Fix TypeScript errors in API endpoints --- src/pages/api/accounts/index.ts | 9 +++++---- src/pages/api/transactions/[id]/index.ts | 9 ++++----- src/pages/api/transactions/index.ts | 11 +++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/pages/api/accounts/index.ts b/src/pages/api/accounts/index.ts index 21c4910..bd261d2 100644 --- a/src/pages/api/accounts/index.ts +++ b/src/pages/api/accounts/index.ts @@ -40,12 +40,13 @@ export const POST: APIRoute = async ({ request }) => { ); } - // Set default values if not provided + // Set default values and ensure proper type casting const data = { ...accountData, - balance: accountData.balance || 0, - type: accountData.type || AccountType.CHECKING, - status: accountData.status || AccountStatus.ACTIVE, + balance: accountData.balance ? Number(accountData.balance) : 0, + type: (accountData.type as AccountType) || AccountType.CHECKING, + status: (accountData.status as AccountStatus) || AccountStatus.ACTIVE, + notes: accountData.notes || undefined, }; // Create the account diff --git a/src/pages/api/transactions/[id]/index.ts b/src/pages/api/transactions/[id]/index.ts index ec6fa32..a7de26e 100644 --- a/src/pages/api/transactions/[id]/index.ts +++ b/src/pages/api/transactions/[id]/index.ts @@ -1,6 +1,5 @@ import { transactionService } from '@data/db.service'; -import type { Transaction } from '@types'; -import type { TransactionStatus, TransactionType } from '@types'; +import type { Transaction, TransactionStatus, TransactionType } from '@types'; import type { APIRoute } from 'astro'; export const GET: APIRoute = async ({ params }) => { @@ -73,9 +72,9 @@ export const PUT: APIRoute = async ({ request, params }) => { 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; + if (updates.category !== undefined) updatedData.category = updates.category || undefined; + if (updates.notes !== undefined) updatedData.notes = updates.notes || undefined; + if (updates.tags !== undefined) updatedData.tags = updates.tags || undefined; // Convert date to Date object if it's a string if (updates.date !== undefined) { diff --git a/src/pages/api/transactions/index.ts b/src/pages/api/transactions/index.ts index 8f499ba..299aa57 100644 --- a/src/pages/api/transactions/index.ts +++ b/src/pages/api/transactions/index.ts @@ -10,10 +10,9 @@ * - 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, TransactionStatus, TransactionType } from '@types'; /** * TODO: API Improvements @@ -63,11 +62,11 @@ export const POST: APIRoute = async ({ request }) => { date: transactionDate, description: transaction.description, amount: Number(transaction.amount), - category: transaction.category, + category: transaction.category || undefined, status: transaction.status as TransactionStatus, type: transaction.type as TransactionType, - notes: transaction.notes, - tags: transaction.tags, + notes: transaction.notes || undefined, + tags: transaction.tags || undefined, }); // Convert Decimal to number for response