use common buildURL function
This commit is contained in:
parent
116dccd12a
commit
dcb76a3047
|
@ -1,4 +1,4 @@
|
||||||
import { Model } from '../../model';
|
import { Model, ModelID } from '../../model';
|
||||||
import { MetaData, PostStatus } from '../../shared-types';
|
import { MetaData, PostStatus } from '../../shared-types';
|
||||||
import {
|
import {
|
||||||
CatalogVisibility,
|
CatalogVisibility,
|
||||||
|
@ -13,6 +13,14 @@ import {
|
||||||
*/
|
*/
|
||||||
export type ProductSearchParams = { search: string };
|
export type ProductSearchParams = { search: string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A common URL builder.
|
||||||
|
*
|
||||||
|
* @param {ModelID} id the id of the product.
|
||||||
|
* @return {string} RESTful Url.
|
||||||
|
*/
|
||||||
|
export const buildProductURL = ( id: ModelID ) => '/wc/v3/products/' + id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base for all product types.
|
* The base for all product types.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { HTTPClient } from '../../../http';
|
import { HTTPClient } from '../../../http';
|
||||||
import { ModelRepository } from '../../../framework';
|
import { ModelRepository } from '../../../framework';
|
||||||
import {
|
import {
|
||||||
|
buildProductURL,
|
||||||
ExternalProduct,
|
ExternalProduct,
|
||||||
ModelID,
|
|
||||||
CreatesExternalProducts,
|
CreatesExternalProducts,
|
||||||
DeletesExternalProducts,
|
DeletesExternalProducts,
|
||||||
ListsExternalProducts,
|
ListsExternalProducts,
|
||||||
|
@ -41,8 +41,6 @@ export function externalProductRESTRepository( httpClient: HTTPClient ): ListsEx
|
||||||
& ReadsExternalProducts
|
& ReadsExternalProducts
|
||||||
& UpdatesExternalProducts
|
& UpdatesExternalProducts
|
||||||
& DeletesExternalProducts {
|
& DeletesExternalProducts {
|
||||||
const buildURL = ( id: ModelID ) => '/wc/v3/products/' + id;
|
|
||||||
|
|
||||||
const external = createProductExternalTransformation();
|
const external = createProductExternalTransformation();
|
||||||
const salesTax = createProductSalesTaxTransformation();
|
const salesTax = createProductSalesTaxTransformation();
|
||||||
const upsells = createProductUpSellsTransformation();
|
const upsells = createProductUpSellsTransformation();
|
||||||
|
@ -57,8 +55,8 @@ export function externalProductRESTRepository( httpClient: HTTPClient ): ListsEx
|
||||||
return new ModelRepository(
|
return new ModelRepository(
|
||||||
restList< ExternalProductRepositoryParams >( () => '/wc/v3/products', ExternalProduct, httpClient, transformer ),
|
restList< ExternalProductRepositoryParams >( () => '/wc/v3/products', ExternalProduct, httpClient, transformer ),
|
||||||
restCreate< ExternalProductRepositoryParams >( () => '/wc/v3/products', ExternalProduct, httpClient, transformer ),
|
restCreate< ExternalProductRepositoryParams >( () => '/wc/v3/products', ExternalProduct, httpClient, transformer ),
|
||||||
restRead< ExternalProductRepositoryParams >( buildURL, ExternalProduct, httpClient, transformer ),
|
restRead< ExternalProductRepositoryParams >( buildProductURL, ExternalProduct, httpClient, transformer ),
|
||||||
restUpdate< ExternalProductRepositoryParams >( buildURL, ExternalProduct, httpClient, transformer ),
|
restUpdate< ExternalProductRepositoryParams >( buildProductURL, ExternalProduct, httpClient, transformer ),
|
||||||
restDelete< ExternalProductRepositoryParams >( buildURL, httpClient ),
|
restDelete< ExternalProductRepositoryParams >( buildProductURL, httpClient ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { HTTPClient } from '../../../http';
|
||||||
import { ModelRepository } from '../../../framework';
|
import { ModelRepository } from '../../../framework';
|
||||||
import {
|
import {
|
||||||
SimpleProduct,
|
SimpleProduct,
|
||||||
ModelID,
|
buildProductURL,
|
||||||
CreatesSimpleProducts,
|
CreatesSimpleProducts,
|
||||||
DeletesSimpleProducts,
|
DeletesSimpleProducts,
|
||||||
ListsSimpleProducts,
|
ListsSimpleProducts,
|
||||||
|
@ -44,8 +44,6 @@ export function simpleProductRESTRepository( httpClient: HTTPClient ): ListsSimp
|
||||||
& ReadsSimpleProducts
|
& ReadsSimpleProducts
|
||||||
& UpdatesSimpleProducts
|
& UpdatesSimpleProducts
|
||||||
& DeletesSimpleProducts {
|
& DeletesSimpleProducts {
|
||||||
const buildURL = ( id: ModelID ) => '/wc/v3/products/' + id;
|
|
||||||
|
|
||||||
const crossSells = createProductCrossSellsTransformation();
|
const crossSells = createProductCrossSellsTransformation();
|
||||||
const delivery = createProductDeliveryTransformation();
|
const delivery = createProductDeliveryTransformation();
|
||||||
const inventory = createProductInventoryTransformation();
|
const inventory = createProductInventoryTransformation();
|
||||||
|
@ -66,8 +64,8 @@ export function simpleProductRESTRepository( httpClient: HTTPClient ): ListsSimp
|
||||||
return new ModelRepository(
|
return new ModelRepository(
|
||||||
restList< SimpleProductRepositoryParams >( () => '/wc/v3/products', SimpleProduct, httpClient, transformer ),
|
restList< SimpleProductRepositoryParams >( () => '/wc/v3/products', SimpleProduct, httpClient, transformer ),
|
||||||
restCreate< SimpleProductRepositoryParams >( () => '/wc/v3/products', SimpleProduct, httpClient, transformer ),
|
restCreate< SimpleProductRepositoryParams >( () => '/wc/v3/products', SimpleProduct, httpClient, transformer ),
|
||||||
restRead< SimpleProductRepositoryParams >( buildURL, SimpleProduct, httpClient, transformer ),
|
restRead< SimpleProductRepositoryParams >( buildProductURL, SimpleProduct, httpClient, transformer ),
|
||||||
restUpdate< SimpleProductRepositoryParams >( buildURL, SimpleProduct, httpClient, transformer ),
|
restUpdate< SimpleProductRepositoryParams >( buildProductURL, SimpleProduct, httpClient, transformer ),
|
||||||
restDelete< SimpleProductRepositoryParams >( buildURL, httpClient ),
|
restDelete< SimpleProductRepositoryParams >( buildProductURL, httpClient ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue