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