Datenbank aufgefüllt und Einträge angepasst (bei 'Wie')
This commit is contained in:
@@ -10,20 +10,41 @@ export async function GET(request: Request) {
|
||||
const startDate = searchParams.get('startDate');
|
||||
const month = searchParams.get('month');
|
||||
const year = searchParams.get('year');
|
||||
const typ = searchParams.get('typ');
|
||||
|
||||
const pool = getDbPool();
|
||||
|
||||
let query = 'SELECT * FROM Ausgaben';
|
||||
let query = `SELECT *,
|
||||
CASE DAYOFWEEK(Datum)
|
||||
WHEN 1 THEN 'Sonntag'
|
||||
WHEN 2 THEN 'Montag'
|
||||
WHEN 3 THEN 'Dienstag'
|
||||
WHEN 4 THEN 'Mittwoch'
|
||||
WHEN 5 THEN 'Donnerstag'
|
||||
WHEN 6 THEN 'Freitag'
|
||||
WHEN 7 THEN 'Samstag'
|
||||
END as WochTag
|
||||
FROM Ausgaben`;
|
||||
const params: any[] = [];
|
||||
const conditions: string[] = [];
|
||||
|
||||
if (typ !== null && typ !== undefined) {
|
||||
conditions.push('TYP = ?');
|
||||
params.push(parseInt(typ));
|
||||
}
|
||||
|
||||
if (month && year) {
|
||||
query += ' WHERE YEAR(Datum) = ? AND MONTH(Datum) = ?';
|
||||
conditions.push('YEAR(Datum) = ? AND MONTH(Datum) = ?');
|
||||
params.push(year, month);
|
||||
} else if (startDate) {
|
||||
query += ' WHERE Datum >= ?';
|
||||
conditions.push('Datum >= ?');
|
||||
params.push(startDate);
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
query += ' WHERE ' + conditions.join(' AND ');
|
||||
}
|
||||
|
||||
query += ' ORDER BY Datum DESC, ID DESC LIMIT ?';
|
||||
params.push(parseInt(limit));
|
||||
|
||||
@@ -46,9 +67,9 @@ export async function GET(request: Request) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { Datum, WochTag, Wo, Was, Wieviel, Wie, OK } = body;
|
||||
const { Datum, Wo, Was, Wieviel, Wie, TYP, OK } = body;
|
||||
|
||||
if (!Datum || !Wo || !Was || !Wieviel || !Wie) {
|
||||
if (!Datum || !Wo || !Was || !Wieviel || !Wie || TYP === undefined) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Missing required fields' },
|
||||
{ status: 400 }
|
||||
@@ -58,17 +79,17 @@ export async function POST(request: Request) {
|
||||
const pool = getDbPool();
|
||||
|
||||
const query = `
|
||||
INSERT INTO Ausgaben (Datum, WochTag, Wo, Was, Wieviel, Wie, OK)
|
||||
INSERT INTO Ausgaben (Datum, Wo, Was, Wieviel, Wie, TYP, OK)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`;
|
||||
|
||||
const [result] = await pool.query<ResultSetHeader>(query, [
|
||||
Datum,
|
||||
WochTag,
|
||||
Wo,
|
||||
Was,
|
||||
parseFloat(Wieviel),
|
||||
Wie,
|
||||
TYP,
|
||||
OK || 0,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user