mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 16:07:01 +00:00
move criteria for seo url
This commit is contained in:
parent
06bae60b1a
commit
6a48709c61
@ -4,42 +4,45 @@ type schemas = components['schemas'];
|
||||
|
||||
type operationsWithoutOriginal = Omit<
|
||||
operations,
|
||||
| 'addLineItem'
|
||||
| 'deleteLineItem'
|
||||
| 'readCart'
|
||||
| 'readCategory'
|
||||
| 'readCategoryList'
|
||||
| 'readNavigation'
|
||||
| 'readProduct'
|
||||
| 'readProductCrossSellings'
|
||||
| 'readProductListing'
|
||||
| 'readSeoUrl'
|
||||
| 'searchPage'
|
||||
| 'addLineItem'
|
||||
| 'readCart'
|
||||
| 'deleteLineItem'
|
||||
>;
|
||||
|
||||
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'
|
||||
| 'readCategoryList post /category'
|
||||
| 'readNavigation post /navigation/{activeId}/{rootId} sw-include-seo-urls'
|
||||
| 'readProduct post /product'
|
||||
| 'readProductCrossSellings post /product/{productId}/cross-selling'
|
||||
| 'readProductListing post /product-listing/{categoryId}'
|
||||
| 'readSeoUrl post /seo-url'
|
||||
| 'searchPage post /search'
|
||||
| 'addLineItem post /checkout/cart/line-item'
|
||||
| 'readCart get /checkout/cart?name'
|
||||
| 'deleteLineItem delete /checkout/cart/line-item?id[]={ids}'
|
||||
| operationPaths;
|
||||
|
||||
export type extendedOperations = operationsWithoutOriginal & {
|
||||
addLineItem: extendedAddLineItem;
|
||||
deleteLineItem: extendedDeleteLineItem;
|
||||
readCart: extendedReadCart;
|
||||
readCategory: extendedReadCategory;
|
||||
readCategoryList: extendedReadCategoryList;
|
||||
readNavigation: extendedReadNavigation;
|
||||
readProduct: extendedReadProduct;
|
||||
readProductCrossSellings: extendedReadProductCrossSellings;
|
||||
readProductListing: extendedReadProductListing;
|
||||
readSeoUrl: extendedReadSeoUrl;
|
||||
searchPage: extendedSearchPage;
|
||||
addLineItem: extendedAddLineItem;
|
||||
readCart: extendedReadCart;
|
||||
deleteLineItem: extendedDeleteLineItem;
|
||||
};
|
||||
|
||||
export type messageKeys =
|
||||
@ -133,11 +136,18 @@ export type ExtendedCategory = Omit<schemas['Category'], 'children' | 'seoUrls'
|
||||
cmsPage?: ExtendedCmsPage;
|
||||
};
|
||||
|
||||
export type ExtendedCriteriaFilter = {
|
||||
field?: string;
|
||||
type: string;
|
||||
value?: string | boolean | null;
|
||||
};
|
||||
|
||||
export type ExtendedCriteria = Omit<schemas['Criteria'], 'filter'> & {
|
||||
filter?: {
|
||||
field: string;
|
||||
field?: 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'] & {
|
||||
items?: Partial<ExtendedLineItem>[];
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ export async function requestCategory(
|
||||
try {
|
||||
return await getApiClient().invoke('readCategory post /category/{navigationId}?slots', {
|
||||
navigationId: categoryId,
|
||||
criteria
|
||||
...criteria
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof ApiClientError) {
|
||||
@ -167,35 +167,10 @@ export async function requestSeoUrls(routeName: RouteNames, page: number = 1, li
|
||||
}
|
||||
|
||||
export async function requestSeoUrl(
|
||||
handle: string,
|
||||
page: number = 1,
|
||||
limit: number = 1
|
||||
criteria: Partial<ExtendedCriteria>
|
||||
): Promise<SeoURLResultSW | undefined> {
|
||||
try {
|
||||
const criteriaSeoUrls = {
|
||||
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);
|
||||
return await getApiClient().invoke('readSeoUrl post /seo-url', criteria);
|
||||
} catch (error) {
|
||||
if (error instanceof ApiClientError) {
|
||||
console.error(error);
|
||||
|
@ -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) {
|
||||
switch (true) {
|
||||
case sortKey === 'CREATED_AT' && reverse === true:
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
getDefaultProductsCriteria,
|
||||
getDefaultSearchProductsCriteria,
|
||||
getDefaultSubCategoriesCriteria,
|
||||
getSeoUrlCriteria,
|
||||
getSortingCriteria
|
||||
} from './criteria';
|
||||
import {
|
||||
@ -81,7 +82,8 @@ export async function getPage(handle: string | []): Promise<Page | undefined> {
|
||||
export async function getFirstSeoUrlElement(
|
||||
handle: string
|
||||
): 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]) {
|
||||
return seoURL.elements[0];
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ export type ProductListingCriteria = {
|
||||
} & Omit<ApiSchemas['ProductListingCriteria'], 'filter'> &
|
||||
ExtendedCriteria;
|
||||
export type RouteNames =
|
||||
| 'frontend.navigation.page'
|
||||
| 'frontend.detail.page'
|
||||
| 'frontend.account.customer-group-registration.page'
|
||||
| 'frontend.landing.page';
|
||||
| 'frontend.detail.page'
|
||||
| 'frontend.landing.page'
|
||||
| 'frontend.navigation.page';
|
||||
|
||||
/** Return Types */
|
||||
export type CategoryListingResultSW = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user