Add TypeScript path aliases and update import paths

This commit is contained in:
GitHub Copilot
2025-05-06 11:16:49 +00:00
parent 19a0e55654
commit 4bf29c70eb
6 changed files with 58 additions and 15 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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,
});

View File

@@ -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"]
}
}
}