move criteria for seo url

This commit is contained in:
Björn Meyer 2023-09-07 13:37:40 +02:00
parent 06bae60b1a
commit 6a48709c61
5 changed files with 74 additions and 43 deletions

View File

@ -4,42 +4,45 @@ type schemas = components['schemas'];
type operationsWithoutOriginal = Omit< type operationsWithoutOriginal = Omit<
operations, operations,
| 'addLineItem'
| 'deleteLineItem'
| 'readCart'
| 'readCategory' | 'readCategory'
| 'readCategoryList' | 'readCategoryList'
| 'readNavigation' | 'readNavigation'
| 'readProduct' | 'readProduct'
| 'readProductCrossSellings' | 'readProductCrossSellings'
| 'readProductListing' | 'readProductListing'
| 'readSeoUrl'
| 'searchPage' | 'searchPage'
| 'addLineItem'
| 'readCart'
| 'deleteLineItem'
>; >;
export type extendedPaths = export type extendedPaths =
| 'addLineItem post /checkout/cart/line-item'
| 'deleteLineItem delete /checkout/cart/line-item?id[]={ids}'
| 'readCart get /checkout/cart?name'
| 'readCategory post /category/{navigationId}?slots' | 'readCategory post /category/{navigationId}?slots'
| 'readCategoryList post /category' | 'readCategoryList post /category'
| 'readNavigation post /navigation/{activeId}/{rootId} sw-include-seo-urls' | 'readNavigation post /navigation/{activeId}/{rootId} sw-include-seo-urls'
| 'readProduct post /product' | 'readProduct post /product'
| 'readProductCrossSellings post /product/{productId}/cross-selling' | 'readProductCrossSellings post /product/{productId}/cross-selling'
| 'readProductListing post /product-listing/{categoryId}' | 'readProductListing post /product-listing/{categoryId}'
| 'readSeoUrl post /seo-url'
| 'searchPage post /search' | 'searchPage post /search'
| 'addLineItem post /checkout/cart/line-item'
| 'readCart get /checkout/cart?name'
| 'deleteLineItem delete /checkout/cart/line-item?id[]={ids}'
| operationPaths; | operationPaths;
export type extendedOperations = operationsWithoutOriginal & { export type extendedOperations = operationsWithoutOriginal & {
addLineItem: extendedAddLineItem;
deleteLineItem: extendedDeleteLineItem;
readCart: extendedReadCart;
readCategory: extendedReadCategory; readCategory: extendedReadCategory;
readCategoryList: extendedReadCategoryList; readCategoryList: extendedReadCategoryList;
readNavigation: extendedReadNavigation; readNavigation: extendedReadNavigation;
readProduct: extendedReadProduct; readProduct: extendedReadProduct;
readProductCrossSellings: extendedReadProductCrossSellings; readProductCrossSellings: extendedReadProductCrossSellings;
readProductListing: extendedReadProductListing; readProductListing: extendedReadProductListing;
readSeoUrl: extendedReadSeoUrl;
searchPage: extendedSearchPage; searchPage: extendedSearchPage;
addLineItem: extendedAddLineItem;
readCart: extendedReadCart;
deleteLineItem: extendedDeleteLineItem;
}; };
export type messageKeys = export type messageKeys =
@ -133,11 +136,18 @@ export type ExtendedCategory = Omit<schemas['Category'], 'children' | 'seoUrls'
cmsPage?: ExtendedCmsPage; cmsPage?: ExtendedCmsPage;
}; };
export type ExtendedCriteriaFilter = {
field?: string;
type: string;
value?: string | boolean | null;
};
export type ExtendedCriteria = Omit<schemas['Criteria'], 'filter'> & { export type ExtendedCriteria = Omit<schemas['Criteria'], 'filter'> & {
filter?: { filter?: {
field: string; field?: string;
type: string; type: string;
value: string | boolean | null; value?: string | boolean | null;
queries?: ExtendedCriteriaFilter[];
}[]; }[];
}; };
@ -359,6 +369,25 @@ type extendedReadProductListing = {
}; };
}; };
type extendedReadSeoUrl = {
requestBody?: {
content: {
'application/json': ExtendedCriteria;
};
};
responses: {
/** Entity search result containing seo urls. */
200: {
content: {
'application/json': {
elements?: components['schemas']['SeoUrl'][];
} & components['schemas']['EntitySearchResult'];
};
};
404: components['responses']['404'];
};
};
type extendedCartItems = components['schemas']['ArrayStruct'] & { type extendedCartItems = components['schemas']['ArrayStruct'] & {
items?: Partial<ExtendedLineItem>[]; items?: Partial<ExtendedLineItem>[];
}; };

View File

@ -64,7 +64,7 @@ export async function requestCategory(
try { try {
return await getApiClient().invoke('readCategory post /category/{navigationId}?slots', { return await getApiClient().invoke('readCategory post /category/{navigationId}?slots', {
navigationId: categoryId, navigationId: categoryId,
criteria ...criteria
}); });
} catch (error) { } catch (error) {
if (error instanceof ApiClientError) { if (error instanceof ApiClientError) {
@ -167,35 +167,10 @@ export async function requestSeoUrls(routeName: RouteNames, page: number = 1, li
} }
export async function requestSeoUrl( export async function requestSeoUrl(
handle: string, criteria: Partial<ExtendedCriteria>
page: number = 1,
limit: number = 1
): Promise<SeoURLResultSW | undefined> { ): Promise<SeoURLResultSW | undefined> {
try { try {
const criteriaSeoUrls = { return await getApiClient().invoke('readSeoUrl post /seo-url', criteria);
page: page,
limit: limit,
filter: [
{
type: 'multi',
operator: 'or',
queries: [
{
type: 'equals',
field: 'seoPathInfo',
value: handle + '/'
},
{
type: 'equals',
field: 'seoPathInfo',
value: handle
}
]
}
]
};
// @ts-ignore
return await getApiClient().invoke('readSeoUrl post /seo-url', criteriaSeoUrls);
} catch (error) { } catch (error) {
if (error instanceof ApiClientError) { if (error instanceof ApiClientError) {
console.error(error); console.error(error);

View File

@ -214,6 +214,31 @@ export function getDefaultCrossSellingCriteria(page: number = 1, limit: number =
}; };
} }
export function getSeoUrlCriteria(handle: string, page: number = 1, limit: number = 1) {
return {
page: page,
limit: limit,
filter: [
{
type: 'multi',
operator: 'or',
queries: [
{
type: 'equals',
field: 'seoPathInfo',
value: handle + '/'
},
{
type: 'equals',
field: 'seoPathInfo',
value: handle
}
]
}
]
};
}
export function getSortingCriteria(sortKey?: string, reverse?: boolean) { export function getSortingCriteria(sortKey?: string, reverse?: boolean) {
switch (true) { switch (true) {
case sortKey === 'CREATED_AT' && reverse === true: case sortKey === 'CREATED_AT' && reverse === true:

View File

@ -22,6 +22,7 @@ import {
getDefaultProductsCriteria, getDefaultProductsCriteria,
getDefaultSearchProductsCriteria, getDefaultSearchProductsCriteria,
getDefaultSubCategoriesCriteria, getDefaultSubCategoriesCriteria,
getSeoUrlCriteria,
getSortingCriteria getSortingCriteria
} from './criteria'; } from './criteria';
import { import {
@ -81,7 +82,8 @@ export async function getPage(handle: string | []): Promise<Page | undefined> {
export async function getFirstSeoUrlElement( export async function getFirstSeoUrlElement(
handle: string handle: string
): Promise<ApiSchemas['SeoUrl'] | undefined> { ): Promise<ApiSchemas['SeoUrl'] | undefined> {
const seoURL = await requestSeoUrl(handle); const seoURLCriteria = getSeoUrlCriteria(handle);
const seoURL = await requestSeoUrl(seoURLCriteria);
if (seoURL && seoURL.elements && seoURL.elements.length > 0 && seoURL.elements[0]) { if (seoURL && seoURL.elements && seoURL.elements.length > 0 && seoURL.elements[0]) {
return seoURL.elements[0]; return seoURL.elements[0];
} }

View File

@ -11,10 +11,10 @@ export type ProductListingCriteria = {
} & Omit<ApiSchemas['ProductListingCriteria'], 'filter'> & } & Omit<ApiSchemas['ProductListingCriteria'], 'filter'> &
ExtendedCriteria; ExtendedCriteria;
export type RouteNames = export type RouteNames =
| 'frontend.navigation.page'
| 'frontend.detail.page'
| 'frontend.account.customer-group-registration.page' | 'frontend.account.customer-group-registration.page'
| 'frontend.landing.page'; | 'frontend.detail.page'
| 'frontend.landing.page'
| 'frontend.navigation.page';
/** Return Types */ /** Return Types */
export type CategoryListingResultSW = { export type CategoryListingResultSW = {