Add VSCode task for automatic build on project open and update dependencies

Remove .vscode from .gitignore to allow for project-specific settings. Introduce a VSCode task to run `npm run dev` automatically when the project is opened. Update environment configuration files and dependencies to enhance support for the Node adapter.

Fixes #13
This commit is contained in:
GitHub Copilot
2025-05-01 21:05:24 +00:00
parent 8058df41fd
commit b51fe35a16
23 changed files with 342 additions and 401 deletions

View File

@@ -1,14 +1,14 @@
import type { APIRoute } from "astro";
import { accounts } from "../../../../data/store";
import type { APIRoute } from 'astro';
import { accounts } from '../../../../data/store';
export const GET: APIRoute = async ({ params }) => {
const account = accounts.find((a) => a.id === params.id);
if (!account) {
return new Response(JSON.stringify({ error: "Account not found" }), {
return new Response(JSON.stringify({ error: 'Account not found' }), {
status: 404,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
}
@@ -16,7 +16,7 @@ export const GET: APIRoute = async ({ params }) => {
return new Response(JSON.stringify(account), {
status: 200,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
};

View File

@@ -1,15 +1,13 @@
import type { APIRoute } from "astro";
import { transactions } from "../../../../../data/store";
import type { APIRoute } from 'astro';
import { transactions } from '../../../../../data/store';
export const GET: APIRoute = async ({ params }) => {
const accountTransactions = transactions.filter(
(t) => t.accountId === params.id
);
const accountTransactions = transactions.filter((t) => t.accountId === params.id);
return new Response(JSON.stringify(accountTransactions), {
status: 200,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
};

View File

@@ -1,11 +1,11 @@
import type { APIRoute } from "astro";
import { accounts } from "../../../data/store";
import type { APIRoute } from 'astro';
import { accounts } from '../../../data/store';
export const GET: APIRoute = async () => {
return new Response(JSON.stringify(accounts), {
status: 200,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
};

View File

@@ -1,18 +1,15 @@
import type { APIRoute } from "astro";
import { transactions, accounts } from "../../../../data/store";
import type { Transaction } from "../../../../types";
import type { APIRoute } from 'astro';
import { transactions, accounts } from '../../../../data/store';
import type { Transaction } from '../../../../types';
export const PUT: APIRoute = async ({ request, params }) => {
const { id } = params;
if (!id) {
return new Response(
JSON.stringify({ error: "Transaction ID is required" }),
{
status: 400,
headers: { "Content-Type": "application/json" },
}
);
return new Response(JSON.stringify({ error: 'Transaction ID is required' }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
try {
@@ -20,9 +17,9 @@ export const PUT: APIRoute = async ({ request, params }) => {
const transactionIndex = transactions.findIndex((t) => t.id === id);
if (transactionIndex === -1) {
return new Response(JSON.stringify({ error: "Transaction not found" }), {
return new Response(JSON.stringify({ error: 'Transaction not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
@@ -31,9 +28,9 @@ export const PUT: APIRoute = async ({ request, params }) => {
// Get the old account first
const oldAccount = accounts.find((a) => a.id === oldTransaction.accountId);
if (!oldAccount) {
return new Response(JSON.stringify({ error: "Account not found" }), {
return new Response(JSON.stringify({ error: 'Account not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
@@ -42,9 +39,9 @@ export const PUT: APIRoute = async ({ request, params }) => {
if (updates.accountId && updates.accountId !== oldTransaction.accountId) {
const foundAccount = accounts.find((a) => a.id === updates.accountId);
if (!foundAccount) {
return new Response(JSON.stringify({ error: "Account not found" }), {
return new Response(JSON.stringify({ error: 'Account not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
newAccount = foundAccount;
@@ -74,12 +71,12 @@ export const PUT: APIRoute = async ({ request, params }) => {
return new Response(JSON.stringify(updatedTransaction), {
status: 200,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
return new Response(JSON.stringify({ error: "Invalid request body" }), {
return new Response(JSON.stringify({ error: 'Invalid request body' }), {
status: 400,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
};
@@ -88,21 +85,18 @@ export const DELETE: APIRoute = async ({ params }) => {
const { id } = params;
if (!id) {
return new Response(
JSON.stringify({ error: "Transaction ID is required" }),
{
status: 400,
headers: { "Content-Type": "application/json" },
}
);
return new Response(JSON.stringify({ error: 'Transaction ID is required' }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
const transactionIndex = transactions.findIndex((t) => t.id === id);
if (transactionIndex === -1) {
return new Response(JSON.stringify({ error: "Transaction not found" }), {
return new Response(JSON.stringify({ error: 'Transaction not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
@@ -110,9 +104,9 @@ export const DELETE: APIRoute = async ({ params }) => {
const account = accounts.find((a) => a.id === transaction.accountId);
if (!account) {
return new Response(JSON.stringify({ error: "Account not found" }), {
return new Response(JSON.stringify({ error: 'Account not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}

View File

@@ -10,9 +10,9 @@
* - Set up proper CORS configuration
*/
import type { APIRoute } from "astro";
import { transactions, accounts } from "../../../data/store";
import type { Transaction } from "../../../types";
import type { APIRoute } from 'astro';
import { transactions, accounts } from '../../../data/store';
import type { Transaction } from '../../../types';
/**
* TODO: API Improvements
@@ -27,7 +27,7 @@ import type { Transaction } from "../../../types";
export const POST: APIRoute = async ({ request }) => {
try {
const transaction = (await request.json()) as Omit<Transaction, "id">;
const transaction = (await request.json()) as Omit<Transaction, 'id'>;
// Validate required fields
if (
@@ -36,21 +36,18 @@ export const POST: APIRoute = async ({ request }) => {
!transaction.description ||
transaction.amount === undefined
) {
return new Response(
JSON.stringify({ error: "Missing required fields" }),
{
status: 400,
headers: { "Content-Type": "application/json" },
}
);
return new Response(JSON.stringify({ error: 'Missing required fields' }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
// Validate account exists
const account = accounts.find((a) => a.id === transaction.accountId);
if (!account) {
return new Response(JSON.stringify({ error: "Account not found" }), {
return new Response(JSON.stringify({ error: 'Account not found' }), {
status: 404,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
@@ -68,12 +65,12 @@ export const POST: APIRoute = async ({ request }) => {
return new Response(JSON.stringify(newTransaction), {
status: 201,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
return new Response(JSON.stringify({ error: "Invalid request body" }), {
return new Response(JSON.stringify({ error: 'Invalid request body' }), {
status: 400,
headers: { "Content-Type": "application/json" },
headers: { 'Content-Type': 'application/json' },
});
}
};

View File

@@ -5,8 +5,8 @@ import MainContent from '../components/MainContent.astro';
import type { Account, Transaction } from '../types';
export interface Props {
account: Account;
transactions: Transaction[];
account: Account;
transactions: Transaction[];
}
// Get the base URL from the incoming request
@@ -18,17 +18,19 @@ const accounts: Account[] = await accountsResponse.json();
// Initialize with first account or empty account if none exist
const initialAccount: Account = accounts[0] || {
id: '',
name: 'No accounts available',
last4: '0000',
balance: 0
id: '',
name: 'No accounts available',
last4: '0000',
balance: 0,
};
// Fetch initial transactions if we have an account, using absolute URL
let initialTransactions: Transaction[] = [];
if (initialAccount.id) {
const transactionsResponse = await fetch(`${baseUrl}/api/accounts/${initialAccount.id}/transactions`);
initialTransactions = await transactionsResponse.json();
const transactionsResponse = await fetch(
`${baseUrl}/api/accounts/${initialAccount.id}/transactions`
);
initialTransactions = await transactionsResponse.json();
}
---