From 5894e13d67f59022a96bab4396063720a38fdbe1 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 18 Jul 2025 17:17:47 +0300 Subject: [PATCH] feat(database): enhance getItemsByUrl to include core and selected custom properties --- src/lib/database.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib/database.ts b/src/lib/database.ts index f682909..f4c5efc 100644 --- a/src/lib/database.ts +++ b/src/lib/database.ts @@ -66,11 +66,31 @@ export async function getItemsByUrl(url: string): Promise { const items: Item[] = []; for (const dbItem of urlRecord.items) { - // Get all properties for this globalItemId - const itemProperties = await tx.itemProperty.findMany({ - where: { globalItemId: dbItem.globalItemId }, + // Get core properties (name, description) - these should always be included + const corePropertyNames = ['name', 'description']; + const coreProperties = await tx.property.findMany({ + where: { name: { in: corePropertyNames } } + }); + const corePropertyIds = coreProperties.map(p => p.id); + + // Get selected custom properties for this URL + const selectedPropertiesForUrl = await tx.selectedProperty.findMany({ + where: { urlId: urlRecord.id }, include: { property: true } }); + const selectedCustomPropertyIds = selectedPropertiesForUrl.map(sp => sp.propertyId); + + // Combine core properties with selected custom properties + const allowedPropertyIds = [...corePropertyIds, ...selectedCustomPropertyIds]; + + // Get properties for this globalItemId, including core properties and selected custom properties + const itemProperties = await tx.itemProperty.findMany({ + where: { + globalItemId: dbItem.globalItemId, + propertyId: { in: allowedPropertyIds } + }, + include: { property: true } + }); // Separate core properties from custom properties const customProperties: Record = {};