feat(database): enhance getItemsByUrl to include core and selected custom properties
This commit is contained in:
parent
24c97670cc
commit
5894e13d67
1 changed files with 23 additions and 3 deletions
|
@ -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 }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue