Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix(client): sorting for store-api (#1018)
Browse files Browse the repository at this point in the history
* fix(client): adjust sorting within the store-api

* chore: remove internal interface from public contract

Co-authored-by: patzick <tomczyk.patryk@gmail.com>
  • Loading branch information
mkucmus and patzick authored Aug 13, 2020
1 parent 11cb80b commit 3564da4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 41 deletions.
34 changes: 0 additions & 34 deletions api/shopware-6-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ import { Currency } from '@shopware-pwa/commons/interfaces/models/system/currenc
import { Customer } from '@shopware-pwa/commons/interfaces/models/checkout/customer/Customer';
import { CustomerAddress } from '@shopware-pwa/commons/interfaces/models/checkout/customer/CustomerAddress';
import { CustomerRegistrationParams } from '@shopware-pwa/commons/interfaces/request/CustomerRegistrationParams';
import { EqualsAnyFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { EqualsFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { Grouping } from '@shopware-pwa/commons/interfaces/search/Grouping';
import { GuestOrderParams } from '@shopware-pwa/commons/interfaces/request/GuestOrderParams';
import { Includes } from '@shopware-pwa/commons/interfaces/search/SearchCriteria';
import { Language } from '@shopware-pwa/commons/interfaces/models/framework/language/Language';
import { MultiFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { NavigationResponse } from '@shopware-pwa/commons/interfaces/models/content/navigation/Navigation';
import { NotFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { Order } from '@shopware-pwa/commons/interfaces/models/checkout/order/Order';
import { PaymentMethod } from '@shopware-pwa/commons/interfaces/models/checkout/payment/PaymentMethod';
import { Product } from '@shopware-pwa/commons/interfaces/models/content/product/Product';
import { ProductListingResult } from '@shopware-pwa/commons/interfaces/response/ProductListingResult';
import { RangeFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { Salutation } from '@shopware-pwa/commons/interfaces/models/system/salutation/Salutation';
import { SearchCriteria } from '@shopware-pwa/commons/interfaces/search/SearchCriteria';
import { SearchResult } from '@shopware-pwa/commons/interfaces/response/SearchResult';
import { SessionContext } from '@shopware-pwa/commons/interfaces/response/SessionContext';
import { ShippingMethod } from '@shopware-pwa/commons/interfaces/models/checkout/shipping/ShippingMethod';
import { ShopwareAssociation } from '@shopware-pwa/commons/interfaces/search/Association';
import { StoreNavigationElement } from '@shopware-pwa/commons/interfaces/models/content/navigation/Navigation';

// @alpha
Expand Down Expand Up @@ -375,32 +367,6 @@ export interface ShopwareApiInstance {
update: (config?: ClientSettings) => void;
}

// @alpha @deprecated (undocumented)
export interface ShopwareParams {
// (undocumented)
associations?: ShopwareAssociation;
// (undocumented)
filter?: (NotFilter | MultiFilter | EqualsFilter | EqualsAnyFilter | RangeFilter)[];
// (undocumented)
grouping?: Grouping;
// (undocumented)
includes?: Includes;
// (undocumented)
limit?: number;
// (undocumented)
manufacturer?: string;
// (undocumented)
p?: number;
// (undocumented)
page?: number;
// (undocumented)
properties?: string;
// (undocumented)
sort?: string;
// (undocumented)
term?: string;
}

// @beta
export const update: (config?: ClientSettings) => void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe("SearchConverter - convertSearchCriteria", () => {
});
expect(paramsObject?.p).toEqual(1);
expect(paramsObject?.limit).toEqual(config.defaultPaginationLimit);
expect(paramsObject?.sort).toEqual("name-desc");
expect(paramsObject?.order).toEqual("name-desc");
});
it("should have sorting param in specific format if apiType is set to 'store' - default ascending", () => {
const paramsObject = convertSearchCriteria({
Expand All @@ -235,7 +235,7 @@ describe("SearchConverter - convertSearchCriteria", () => {
apiType: ApiType.store,
config,
});
expect(paramsObject?.sort).toEqual("name-asc");
expect(paramsObject?.order).toEqual("name-asc");
});
it("should have pagination and sort params", () => {
const paramsObject = convertSearchCriteria({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("ProductService - getCategoryProductsListing", () => {
mockedPost
).toBeCalledWith(
"/store-api/v3/product-listing/044a190a54ab4f06803909c3ee8063ef",
{ sort: "name-asc", limit: 10 }
{ order: "name-asc", limit: 10 }
);
expect(result).toHaveProperty("elements");
});
Expand Down
4 changes: 2 additions & 2 deletions packages/shopware-6-client/src/helpers/searchConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export enum ApiType {

/**
* @deprecated - that interface will be replaced with the new one from ShopwareSearchParams to follow the product-listing filters interface.
* @alpha
*/
export interface ShopwareParams {
p?: number; // p for page in store-api
page?: number;
limit?: number;
order?: string;
sort?: string;
term?: string;
filter?: (
Expand Down Expand Up @@ -131,7 +131,7 @@ export const convertSearchCriteria = ({
} else {
let order = sort.desc ? "desc" : "asc";
// TODO: https://github.com/DivanteLtd/shopware-pwa/issues/834
params.sort = sort.name || `${sort.field}-${order}`;
params.order = sort.name || `${sort.field}-${order}`;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/shopware-6-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export * from "./services/pluginService";
export * from "./services/searchService";
export * from "./services/formsService";

export { ShopwareParams } from "./helpers/searchConverter";

/**
* @beta
*/
Expand Down

0 comments on commit 3564da4

Please sign in to comment.