update goods
This commit is contained in:
@@ -107,8 +107,12 @@ export async function registerAdminProductRoutes(fastify) {
|
||||
return
|
||||
}
|
||||
const priceCents = Number(body.priceCents)
|
||||
if (!Number.isFinite(priceCents) || priceCents < 0) {
|
||||
reply.code(400).send({ error: 'Некорректная цена (priceCents ≥ 0)' })
|
||||
if (!Number.isFinite(priceCents) || priceCents <= 0) {
|
||||
reply.code(400).send({ error: 'Цена должна быть больше 0' })
|
||||
return
|
||||
}
|
||||
if (priceCents > 10_000_00) {
|
||||
reply.code(400).send({ error: 'Цена не может превышать 10 000 ₽' })
|
||||
return
|
||||
}
|
||||
const exists = await prisma.product.findUnique({ where: { slug } })
|
||||
@@ -118,11 +122,11 @@ export async function registerAdminProductRoutes(fastify) {
|
||||
}
|
||||
|
||||
const n = Number(body.quantity)
|
||||
if (!Number.isFinite(n) || n < 0) {
|
||||
reply.code(400).send({ error: 'Некорректное количество (quantity ≥ 0)' })
|
||||
if (!Number.isInteger(n) || n < 0 || n > 10) {
|
||||
reply.code(400).send({ error: 'Количество — целое число от 0 до 10' })
|
||||
return
|
||||
}
|
||||
const quantity = Math.floor(n)
|
||||
const quantity = n
|
||||
|
||||
const product = await prisma.product.create({
|
||||
data: {
|
||||
@@ -184,19 +188,23 @@ export async function registerAdminProductRoutes(fastify) {
|
||||
}
|
||||
if (body.quantity !== undefined) {
|
||||
const n = Number(body.quantity)
|
||||
if (!Number.isFinite(n) || n < 0) {
|
||||
reply.code(400).send({ error: 'Некорректное количество (quantity ≥ 0)' })
|
||||
if (!Number.isInteger(n) || n < 0 || n > 10) {
|
||||
reply.code(400).send({ error: 'Количество — целое число от 0 до 10' })
|
||||
return
|
||||
}
|
||||
data.quantity = Math.floor(n)
|
||||
data.quantity = n
|
||||
}
|
||||
if (body.materials !== undefined) {
|
||||
data.materials = JSON.stringify(request.server.parseMaterialsInput(body.materials))
|
||||
}
|
||||
if (body.priceCents !== undefined) {
|
||||
const p = Number(body.priceCents)
|
||||
if (!Number.isFinite(p) || p < 0) {
|
||||
reply.code(400).send({ error: 'Некорректная цена' })
|
||||
if (!Number.isFinite(p) || p <= 0) {
|
||||
reply.code(400).send({ error: 'Цена должна быть больше 0' })
|
||||
return
|
||||
}
|
||||
if (p > 10_000_00) {
|
||||
reply.code(400).send({ error: 'Цена не может превышать 10 000 ₽' })
|
||||
return
|
||||
}
|
||||
data.priceCents = Math.round(p)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 126 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 52 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 104 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user