This commit is contained in:
root
2026-01-03 06:06:54 +00:00
parent d138dae2ca
commit eeaa9a66bb
16 changed files with 728 additions and 348 deletions

View File

@@ -71,7 +71,7 @@ export async function PUT(
}
const body = await request.json()
const { item, size, unit, ppu, imageUrl, startTime } = body
const { item, description, size, unit, ppu, priceChf, priceEur, wholesalePriceChf, wholesalePriceEur, imageUrl, startTime } = body
// Check if drop exists
const [existingRows] = await pool.execute(
@@ -95,6 +95,11 @@ export async function PUT(
values.push(item)
}
if (description !== undefined) {
updates.push('description = ?')
values.push(description || null)
}
if (size !== undefined) {
if (size <= 0) {
return NextResponse.json(
@@ -122,6 +127,50 @@ export async function PUT(
values.push(ppu)
}
if (priceChf !== undefined) {
if (priceChf !== null && priceChf < 0) {
return NextResponse.json(
{ error: 'Price CHF must be greater than or equal to 0' },
{ status: 400 }
)
}
updates.push('price_chf = ?')
values.push(priceChf !== null && priceChf !== '' ? priceChf : null)
}
if (priceEur !== undefined) {
if (priceEur !== null && priceEur < 0) {
return NextResponse.json(
{ error: 'Price EUR must be greater than or equal to 0' },
{ status: 400 }
)
}
updates.push('price_eur = ?')
values.push(priceEur !== null && priceEur !== '' ? priceEur : null)
}
if (wholesalePriceChf !== undefined) {
if (wholesalePriceChf !== null && wholesalePriceChf < 0) {
return NextResponse.json(
{ error: 'Wholesale price CHF must be greater than or equal to 0' },
{ status: 400 }
)
}
updates.push('wholesale_price_chf = ?')
values.push(wholesalePriceChf !== null && wholesalePriceChf !== '' ? wholesalePriceChf : null)
}
if (wholesalePriceEur !== undefined) {
if (wholesalePriceEur !== null && wholesalePriceEur < 0) {
return NextResponse.json(
{ error: 'Wholesale price EUR must be greater than or equal to 0' },
{ status: 400 }
)
}
updates.push('wholesale_price_eur = ?')
values.push(wholesalePriceEur !== null && wholesalePriceEur !== '' ? wholesalePriceEur : null)
}
if (imageUrl !== undefined) {
updates.push('image_url = ?')
values.push(imageUrl || null)