V1.0.0 Es funktioniert soweit Alles

This commit is contained in:
2026-02-27 16:41:03 +00:00
parent 14bb3fd2cd
commit 5981a7a6db
4 changed files with 48 additions and 20 deletions

View File

@@ -10,13 +10,20 @@ export async function PUT(
try { try {
const { id } = await context.params; const { id } = await context.params;
const body = await request.json(); const body = await request.json();
const { Datum, Wo, Was, Wieviel, Wie, TYP, OK } = body; const { Datum, Wo, Was, Wieviel, Wie, TYP } = body;
if (!Datum || !Wo || !Was || !Wieviel || !Wie || TYP === undefined) {
return NextResponse.json(
{ success: false, error: 'Missing required fields' },
{ status: 400 }
);
}
const pool = getDbPool(); const pool = getDbPool();
const query = ` const query = `
UPDATE Ausgaben UPDATE Ausgaben
SET Datum = ?, Wo = ?, Was = ?, Wieviel = ?, Wie = ?, TYP = ?, OK = ? SET Datum = ?, Wo = ?, Was = ?, Wieviel = ?, Wie = ?, TYP = ?
WHERE ID = ? WHERE ID = ?
`; `;
@@ -27,7 +34,6 @@ export async function PUT(
parseFloat(Wieviel), parseFloat(Wieviel),
Wie, Wie,
TYP, TYP,
OK || 0,
parseInt(id), parseInt(id),
]); ]);

View File

@@ -14,7 +14,8 @@ export async function GET(request: Request) {
const pool = getDbPool(); const pool = getDbPool();
let query = `SELECT *, let query = `SELECT
ID, Datum, Wo, Was, Wieviel, Wie, TYP,
CASE DAYOFWEEK(Datum) CASE DAYOFWEEK(Datum)
WHEN 1 THEN 'Sonntag' WHEN 1 THEN 'Sonntag'
WHEN 2 THEN 'Montag' WHEN 2 THEN 'Montag'
@@ -67,7 +68,7 @@ export async function GET(request: Request) {
export async function POST(request: Request) { export async function POST(request: Request) {
try { try {
const body = await request.json(); const body = await request.json();
const { Datum, Wo, Was, Wieviel, Wie, TYP, OK } = body; const { Datum, Wo, Was, Wieviel, Wie, TYP } = body;
if (!Datum || !Wo || !Was || !Wieviel || !Wie || TYP === undefined) { if (!Datum || !Wo || !Was || !Wieviel || !Wie || TYP === undefined) {
return NextResponse.json( return NextResponse.json(
@@ -79,8 +80,8 @@ export async function POST(request: Request) {
const pool = getDbPool(); const pool = getDbPool();
const query = ` const query = `
INSERT INTO Ausgaben (Datum, Wo, Was, Wieviel, Wie, TYP, OK) INSERT INTO Ausgaben (Datum, Wo, Was, Wieviel, Wie, TYP)
VALUES (?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
`; `;
const [result] = await pool.query<ResultSetHeader>(query, [ const [result] = await pool.query<ResultSetHeader>(query, [
@@ -90,7 +91,6 @@ export async function POST(request: Request) {
parseFloat(Wieviel), parseFloat(Wieviel),
Wie, Wie,
TYP, TYP,
OK || 0,
]); ]);
return NextResponse.json({ return NextResponse.json({

View File

@@ -21,7 +21,6 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: '', Wieviel: '',
Wie: defaultZahlungsart, Wie: defaultZahlungsart,
TYP: typ, TYP: typ,
OK: 0,
}); });
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
@@ -95,26 +94,41 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: selectedEntry.Wieviel.toString(), Wieviel: selectedEntry.Wieviel.toString(),
Wie: selectedEntry.Wie, Wie: selectedEntry.Wie,
TYP: selectedEntry.TYP, TYP: selectedEntry.TYP,
OK: selectedEntry.OK || 0,
}); });
setEditId(selectedEntry.ID); // Handle both uppercase and lowercase ID field names
const entryId = (selectedEntry as any).id || selectedEntry.ID;
setEditId(entryId);
} else { } else {
// Initialize with current date for new entry // Reset form for new entry
const now = new Date(); const now = new Date();
const dateStr = now.toISOString().split('T')[0]; const dateStr = now.toISOString().split('T')[0];
const weekday = getWeekday(now); const weekday = getWeekday(now);
setFormData(prev => ({ setFormData({
...prev,
Datum: dateStr, Datum: dateStr,
WochTag: weekday, WochTag: weekday,
Wo: '',
Was: '',
Wieviel: '',
Wie: defaultZahlungsart,
TYP: typ, TYP: typ,
})); });
setEditId(null); setEditId(null);
} }
}, [selectedEntry, typ]); }, [selectedEntry]);
// Update TYP when tab changes
useEffect(() => {
if (!selectedEntry) {
setFormData(prev => ({
...prev,
TYP: typ,
Wie: defaultZahlungsart,
}));
}
}, [typ]);
const getWeekday = (date: Date): string => { const getWeekday = (date: Date): string => {
const weekdays = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']; const weekdays = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
@@ -143,12 +157,22 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
const url = editId ? `/api/ausgaben/${editId}` : '/api/ausgaben'; const url = editId ? `/api/ausgaben/${editId}` : '/api/ausgaben';
const method = editId ? 'PUT' : 'POST'; const method = editId ? 'PUT' : 'POST';
// Send only the fields we need, excluding any extra fields
const dataToSend = {
Datum: formData.Datum,
Wo: formData.Wo,
Was: formData.Was,
Wieviel: formData.Wieviel,
Wie: formData.Wie,
TYP: formData.TYP,
};
const response = await fetch(url, { const response = await fetch(url, {
method: method, method: method,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify(formData), body: JSON.stringify(dataToSend),
}); });
if (response.ok) { if (response.ok) {
@@ -180,7 +204,7 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: '', Wieviel: '',
Wie: defaultZahlungsart, Wie: defaultZahlungsart,
TYP: typ, TYP: typ,
OK: 0,
}); });
setEditId(null); setEditId(null);

View File

@@ -9,7 +9,6 @@ export interface AusgabenEntry {
Wieviel: number; Wieviel: number;
Wie: string; Wie: string;
TYP: number; TYP: number;
OK?: number;
} }
export interface CreateAusgabenEntry { export interface CreateAusgabenEntry {
@@ -20,7 +19,6 @@ export interface CreateAusgabenEntry {
Wieviel: string | number; Wieviel: string | number;
Wie: string; Wie: string;
TYP: number; TYP: number;
OK?: number;
} }
export interface MonthlyStats { export interface MonthlyStats {