From 013c05fb026998ae67e63f6dd03999c63667c545 Mon Sep 17 00:00:00 2001 From: Bivekich Date: Thu, 10 Jul 2025 10:28:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=80=D0=B5=D0=B7=D0=BE=D0=BB=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B8=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B8=20=D0=B0=D0=BA=D1=81=D0=B5=D1=81?= =?UTF-8?q?=D1=81=D1=83=D0=B0=D1=80=D0=BD=D1=8B=D1=85=20=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2.=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D0=BE=D0=BD=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD=D1=8F=D1=8E=D1=82=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=B8=D0=B7=20=D0=B4=D0=B2=D1=83=D1=85=20=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=BD=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B8,=20?= =?UTF-8?q?=D1=87=D1=82=D0=BE=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D1=82=D1=83=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE?= =?UTF-8?q?=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0=D1=85.=20=D0=98=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B8=D0=BF=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D0=B0=D1=85=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=BC=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=B0=D0=BC.=20=D0=AD?= =?UTF-8?q?=D1=82=D0=BE=20=D0=BF=D0=BE=D0=B2=D1=8B=D1=88=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B3=D0=B8=D0=B1=D0=BA=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D0=B7?= =?UTF-8?q?=D0=B0=D0=B8=D0=BC=D0=BE=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=20API.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/graphql/resolvers.ts | 56 ++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/lib/graphql/resolvers.ts b/src/lib/graphql/resolvers.ts index 51fa1df..279b921 100644 --- a/src/lib/graphql/resolvers.ts +++ b/src/lib/graphql/resolvers.ts @@ -575,18 +575,30 @@ export const resolvers = { }) }, relatedProducts: async (parent: { id: string }) => { - const product = await prisma.product.findUnique({ - where: { id: parent.id }, - include: { relatedProducts: { include: { images: { orderBy: { order: 'asc' } } } } } - }) - return product?.relatedProducts || [] + const product = await prisma.product.findUnique({ + where: { id: parent.id }, + include: { + products_RelatedProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_RelatedProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } + } + }) + // Объединяем связанные товары из обеих сторон связи + const relatedA = product?.products_RelatedProducts_A || [] + const relatedB = product?.products_RelatedProducts_B || [] + return [...relatedA, ...relatedB] }, accessoryProducts: async (parent: { id: string }) => { - const product = await prisma.product.findUnique({ - where: { id: parent.id }, - include: { accessoryProducts: { include: { images: { orderBy: { order: 'asc' } } } } } - }) - return product?.accessoryProducts || [] + const product = await prisma.product.findUnique({ + where: { id: parent.id }, + include: { + products_AccessoryProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } + } + }) + // Объединяем аксессуары из обеих сторон связи + const accessoryA = product?.products_AccessoryProducts_A || [] + const accessoryB = product?.products_AccessoryProducts_B || [] + return [...accessoryA, ...accessoryB] } }, @@ -855,8 +867,10 @@ export const resolvers = { } }, characteristics: { include: { characteristic: true } }, - relatedProducts: { include: { images: { orderBy: { order: 'asc' } } } }, - accessoryProducts: { include: { images: { orderBy: { order: 'asc' } } } } + products_RelatedProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_RelatedProducts_B: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } } }) } catch (error) { @@ -879,8 +893,10 @@ export const resolvers = { } }, characteristics: { include: { characteristic: true } }, - relatedProducts: { include: { images: { orderBy: { order: 'asc' } } } }, - accessoryProducts: { include: { images: { orderBy: { order: 'asc' } } } } + products_RelatedProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_RelatedProducts_B: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } } }) } catch (error) { @@ -4492,8 +4508,10 @@ export const resolvers = { } }, characteristics: { include: { characteristic: true } }, - relatedProducts: { include: { images: { orderBy: { order: 'asc' } } } }, - accessoryProducts: { include: { images: { orderBy: { order: 'asc' } } } } + products_RelatedProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_RelatedProducts_B: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } } }) @@ -4562,8 +4580,10 @@ export const resolvers = { } }, characteristics: { include: { characteristic: true } }, - relatedProducts: { include: { images: { orderBy: { order: 'asc' } } } }, - accessoryProducts: { include: { images: { orderBy: { order: 'asc' } } } } + products_RelatedProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_RelatedProducts_B: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_A: { include: { images: { orderBy: { order: 'asc' } } } }, + products_AccessoryProducts_B: { include: { images: { orderBy: { order: 'asc' } } } } } })