base commit

This commit is contained in:
@kirill.komarov
2026-04-29 20:23:30 +05:00
parent f26223091a
commit 123d86091d
25 changed files with 525 additions and 159 deletions
+19 -10
View File
@@ -89,8 +89,14 @@ export async function registerAdminProductRoutes(
return
}
let quantity = null
if (!(body.quantity === undefined || body.quantity === null || body.quantity === '')) {
let quantity = 0
if (!inStock) {
quantity = 1
} else {
if (body.quantity === undefined || body.quantity === null || body.quantity === '') {
reply.code(400).send({ error: 'Укажите количество' })
return
}
const n = Number(body.quantity)
if (!Number.isFinite(n) || n < 0) {
reply.code(400).send({ error: 'Некорректное количество (quantity ≥ 0)' })
@@ -162,15 +168,15 @@ export async function registerAdminProductRoutes(
if (body.quantity !== undefined) {
const v = body.quantity
if (v === null || v === '') {
data.quantity = null
} else {
const n = Number(v)
if (!Number.isFinite(n) || n < 0) {
reply.code(400).send({ error: 'Некорректное количество (quantity ≥ 0)' })
return
}
data.quantity = Math.floor(n)
reply.code(400).send({ error: 'Укажите количество' })
return
}
const n = Number(v)
if (!Number.isFinite(n) || n < 0) {
reply.code(400).send({ error: 'Некорректное количество (quantity ≥ 0)' })
return
}
data.quantity = Math.floor(n)
}
if (body.materials !== undefined) {
data.materials = JSON.stringify(parseMaterialsInput(body.materials))
@@ -209,6 +215,9 @@ export async function registerAdminProductRoutes(
if (nextInStock && data.leadTimeDays !== undefined) {
data.leadTimeDays = null
}
if (!nextInStock) {
data.quantity = 1
}
const imagesUpdate =
body.imageUrls !== undefined
+2 -2
View File
@@ -29,7 +29,7 @@ export async function registerPublicCatalogRoutes(fastify, { mapProductForApi }
const priceMaxParsed = typeof priceMaxRaw === 'string' ? Number(priceMaxRaw) : Number(priceMaxRaw)
const priceMax = Number.isFinite(priceMaxParsed) && priceMaxParsed >= 0 ? Math.floor(priceMaxParsed) : null
const where = { published: true }
const where = { published: true, quantity: { gt: 0 } }
if (typeof categorySlug === 'string' && categorySlug.length > 0) {
where.category = { slug: categorySlug }
}
@@ -70,7 +70,7 @@ export async function registerPublicCatalogRoutes(fastify, { mapProductForApi }
fastify.get('/api/products/:id', async (request, reply) => {
const { id } = request.params
const product = await prisma.product.findFirst({
where: { id, published: true },
where: { id, published: true, quantity: { gt: 0 } },
include: { category: true, images: { orderBy: { sort: 'asc' } } },
})
if (!product) {