feat(database): enhance getItemsByUrl to include core and selected custom properties

This commit is contained in:
ryan 2025-07-18 17:17:47 +03:00
parent 24c97670cc
commit 5894e13d67

View file

@ -66,9 +66,29 @@ export async function getItemsByUrl(url: string): Promise<Item[]> {
const items: Item[] = []; const items: Item[] = [];
for (const dbItem of urlRecord.items) { for (const dbItem of urlRecord.items) {
// Get all properties for this 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({ const itemProperties = await tx.itemProperty.findMany({
where: { globalItemId: dbItem.globalItemId }, where: {
globalItemId: dbItem.globalItemId,
propertyId: { in: allowedPropertyIds }
},
include: { property: true } include: { property: true }
}); });