From 300752e684b212f18df7aff94f605a8ab0d2ea8a Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:54:47 +0100 Subject: [PATCH] Specified primaryKey to avoid problems with videos + filterable categories for libraryitem --- src/core/graphql/meiliTypes.ts | 1 + src/helpers/meili.ts | 3 +++ src/syncho.ts | 5 ++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/graphql/meiliTypes.ts b/src/core/graphql/meiliTypes.ts index d5989d1..2796e27 100644 --- a/src/core/graphql/meiliTypes.ts +++ b/src/core/graphql/meiliTypes.ts @@ -18,6 +18,7 @@ export interface MeiliLibraryItem extends LibraryItemAttributesFragment { sortable_name: string; sortable_price: number | undefined; sortable_date: number | undefined; + filterable_categories: string[]; untangible_group_item: boolean; } diff --git a/src/helpers/meili.ts b/src/helpers/meili.ts index 8e5ca5a..89f55b8 100644 --- a/src/helpers/meili.ts +++ b/src/helpers/meili.ts @@ -75,6 +75,9 @@ const transformLibraryItem: TransformFunction = (data attributes.price?.currency?.data?.attributes && isDefined(attributes.price.amount) ? attributes.price.amount * attributes.price.currency.data.attributes.rate_to_usd : undefined, + filterable_categories: filterHasAttributes(attributes.categories?.data, [ + "attributes.short", + ] as const).map((category) => category.attributes.short), untangible_group_item: isUntangibleGroupItem(attributes.metadata?.[0]), ...attributes, }; diff --git a/src/syncho.ts b/src/syncho.ts index d9b69ba..ddd013e 100644 --- a/src/syncho.ts +++ b/src/syncho.ts @@ -7,7 +7,6 @@ export const synchronizeStrapiAndMeili = async (): Promise => { const meili = getMeili(); const indexes = await meili.getIndexes(); await Promise.all(indexes.results.map(async (index) => index.delete())); - // [ LIBRARY ITEMS ] @@ -19,7 +18,7 @@ export const synchronizeStrapiAndMeili = async (): Promise => { ), ["title", "subtitle", "descriptions"], ["sortable_name", "sortable_date", "sortable_price"], - ["primary", "root_item", "id", "untangible_group_item"] + ["primary", "root_item", "id", "untangible_group_item", "filterable_categories"] ); // [ CONTENT ] @@ -94,7 +93,7 @@ const processIndex = async ( const meili = getMeili(); if (data && data.length > 0) { - await meili.createIndex(indexName); + await meili.createIndex(indexName, { primaryKey: "id" }); const index = meili.index(indexName); index.updateSettings({ searchableAttributes: searchableAttributes as string[],