Interface: ProductsUpdateSupplier
This is the caller side of the contract.
Remarks
- The processUpdateRequest method converts the raw http request into an PatchProductsRequest
- The PatchProductsRequest is processed by the other system which returns the ProductDto for the patched product
- The provideUpdatedProduct method converts the ProductDto to a response that is suitable for the requesting system.
Methods
processProductsUpdateRequest
▸ processProductsUpdateRequest(request
): Promise
<{ fields?
: [{ field?: string; operation?: PatchOperation.Remove; } | { field?
: string
; operation?
: Append
; value?
: unknown
} | { field?
: string
; operation?
: Set
; value?
: unknown
}, ...(({ field?: string; operation?: PatchOperation.Remove; }) | Object | Object)[]] ; filters?
: [{ field?
: string
; operation?
: FilterOperation
; value?
: unknown
}, ...Object[]] }>
Handle the incoming request and transform it to a QueryProductsRequest.
Parameters
Name | Type | Description |
---|---|---|
request | Object | The raw http request to process. |
request.body? | string | - |
request.headers? | Record <string , string > | - |
request.method? | string | - |
request.url? | string | - |
Returns
Promise
<{ fields?
: [{ field?: string; operation?: PatchOperation.Remove; } | { field?
: string
; operation?
: Append
; value?
: unknown
} | { field?
: string
; operation?
: Set
; value?
: unknown
}, ...(({ field?: string; operation?: PatchOperation.Remove; }) | Object | Object)[]] ; filters?
: [{ field?
: string
; operation?
: FilterOperation
; value?
: unknown
}, ...Object[]] }>
The PatchProductsRequest
Example
Raw http request:
POST /product_id=1234
Content-Type: application/json
{
"name": "test",
"meta": {
"description": "A nice product"
}
}
PatchProductsRequest:
{
filters: [
{field: 'id', operation: FilterOperation.Equal, value: enforce<ProductDto["id"]>('1234')}
],
fields: [
{field: 'name', operation: PatchOperation.Set, value: enforce<ProductDto["name"]>('test')},
{field: 'description', operation: PatchOperation.Set, value: enforce<ProductDto["description"]>('A nice product')},
],
}
Defined in
src/contracts/patch-products/handler/products-update-supplier.ts:48
provideUpdatedProducts
▸ provideUpdatedProducts(products
): Promise
<{ body?
: string
; headers?
: Record
<string
, string
> ; statusCode?
: number
}>
Convert the updated products to valid http response.
Parameters
Name | Type | Description |
---|---|---|
products | { attributeValues? : Record <string , unknown > = ZAttributeValues; availability? : { amount?: number; stockId?: string; stockName?: string; attributeValues?: Record<string, unknown>; }[] ; description? : string ; details? : Record <string , string > ; grossPrice? : { value?: number; divisor?: number; currencyCode?: string; } ; gtin? : string ; id? : string ; images? : { url?: string; isDefault?: boolean; attributeValues?: Record<string, unknown>; }[] ; manufacturer? : string ; name? : string ; netPrice? : { value?: number; divisor?: number; currencyCode?: string; } ; sku? : string ; taxRate? : number ; variationParentId? : string ; weightInGrams? : number }[] | The updated products. |
Returns
Promise
<{ body?
: string
; headers?
: Record
<string
, string
> ; statusCode?
: number
}>
Defined in
src/contracts/patch-products/handler/products-update-supplier.ts:55