final
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user