Filter store to only show artworks with GBP prices set
The store was fetching all 2,324 artworks and filtering client-side, resulting in 656 items shown (including imported catalog entries with only USD prices and no images). Now filters at the Directus API level for artworks with price_gbp set, showing only the 19 actual store items. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2523a304cf
commit
94894181ea
|
|
@ -13,11 +13,8 @@ export const revalidate = 0;
|
|||
|
||||
async function getShopItems(): Promise<{ available: Artwork[]; sold: Artwork[] }> {
|
||||
try {
|
||||
const allArtworks = await getArtworks({});
|
||||
const available = allArtworks.filter(
|
||||
(a) => a.status === 'published' && a.price && a.price > 0
|
||||
);
|
||||
const sold = allArtworks.filter((a) => a.status === 'sold');
|
||||
const available = await getArtworks({ status: 'published', forSale: true });
|
||||
const sold = await getArtworks({ status: 'sold', forSale: true });
|
||||
return { available, sold };
|
||||
} catch (error) {
|
||||
console.error('Error fetching shop items:', error);
|
||||
|
|
|
|||
|
|
@ -238,10 +238,14 @@ export async function getArtworks(options?: {
|
|||
series?: string;
|
||||
limit?: number;
|
||||
fields?: string[];
|
||||
forSale?: boolean;
|
||||
}): Promise<Artwork[]> {
|
||||
const filter: Record<string, unknown> = {};
|
||||
if (options?.status) filter.status = { _eq: options.status };
|
||||
if (options?.series) filter.series = { _eq: options.series };
|
||||
if (options?.forSale) {
|
||||
filter.price_gbp = { _nnull: true, _gt: 0 };
|
||||
}
|
||||
|
||||
const result = await directus.request(
|
||||
readItems('artworks', {
|
||||
|
|
|
|||
Loading…
Reference in New Issue