From 3d545244d433432a7d6383f32a0c5091f9dd3762 Mon Sep 17 00:00:00 2001 From: Jeremy Oustrich Date: Thu, 13 Oct 2022 12:22:03 -0400 Subject: [PATCH] API version 2. See https://docs.patch.io/#/changelog for changes (#79) --- package-lock.json | 4 +- package.json | 2 +- src/ApiClient.js | 5 +- src/api/EstimatesApi.js | 193 +++++++++++----- src/api/OrderLineItemsApi.js | 213 ++++++++++++++++++ src/api/OrdersApi.js | 91 ++++++-- src/api/ProjectsApi.js | 8 +- src/api/TechnologyTypesApi.js | 14 +- src/index.js | 5 +- src/model/Allocation.js | 50 ---- src/model/CreateAirShippingEstimateRequest.js | 2 +- src/model/CreateBitcoinEstimateRequest.js | 2 +- src/model/CreateEcommerceEstimateRequest.js | 2 +- src/model/CreateEthereumEstimateRequest.js | 2 +- src/model/CreateFlightEstimateRequest.js | 2 +- src/model/CreateHotelEstimateRequest.js | 2 +- src/model/CreateMassEstimateRequest.js | 2 +- src/model/CreateOrderLineItemRequest.js | 67 ++++++ src/model/CreateOrderRequest.js | 17 +- .../CreateRailShippingEstimateRequest.js | 2 +- .../CreateRoadShippingEstimateRequest.js | 2 +- src/model/CreateSeaShippingEstimateRequest.js | 2 +- src/model/CreateShippingEstimateRequest.js | 2 +- src/model/CreateSuccessResponse.js | 2 +- src/model/CreateVehicleEstimateRequest.js | 2 +- src/model/DeleteOrderLineItemResponse.js | 47 ++++ src/model/DeleteOrderResponse.js | 47 ++++ src/model/ErrorResponse.js | 2 +- src/model/Estimate.js | 2 +- src/model/EstimateListResponse.js | 2 +- src/model/EstimateResponse.js | 2 +- src/model/Highlight.js | 2 +- src/model/Inventory.js | 2 +- src/model/MetaIndexObject.js | 2 +- src/model/Order.js | 70 +----- src/model/OrderIssuedTo.js | 2 +- .../{OrderInventory.js => OrderLineItem.js} | 32 +-- ...toryProject.js => OrderLineItemProject.js} | 14 +- src/model/OrderLineItemResponse.js | 48 ++++ src/model/OrderListResponse.js | 2 +- src/model/OrderResponse.js | 2 +- src/model/ParentTechnologyType.js | 2 +- src/model/Photo.js | 2 +- src/model/PlaceOrderRequest.js | 2 +- src/model/Project.js | 51 +---- src/model/ProjectListRequest.js | 43 ---- src/model/ProjectListResponse.js | 2 +- src/model/ProjectResponse.js | 2 +- src/model/Sdg.js | 2 +- src/model/Standard.js | 2 +- src/model/TechnologyType.js | 2 +- src/model/TechnologyTypeListResponse.js | 2 +- src/model/UpdateOrderLineItemRequest.js | 58 +++++ test/integration/estimates.test.js | 2 +- test/integration/orders.test.js | 102 +++++++-- test/integration/projects.test.js | 6 +- yarn.lock | 5 - 57 files changed, 885 insertions(+), 373 deletions(-) create mode 100644 src/api/OrderLineItemsApi.js delete mode 100644 src/model/Allocation.js create mode 100644 src/model/CreateOrderLineItemRequest.js create mode 100644 src/model/DeleteOrderLineItemResponse.js create mode 100644 src/model/DeleteOrderResponse.js rename src/model/{OrderInventory.js => OrderLineItem.js} (68%) rename src/model/{OrderInventoryProject.js => OrderLineItemProject.js} (66%) create mode 100644 src/model/OrderLineItemResponse.js delete mode 100644 src/model/ProjectListRequest.js create mode 100644 src/model/UpdateOrderLineItemRequest.js diff --git a/package-lock.json b/package-lock.json index 46bdf43..ae08ba6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@patch-technology/patch", - "version": "1.24.2", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@patch-technology/patch", - "version": "1.24.2", + "version": "2.0.0", "license": "MIT", "dependencies": { "query-string": "^7.0.1", diff --git a/package.json b/package.json index d0d59a1..8848b27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.24.2", + "version": "2.0.0", "description": "Node.js wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/ApiClient.js b/src/ApiClient.js index b04fd6c..fa473bc 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -16,7 +16,8 @@ class ApiClient { }; this.defaultHeaders = { - 'User-Agent': 'patch-node/1.24.2' + 'User-Agent': 'patch-node/2.0.0', + 'Patch-Version': 2 }; /** diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index 3e21b2b..a6bc643 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -27,7 +27,12 @@ export default class EstimatesApi { this.apiClient = apiClient || ApiClient.instance; } - createAirShippingEstimateWithHttpInfo(createAirShippingEstimateRequest) { + createAirShippingEstimateWithHttpInfo( + createAirShippingEstimateRequest, + opts + ) { + opts = opts || {}; + const _createAirShippingEstimateRequest = CreateAirShippingEstimateRequest.constructFromObject( createAirShippingEstimateRequest, @@ -47,7 +52,9 @@ export default class EstimatesApi { let postBody = _createAirShippingEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -70,13 +77,16 @@ export default class EstimatesApi { ); } - createAirShippingEstimate(createAirShippingEstimateRequest) { + createAirShippingEstimate(createAirShippingEstimateRequest, opts) { return this.createAirShippingEstimateWithHttpInfo( - createAirShippingEstimateRequest + createAirShippingEstimateRequest, + opts ); } - createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest) { + createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest, opts) { + opts = opts || {}; + const _createBitcoinEstimateRequest = CreateBitcoinEstimateRequest.constructFromObject( createBitcoinEstimateRequest, @@ -96,7 +106,9 @@ export default class EstimatesApi { let postBody = _createBitcoinEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -119,11 +131,16 @@ export default class EstimatesApi { ); } - createBitcoinEstimate(createBitcoinEstimateRequest) { - return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest); + createBitcoinEstimate(createBitcoinEstimateRequest, opts) { + return this.createBitcoinEstimateWithHttpInfo( + createBitcoinEstimateRequest, + opts + ); } - createEcommerceEstimateWithHttpInfo(createEcommerceEstimateRequest) { + createEcommerceEstimateWithHttpInfo(createEcommerceEstimateRequest, opts) { + opts = opts || {}; + const _createEcommerceEstimateRequest = CreateEcommerceEstimateRequest.constructFromObject( createEcommerceEstimateRequest, @@ -143,7 +160,9 @@ export default class EstimatesApi { let postBody = _createEcommerceEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -166,13 +185,16 @@ export default class EstimatesApi { ); } - createEcommerceEstimate(createEcommerceEstimateRequest) { + createEcommerceEstimate(createEcommerceEstimateRequest, opts) { return this.createEcommerceEstimateWithHttpInfo( - createEcommerceEstimateRequest + createEcommerceEstimateRequest, + opts ); } - createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) { + createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest, opts) { + opts = opts || {}; + const _createEthereumEstimateRequest = CreateEthereumEstimateRequest.constructFromObject( createEthereumEstimateRequest, @@ -192,7 +214,9 @@ export default class EstimatesApi { let postBody = _createEthereumEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -215,13 +239,16 @@ export default class EstimatesApi { ); } - createEthereumEstimate(createEthereumEstimateRequest) { + createEthereumEstimate(createEthereumEstimateRequest, opts) { return this.createEthereumEstimateWithHttpInfo( - createEthereumEstimateRequest + createEthereumEstimateRequest, + opts ); } - createFlightEstimateWithHttpInfo(createFlightEstimateRequest) { + createFlightEstimateWithHttpInfo(createFlightEstimateRequest, opts) { + opts = opts || {}; + const _createFlightEstimateRequest = CreateFlightEstimateRequest.constructFromObject( createFlightEstimateRequest, @@ -241,7 +268,9 @@ export default class EstimatesApi { let postBody = _createFlightEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -264,11 +293,16 @@ export default class EstimatesApi { ); } - createFlightEstimate(createFlightEstimateRequest) { - return this.createFlightEstimateWithHttpInfo(createFlightEstimateRequest); + createFlightEstimate(createFlightEstimateRequest, opts) { + return this.createFlightEstimateWithHttpInfo( + createFlightEstimateRequest, + opts + ); } - createHotelEstimateWithHttpInfo(createHotelEstimateRequest) { + createHotelEstimateWithHttpInfo(createHotelEstimateRequest, opts) { + opts = opts || {}; + const _createHotelEstimateRequest = CreateHotelEstimateRequest.constructFromObject( createHotelEstimateRequest, @@ -288,7 +322,9 @@ export default class EstimatesApi { let postBody = _createHotelEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -311,11 +347,16 @@ export default class EstimatesApi { ); } - createHotelEstimate(createHotelEstimateRequest) { - return this.createHotelEstimateWithHttpInfo(createHotelEstimateRequest); + createHotelEstimate(createHotelEstimateRequest, opts) { + return this.createHotelEstimateWithHttpInfo( + createHotelEstimateRequest, + opts + ); } - createMassEstimateWithHttpInfo(createMassEstimateRequest) { + createMassEstimateWithHttpInfo(createMassEstimateRequest, opts) { + opts = opts || {}; + const _createMassEstimateRequest = CreateMassEstimateRequest.constructFromObject( createMassEstimateRequest, @@ -335,7 +376,9 @@ export default class EstimatesApi { let postBody = _createMassEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -358,11 +401,16 @@ export default class EstimatesApi { ); } - createMassEstimate(createMassEstimateRequest) { - return this.createMassEstimateWithHttpInfo(createMassEstimateRequest); + createMassEstimate(createMassEstimateRequest, opts) { + return this.createMassEstimateWithHttpInfo(createMassEstimateRequest, opts); } - createRailShippingEstimateWithHttpInfo(createRailShippingEstimateRequest) { + createRailShippingEstimateWithHttpInfo( + createRailShippingEstimateRequest, + opts + ) { + opts = opts || {}; + const _createRailShippingEstimateRequest = CreateRailShippingEstimateRequest.constructFromObject( createRailShippingEstimateRequest, @@ -382,7 +430,9 @@ export default class EstimatesApi { let postBody = _createRailShippingEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -405,13 +455,19 @@ export default class EstimatesApi { ); } - createRailShippingEstimate(createRailShippingEstimateRequest) { + createRailShippingEstimate(createRailShippingEstimateRequest, opts) { return this.createRailShippingEstimateWithHttpInfo( - createRailShippingEstimateRequest + createRailShippingEstimateRequest, + opts ); } - createRoadShippingEstimateWithHttpInfo(createRoadShippingEstimateRequest) { + createRoadShippingEstimateWithHttpInfo( + createRoadShippingEstimateRequest, + opts + ) { + opts = opts || {}; + const _createRoadShippingEstimateRequest = CreateRoadShippingEstimateRequest.constructFromObject( createRoadShippingEstimateRequest, @@ -431,7 +487,9 @@ export default class EstimatesApi { let postBody = _createRoadShippingEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -454,13 +512,19 @@ export default class EstimatesApi { ); } - createRoadShippingEstimate(createRoadShippingEstimateRequest) { + createRoadShippingEstimate(createRoadShippingEstimateRequest, opts) { return this.createRoadShippingEstimateWithHttpInfo( - createRoadShippingEstimateRequest + createRoadShippingEstimateRequest, + opts ); } - createSeaShippingEstimateWithHttpInfo(createSeaShippingEstimateRequest) { + createSeaShippingEstimateWithHttpInfo( + createSeaShippingEstimateRequest, + opts + ) { + opts = opts || {}; + const _createSeaShippingEstimateRequest = CreateSeaShippingEstimateRequest.constructFromObject( createSeaShippingEstimateRequest, @@ -480,7 +544,9 @@ export default class EstimatesApi { let postBody = _createSeaShippingEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -503,13 +569,16 @@ export default class EstimatesApi { ); } - createSeaShippingEstimate(createSeaShippingEstimateRequest) { + createSeaShippingEstimate(createSeaShippingEstimateRequest, opts) { return this.createSeaShippingEstimateWithHttpInfo( - createSeaShippingEstimateRequest + createSeaShippingEstimateRequest, + opts ); } - createShippingEstimateWithHttpInfo(createShippingEstimateRequest) { + createShippingEstimateWithHttpInfo(createShippingEstimateRequest, opts) { + opts = opts || {}; + const _createShippingEstimateRequest = CreateShippingEstimateRequest.constructFromObject( createShippingEstimateRequest, @@ -529,7 +598,9 @@ export default class EstimatesApi { let postBody = _createShippingEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -552,13 +623,16 @@ export default class EstimatesApi { ); } - createShippingEstimate(createShippingEstimateRequest) { + createShippingEstimate(createShippingEstimateRequest, opts) { return this.createShippingEstimateWithHttpInfo( - createShippingEstimateRequest + createShippingEstimateRequest, + opts ); } - createVehicleEstimateWithHttpInfo(createVehicleEstimateRequest) { + createVehicleEstimateWithHttpInfo(createVehicleEstimateRequest, opts) { + opts = opts || {}; + const _createVehicleEstimateRequest = CreateVehicleEstimateRequest.constructFromObject( createVehicleEstimateRequest, @@ -578,7 +652,9 @@ export default class EstimatesApi { let postBody = _createVehicleEstimateRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -601,11 +677,16 @@ export default class EstimatesApi { ); } - createVehicleEstimate(createVehicleEstimateRequest) { - return this.createVehicleEstimateWithHttpInfo(createVehicleEstimateRequest); + createVehicleEstimate(createVehicleEstimateRequest, opts) { + return this.createVehicleEstimateWithHttpInfo( + createVehicleEstimateRequest, + opts + ); } - retrieveEstimateWithHttpInfo(id) { + retrieveEstimateWithHttpInfo(id, opts) { + opts = opts || {}; + // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( @@ -618,7 +699,9 @@ export default class EstimatesApi { id: id }; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -641,8 +724,8 @@ export default class EstimatesApi { ); } - retrieveEstimate(id) { - return this.retrieveEstimateWithHttpInfo(id); + retrieveEstimate(id, opts) { + return this.retrieveEstimateWithHttpInfo(id, opts); } retrieveEstimatesWithHttpInfo(opts) { @@ -653,7 +736,9 @@ export default class EstimatesApi { let queryParams = { page: opts['page'] }; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; diff --git a/src/api/OrderLineItemsApi.js b/src/api/OrderLineItemsApi.js new file mode 100644 index 0000000..f1d2b0c --- /dev/null +++ b/src/api/OrderLineItemsApi.js @@ -0,0 +1,213 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; +import CreateOrderLineItemRequest from '../model/CreateOrderLineItemRequest'; +import DeleteOrderLineItemResponse from '../model/DeleteOrderLineItemResponse'; +import ErrorResponse from '../model/ErrorResponse'; +import OrderLineItemResponse from '../model/OrderLineItemResponse'; +import UpdateOrderLineItemRequest from '../model/UpdateOrderLineItemRequest'; + +export default class OrderLineItemsApi { + constructor(apiClient) { + this.apiClient = apiClient || ApiClient.instance; + } + + createOrderLineItemWithHttpInfo(orderId, createOrderLineItemRequest, opts) { + opts = opts || {}; + + const _createOrderLineItemRequest = + CreateOrderLineItemRequest.constructFromObject( + createOrderLineItemRequest, + new CreateOrderLineItemRequest() + ); + + // verify the required parameter 'orderId' is set + if (orderId === undefined || orderId === null) { + throw new Error( + "Missing the required parameter 'orderId' when calling createOrderLineItem" + ); + } + + // verify the required parameter 'createOrderLineItemRequest' is set + if ( + _createOrderLineItemRequest === undefined || + _createOrderLineItemRequest === null + ) { + throw new Error( + "Missing the required parameter 'createOrderLineItemRequest' when calling createOrderLineItem" + ); + } + + let postBody = _createOrderLineItemRequest; + let pathParams = { + order_id: orderId + }; + let queryParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = ['application/json']; + let accepts = ['application/json']; + let returnType = OrderLineItemResponse; + + return this.apiClient.callApi( + '/v1/orders/{order_id}/line_items', + 'POST', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + createOrderLineItem(orderId, createOrderLineItemRequest, opts) { + return this.createOrderLineItemWithHttpInfo( + orderId, + createOrderLineItemRequest, + opts + ); + } + + deleteOrderLineItemWithHttpInfo(orderId, serialNumber, opts) { + opts = opts || {}; + + // verify the required parameter 'orderId' is set + if (orderId === undefined || orderId === null) { + throw new Error( + "Missing the required parameter 'orderId' when calling deleteOrderLineItem" + ); + } + + // verify the required parameter 'serialNumber' is set + if (serialNumber === undefined || serialNumber === null) { + throw new Error( + "Missing the required parameter 'serialNumber' when calling deleteOrderLineItem" + ); + } + + let postBody = null; + let pathParams = { + order_id: orderId, + serial_number: serialNumber + }; + let queryParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = []; + let accepts = ['application/json']; + let returnType = DeleteOrderLineItemResponse; + + return this.apiClient.callApi( + '/v1/orders/{order_id}/line_items/{serial_number}', + 'DELETE', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + deleteOrderLineItem(orderId, serialNumber, opts) { + return this.deleteOrderLineItemWithHttpInfo(orderId, serialNumber, opts); + } + + updateOrderLineItemWithHttpInfo( + orderId, + serialNumber, + updateOrderLineItemRequest, + opts + ) { + opts = opts || {}; + + const _updateOrderLineItemRequest = + UpdateOrderLineItemRequest.constructFromObject( + updateOrderLineItemRequest, + new UpdateOrderLineItemRequest() + ); + + // verify the required parameter 'orderId' is set + if (orderId === undefined || orderId === null) { + throw new Error( + "Missing the required parameter 'orderId' when calling updateOrderLineItem" + ); + } + + // verify the required parameter 'serialNumber' is set + if (serialNumber === undefined || serialNumber === null) { + throw new Error( + "Missing the required parameter 'serialNumber' when calling updateOrderLineItem" + ); + } + + // verify the required parameter 'updateOrderLineItemRequest' is set + if ( + _updateOrderLineItemRequest === undefined || + _updateOrderLineItemRequest === null + ) { + throw new Error( + "Missing the required parameter 'updateOrderLineItemRequest' when calling updateOrderLineItem" + ); + } + + let postBody = _updateOrderLineItemRequest; + let pathParams = { + order_id: orderId, + serial_number: serialNumber + }; + let queryParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = ['application/json']; + let accepts = ['application/json']; + let returnType = OrderLineItemResponse; + + return this.apiClient.callApi( + '/v1/orders/{order_id}/line_items/{serial_number}', + 'PATCH', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + updateOrderLineItem(orderId, serialNumber, updateOrderLineItemRequest, opts) { + return this.updateOrderLineItemWithHttpInfo( + orderId, + serialNumber, + updateOrderLineItemRequest, + opts + ); + } +} diff --git a/src/api/OrdersApi.js b/src/api/OrdersApi.js index c183224..fc6304f 100644 --- a/src/api/OrdersApi.js +++ b/src/api/OrdersApi.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -7,6 +7,7 @@ import ApiClient from '../ApiClient'; import CreateOrderRequest from '../model/CreateOrderRequest'; +import DeleteOrderResponse from '../model/DeleteOrderResponse'; import ErrorResponse from '../model/ErrorResponse'; import OrderListResponse from '../model/OrderListResponse'; import OrderResponse from '../model/OrderResponse'; @@ -17,7 +18,9 @@ export default class OrdersApi { this.apiClient = apiClient || ApiClient.instance; } - cancelOrderWithHttpInfo(id) { + cancelOrderWithHttpInfo(id, opts) { + opts = opts || {}; + // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( @@ -30,7 +33,9 @@ export default class OrdersApi { id: id }; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -53,11 +58,13 @@ export default class OrdersApi { ); } - cancelOrder(id) { - return this.cancelOrderWithHttpInfo(id); + cancelOrder(id, opts) { + return this.cancelOrderWithHttpInfo(id, opts); } - createOrderWithHttpInfo(createOrderRequest) { + createOrderWithHttpInfo(createOrderRequest, opts) { + opts = opts || {}; + const _createOrderRequest = CreateOrderRequest.constructFromObject( createOrderRequest, new CreateOrderRequest() @@ -73,7 +80,9 @@ export default class OrdersApi { let postBody = _createOrderRequest; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -96,8 +105,52 @@ export default class OrdersApi { ); } - createOrder(createOrderRequest) { - return this.createOrderWithHttpInfo(createOrderRequest); + createOrder(createOrderRequest, opts) { + return this.createOrderWithHttpInfo(createOrderRequest, opts); + } + + deleteOrderWithHttpInfo(uid, opts) { + opts = opts || {}; + + // verify the required parameter 'uid' is set + if (uid === undefined || uid === null) { + throw new Error( + "Missing the required parameter 'uid' when calling deleteOrder" + ); + } + + let postBody = null; + let pathParams = { + uid: uid + }; + let queryParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = []; + let accepts = ['application/json']; + let returnType = DeleteOrderResponse; + + return this.apiClient.callApi( + '/v1/orders/{uid}', + 'DELETE', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + deleteOrder(uid, opts) { + return this.deleteOrderWithHttpInfo(uid, opts); } placeOrderWithHttpInfo(id, opts) { @@ -115,7 +168,9 @@ export default class OrdersApi { id: id }; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -142,7 +197,9 @@ export default class OrdersApi { return this.placeOrderWithHttpInfo(id, opts); } - retrieveOrderWithHttpInfo(id) { + retrieveOrderWithHttpInfo(id, opts) { + opts = opts || {}; + // verify the required parameter 'id' is set if (id === undefined || id === null) { throw new Error( @@ -155,7 +212,9 @@ export default class OrdersApi { id: id }; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -178,8 +237,8 @@ export default class OrdersApi { ); } - retrieveOrder(id) { - return this.retrieveOrderWithHttpInfo(id); + retrieveOrder(id, opts) { + return this.retrieveOrderWithHttpInfo(id, opts); } retrieveOrdersWithHttpInfo(opts) { @@ -196,7 +255,9 @@ export default class OrdersApi { 'metadata[example2]': opts['metadataExample2'] }; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; diff --git a/src/api/ProjectsApi.js b/src/api/ProjectsApi.js index 1f691d3..db1556e 100644 --- a/src/api/ProjectsApi.js +++ b/src/api/ProjectsApi.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -31,7 +31,8 @@ export default class ProjectsApi { }; let queryParams = {}; let headerParams = { - 'Accept-Language': opts['acceptLanguage'] + 'Accept-Language': opts['acceptLanguage'], + 'Patch-Version': opts['patchVersion'] }; let formParams = {}; @@ -74,7 +75,8 @@ export default class ProjectsApi { minimum_available_mass: opts['minimumAvailableMass'] }; let headerParams = { - 'Accept-Language': opts['acceptLanguage'] + 'Accept-Language': opts['acceptLanguage'], + 'Patch-Version': opts['patchVersion'] }; let formParams = {}; diff --git a/src/api/TechnologyTypesApi.js b/src/api/TechnologyTypesApi.js index b9bdae4..b8bcda5 100644 --- a/src/api/TechnologyTypesApi.js +++ b/src/api/TechnologyTypesApi.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -13,11 +13,15 @@ export default class TechnologyTypesApi { this.apiClient = apiClient || ApiClient.instance; } - retrieveTechnologyTypesWithHttpInfo() { + retrieveTechnologyTypesWithHttpInfo(opts) { + opts = opts || {}; + let postBody = null; let pathParams = {}; let queryParams = {}; - let headerParams = {}; + let headerParams = { + 'Patch-Version': opts['patchVersion'] + }; let formParams = {}; let authNames = ['bearer_auth']; @@ -40,7 +44,7 @@ export default class TechnologyTypesApi { ); } - retrieveTechnologyTypes() { - return this.retrieveTechnologyTypesWithHttpInfo(); + retrieveTechnologyTypes(opts) { + return this.retrieveTechnologyTypesWithHttpInfo(opts); } } diff --git a/src/index.js b/src/index.js index dd248fb..ad73b7b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -7,6 +7,7 @@ import ApiClient from './ApiClient'; import EstimatesApi from './api/EstimatesApi'; +import OrderLineItemsApi from './api/OrderLineItemsApi'; import OrdersApi from './api/OrdersApi'; import ProjectsApi from './api/ProjectsApi'; import TechnologyTypesApi from './api/TechnologyTypesApi'; @@ -19,6 +20,8 @@ export default function Patch(accessToken) { this.estimates = new EstimatesApi(this.client); + this.orderlineitems = new OrderLineItemsApi(this.client); + this.orders = new OrdersApi(this.client); this.projects = new ProjectsApi(this.client); diff --git a/src/model/Allocation.js b/src/model/Allocation.js deleted file mode 100644 index 8974752..0000000 --- a/src/model/Allocation.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Patch API V1 - * The core API used to integrate with Patch's service - * - * Contact: engineering@usepatch.com - */ - -import ApiClient from '../ApiClient'; - -class Allocation { - constructor(id, production, massG) { - Allocation.initialize(this, id, production, massG); - } - - static initialize(obj, id, production, massG) { - obj['id'] = id; - obj['production'] = production; - obj['mass_g'] = massG; - } - - static constructFromObject(data, obj) { - if (data) { - obj = obj || new Allocation(); - - if (data.hasOwnProperty('id')) { - obj['id'] = ApiClient.convertToType(data['id'], 'String'); - } - - if (data.hasOwnProperty('production')) { - obj['production'] = ApiClient.convertToType( - data['production'], - 'Boolean' - ); - } - - if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); - } - } - return obj; - } -} - -Allocation.prototype['id'] = undefined; - -Allocation.prototype['production'] = undefined; - -Allocation.prototype['mass_g'] = undefined; - -export default Allocation; diff --git a/src/model/CreateAirShippingEstimateRequest.js b/src/model/CreateAirShippingEstimateRequest.js index fb4bf0b..0abb1de 100644 --- a/src/model/CreateAirShippingEstimateRequest.js +++ b/src/model/CreateAirShippingEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateBitcoinEstimateRequest.js b/src/model/CreateBitcoinEstimateRequest.js index cf38a67..11cc903 100644 --- a/src/model/CreateBitcoinEstimateRequest.js +++ b/src/model/CreateBitcoinEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateEcommerceEstimateRequest.js b/src/model/CreateEcommerceEstimateRequest.js index 653313b..6c068fc 100644 --- a/src/model/CreateEcommerceEstimateRequest.js +++ b/src/model/CreateEcommerceEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateEthereumEstimateRequest.js b/src/model/CreateEthereumEstimateRequest.js index 6ba7867..ba7f2b4 100644 --- a/src/model/CreateEthereumEstimateRequest.js +++ b/src/model/CreateEthereumEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateFlightEstimateRequest.js b/src/model/CreateFlightEstimateRequest.js index 2ea7bcf..138f94e 100644 --- a/src/model/CreateFlightEstimateRequest.js +++ b/src/model/CreateFlightEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateHotelEstimateRequest.js b/src/model/CreateHotelEstimateRequest.js index d82cad5..bf7764a 100644 --- a/src/model/CreateHotelEstimateRequest.js +++ b/src/model/CreateHotelEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateMassEstimateRequest.js b/src/model/CreateMassEstimateRequest.js index 490d62f..4f1a6bd 100644 --- a/src/model/CreateMassEstimateRequest.js +++ b/src/model/CreateMassEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateOrderLineItemRequest.js b/src/model/CreateOrderLineItemRequest.js new file mode 100644 index 0000000..3c57fcb --- /dev/null +++ b/src/model/CreateOrderLineItemRequest.js @@ -0,0 +1,67 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class CreateOrderLineItemRequest { + constructor() { + CreateOrderLineItemRequest.initialize(this); + } + + static initialize(obj) {} + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new CreateOrderLineItemRequest(); + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = ApiClient.convertToType( + data['project_id'], + 'String' + ); + } + + if (data.hasOwnProperty('vintage_year')) { + obj['vintage_year'] = ApiClient.convertToType( + data['vintage_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('price')) { + obj['price'] = ApiClient.convertToType(data['price'], 'Number'); + } + + if (data.hasOwnProperty('currency')) { + obj['currency'] = ApiClient.convertToType(data['currency'], 'String'); + } + + if (data.hasOwnProperty('amount')) { + obj['amount'] = ApiClient.convertToType(data['amount'], 'Number'); + } + + if (data.hasOwnProperty('unit')) { + obj['unit'] = ApiClient.convertToType(data['unit'], 'String'); + } + } + return obj; + } +} + +CreateOrderLineItemRequest.prototype['project_id'] = undefined; + +CreateOrderLineItemRequest.prototype['vintage_year'] = undefined; + +CreateOrderLineItemRequest.prototype['price'] = undefined; + +CreateOrderLineItemRequest.prototype['currency'] = undefined; + +CreateOrderLineItemRequest.prototype['amount'] = undefined; + +CreateOrderLineItemRequest.prototype['unit'] = undefined; + +export default CreateOrderLineItemRequest; diff --git a/src/model/CreateOrderRequest.js b/src/model/CreateOrderRequest.js index 9d3d86a..12dd7a3 100644 --- a/src/model/CreateOrderRequest.js +++ b/src/model/CreateOrderRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -19,17 +19,6 @@ class CreateOrderRequest { if (data) { obj = obj || new CreateOrderRequest(); - if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); - } - - if (data.hasOwnProperty('total_price_cents_usd')) { - obj['total_price_cents_usd'] = ApiClient.convertToType( - data['total_price_cents_usd'], - 'Number' - ); - } - if (data.hasOwnProperty('project_id')) { obj['project_id'] = ApiClient.convertToType( data['project_id'], @@ -79,10 +68,6 @@ class CreateOrderRequest { } } -CreateOrderRequest.prototype['mass_g'] = undefined; - -CreateOrderRequest.prototype['total_price_cents_usd'] = undefined; - CreateOrderRequest.prototype['project_id'] = undefined; CreateOrderRequest.prototype['metadata'] = undefined; diff --git a/src/model/CreateRailShippingEstimateRequest.js b/src/model/CreateRailShippingEstimateRequest.js index 70deeb3..c55c679 100644 --- a/src/model/CreateRailShippingEstimateRequest.js +++ b/src/model/CreateRailShippingEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateRoadShippingEstimateRequest.js b/src/model/CreateRoadShippingEstimateRequest.js index 5dea7b2..5bdd384 100644 --- a/src/model/CreateRoadShippingEstimateRequest.js +++ b/src/model/CreateRoadShippingEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateSeaShippingEstimateRequest.js b/src/model/CreateSeaShippingEstimateRequest.js index d82ccca..aa4fb07 100644 --- a/src/model/CreateSeaShippingEstimateRequest.js +++ b/src/model/CreateSeaShippingEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateShippingEstimateRequest.js b/src/model/CreateShippingEstimateRequest.js index 5e33250..9008c0b 100644 --- a/src/model/CreateShippingEstimateRequest.js +++ b/src/model/CreateShippingEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateSuccessResponse.js b/src/model/CreateSuccessResponse.js index 34d85bf..6a27b28 100644 --- a/src/model/CreateSuccessResponse.js +++ b/src/model/CreateSuccessResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/CreateVehicleEstimateRequest.js b/src/model/CreateVehicleEstimateRequest.js index afc8ba7..3676ad6 100644 --- a/src/model/CreateVehicleEstimateRequest.js +++ b/src/model/CreateVehicleEstimateRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/DeleteOrderLineItemResponse.js b/src/model/DeleteOrderLineItemResponse.js new file mode 100644 index 0000000..5177ad3 --- /dev/null +++ b/src/model/DeleteOrderLineItemResponse.js @@ -0,0 +1,47 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class DeleteOrderLineItemResponse { + constructor(success, error, data) { + DeleteOrderLineItemResponse.initialize(this, success, error, data); + } + + static initialize(obj, success, error, data) { + obj['success'] = success; + obj['error'] = error; + obj['data'] = data; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new DeleteOrderLineItemResponse(); + + if (data.hasOwnProperty('success')) { + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + } + + if (data.hasOwnProperty('error')) { + obj['error'] = ApiClient.convertToType(data['error'], Object); + } + + if (data.hasOwnProperty('data')) { + obj['data'] = ApiClient.convertToType(data['data'], 'String'); + } + } + return obj; + } +} + +DeleteOrderLineItemResponse.prototype['success'] = undefined; + +DeleteOrderLineItemResponse.prototype['error'] = undefined; + +DeleteOrderLineItemResponse.prototype['data'] = undefined; + +export default DeleteOrderLineItemResponse; diff --git a/src/model/DeleteOrderResponse.js b/src/model/DeleteOrderResponse.js new file mode 100644 index 0000000..dc7e0fb --- /dev/null +++ b/src/model/DeleteOrderResponse.js @@ -0,0 +1,47 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class DeleteOrderResponse { + constructor(success, error, data) { + DeleteOrderResponse.initialize(this, success, error, data); + } + + static initialize(obj, success, error, data) { + obj['success'] = success; + obj['error'] = error; + obj['data'] = data; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new DeleteOrderResponse(); + + if (data.hasOwnProperty('success')) { + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + } + + if (data.hasOwnProperty('error')) { + obj['error'] = ApiClient.convertToType(data['error'], Object); + } + + if (data.hasOwnProperty('data')) { + obj['data'] = ApiClient.convertToType(data['data'], 'String'); + } + } + return obj; + } +} + +DeleteOrderResponse.prototype['success'] = undefined; + +DeleteOrderResponse.prototype['error'] = undefined; + +DeleteOrderResponse.prototype['data'] = undefined; + +export default DeleteOrderResponse; diff --git a/src/model/ErrorResponse.js b/src/model/ErrorResponse.js index 720f7f8..3a0609a 100644 --- a/src/model/ErrorResponse.js +++ b/src/model/ErrorResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Estimate.js b/src/model/Estimate.js index 3ecc691..43d7600 100644 --- a/src/model/Estimate.js +++ b/src/model/Estimate.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/EstimateListResponse.js b/src/model/EstimateListResponse.js index 2d6c8e8..6c5ea26 100644 --- a/src/model/EstimateListResponse.js +++ b/src/model/EstimateListResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/EstimateResponse.js b/src/model/EstimateResponse.js index 85cc0d7..9f975ab 100644 --- a/src/model/EstimateResponse.js +++ b/src/model/EstimateResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Highlight.js b/src/model/Highlight.js index 7daa454..aa656d1 100644 --- a/src/model/Highlight.js +++ b/src/model/Highlight.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Inventory.js b/src/model/Inventory.js index 4164710..66f92d0 100644 --- a/src/model/Inventory.js +++ b/src/model/Inventory.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/MetaIndexObject.js b/src/model/MetaIndexObject.js index 324181d..0e7c65e 100644 --- a/src/model/MetaIndexObject.js +++ b/src/model/MetaIndexObject.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Order.js b/src/model/Order.js index d3b0709..a4b151b 100644 --- a/src/model/Order.js +++ b/src/model/Order.js @@ -1,19 +1,17 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com */ import ApiClient from '../ApiClient'; -import Allocation from './Allocation'; -import OrderInventory from './OrderInventory'; import OrderIssuedTo from './OrderIssuedTo'; +import OrderLineItem from './OrderLineItem'; class Order { constructor( id, - massG, production, state, amount, @@ -21,15 +19,11 @@ class Order { price, patchFee, currency, - allocationState, - priceCentsUsd, - patchFeeCentsUsd, metadata ) { Order.initialize( this, id, - massG, production, state, amount, @@ -37,9 +31,6 @@ class Order { price, patchFee, currency, - allocationState, - priceCentsUsd, - patchFeeCentsUsd, metadata ); } @@ -47,7 +38,6 @@ class Order { static initialize( obj, id, - massG, production, state, amount, @@ -55,13 +45,9 @@ class Order { price, patchFee, currency, - allocationState, - priceCentsUsd, - patchFeeCentsUsd, metadata ) { obj['id'] = id; - obj['mass_g'] = massG; obj['production'] = production; obj['state'] = state; obj['amount'] = amount; @@ -69,9 +55,6 @@ class Order { obj['price'] = price; obj['patch_fee'] = patchFee; obj['currency'] = currency; - obj['allocation_state'] = allocationState; - obj['price_cents_usd'] = priceCentsUsd; - obj['patch_fee_cents_usd'] = patchFeeCentsUsd; obj['metadata'] = metadata; } @@ -87,10 +70,6 @@ class Order { obj['created_at'] = ApiClient.convertToType(data['created_at'], 'Date'); } - if (data.hasOwnProperty('mass_g')) { - obj['mass_g'] = ApiClient.convertToType(data['mass_g'], 'Number'); - } - if (data.hasOwnProperty('production')) { obj['production'] = ApiClient.convertToType( data['production'], @@ -122,33 +101,6 @@ class Order { obj['currency'] = ApiClient.convertToType(data['currency'], 'String'); } - if (data.hasOwnProperty('allocation_state')) { - obj['allocation_state'] = ApiClient.convertToType( - data['allocation_state'], - 'String' - ); - } - - if (data.hasOwnProperty('price_cents_usd')) { - obj['price_cents_usd'] = ApiClient.convertToType( - data['price_cents_usd'], - 'Number' - ); - } - - if (data.hasOwnProperty('patch_fee_cents_usd')) { - obj['patch_fee_cents_usd'] = ApiClient.convertToType( - data['patch_fee_cents_usd'], - 'Number' - ); - } - - if (data.hasOwnProperty('allocations')) { - obj['allocations'] = ApiClient.convertToType(data['allocations'], [ - Allocation - ]); - } - if (data.hasOwnProperty('registry_url')) { obj['registry_url'] = ApiClient.convertToType( data['registry_url'], @@ -160,9 +112,9 @@ class Order { obj['metadata'] = ApiClient.convertToType(data['metadata'], Object); } - if (data.hasOwnProperty('inventory')) { - obj['inventory'] = ApiClient.convertToType(data['inventory'], [ - OrderInventory + if (data.hasOwnProperty('line_items')) { + obj['line_items'] = ApiClient.convertToType(data['line_items'], [ + OrderLineItem ]); } @@ -181,8 +133,6 @@ Order.prototype['id'] = undefined; Order.prototype['created_at'] = undefined; -Order.prototype['mass_g'] = undefined; - Order.prototype['production'] = undefined; Order.prototype['state'] = undefined; @@ -197,19 +147,11 @@ Order.prototype['patch_fee'] = undefined; Order.prototype['currency'] = undefined; -Order.prototype['allocation_state'] = undefined; - -Order.prototype['price_cents_usd'] = undefined; - -Order.prototype['patch_fee_cents_usd'] = undefined; - -Order.prototype['allocations'] = undefined; - Order.prototype['registry_url'] = undefined; Order.prototype['metadata'] = undefined; -Order.prototype['inventory'] = undefined; +Order.prototype['line_items'] = undefined; Order.prototype['issued_to'] = undefined; diff --git a/src/model/OrderIssuedTo.js b/src/model/OrderIssuedTo.js index 8c2a6d5..1daf6cc 100644 --- a/src/model/OrderIssuedTo.js +++ b/src/model/OrderIssuedTo.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/OrderInventory.js b/src/model/OrderLineItem.js similarity index 68% rename from src/model/OrderInventory.js rename to src/model/OrderLineItem.js index 665ba24..a5b21c8 100644 --- a/src/model/OrderInventory.js +++ b/src/model/OrderLineItem.js @@ -1,16 +1,16 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com */ import ApiClient from '../ApiClient'; -import OrderInventoryProject from './OrderInventoryProject'; +import OrderLineItemProject from './OrderLineItemProject'; -class OrderInventory { +class OrderLineItem { constructor(project, vintageYear, amount, unit, price, currency) { - OrderInventory.initialize( + OrderLineItem.initialize( this, project, vintageYear, @@ -32,12 +32,16 @@ class OrderInventory { static constructFromObject(data, obj) { if (data) { - obj = obj || new OrderInventory(); + obj = obj || new OrderLineItem(); + + if (data.hasOwnProperty('id')) { + obj['id'] = ApiClient.convertToType(data['id'], 'String'); + } if (data.hasOwnProperty('project')) { obj['project'] = ApiClient.convertToType( data['project'], - OrderInventoryProject + OrderLineItemProject ); } @@ -68,16 +72,18 @@ class OrderInventory { } } -OrderInventory.prototype['project'] = undefined; +OrderLineItem.prototype['id'] = undefined; + +OrderLineItem.prototype['project'] = undefined; -OrderInventory.prototype['vintage_year'] = undefined; +OrderLineItem.prototype['vintage_year'] = undefined; -OrderInventory.prototype['amount'] = undefined; +OrderLineItem.prototype['amount'] = undefined; -OrderInventory.prototype['unit'] = undefined; +OrderLineItem.prototype['unit'] = undefined; -OrderInventory.prototype['price'] = undefined; +OrderLineItem.prototype['price'] = undefined; -OrderInventory.prototype['currency'] = undefined; +OrderLineItem.prototype['currency'] = undefined; -export default OrderInventory; +export default OrderLineItem; diff --git a/src/model/OrderInventoryProject.js b/src/model/OrderLineItemProject.js similarity index 66% rename from src/model/OrderInventoryProject.js rename to src/model/OrderLineItemProject.js index 60701d7..7e0de67 100644 --- a/src/model/OrderInventoryProject.js +++ b/src/model/OrderLineItemProject.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -7,9 +7,9 @@ import ApiClient from '../ApiClient'; -class OrderInventoryProject { +class OrderLineItemProject { constructor(id, name) { - OrderInventoryProject.initialize(this, id, name); + OrderLineItemProject.initialize(this, id, name); } static initialize(obj, id, name) { @@ -19,7 +19,7 @@ class OrderInventoryProject { static constructFromObject(data, obj) { if (data) { - obj = obj || new OrderInventoryProject(); + obj = obj || new OrderLineItemProject(); if (data.hasOwnProperty('id')) { obj['id'] = ApiClient.convertToType(data['id'], 'String'); @@ -33,8 +33,8 @@ class OrderInventoryProject { } } -OrderInventoryProject.prototype['id'] = undefined; +OrderLineItemProject.prototype['id'] = undefined; -OrderInventoryProject.prototype['name'] = undefined; +OrderLineItemProject.prototype['name'] = undefined; -export default OrderInventoryProject; +export default OrderLineItemProject; diff --git a/src/model/OrderLineItemResponse.js b/src/model/OrderLineItemResponse.js new file mode 100644 index 0000000..1e250c0 --- /dev/null +++ b/src/model/OrderLineItemResponse.js @@ -0,0 +1,48 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; +import OrderLineItem from './OrderLineItem'; + +class OrderLineItemResponse { + constructor(success, error, data) { + OrderLineItemResponse.initialize(this, success, error, data); + } + + static initialize(obj, success, error, data) { + obj['success'] = success; + obj['error'] = error; + obj['data'] = data; + } + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new OrderLineItemResponse(); + + if (data.hasOwnProperty('success')) { + obj['success'] = ApiClient.convertToType(data['success'], 'Boolean'); + } + + if (data.hasOwnProperty('error')) { + obj['error'] = ApiClient.convertToType(data['error'], Object); + } + + if (data.hasOwnProperty('data')) { + obj['data'] = OrderLineItem.constructFromObject(data['data']); + } + } + return obj; + } +} + +OrderLineItemResponse.prototype['success'] = undefined; + +OrderLineItemResponse.prototype['error'] = undefined; + +OrderLineItemResponse.prototype['data'] = undefined; + +export default OrderLineItemResponse; diff --git a/src/model/OrderListResponse.js b/src/model/OrderListResponse.js index d95ad75..9d0c942 100644 --- a/src/model/OrderListResponse.js +++ b/src/model/OrderListResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/OrderResponse.js b/src/model/OrderResponse.js index 3b2696e..c59002d 100644 --- a/src/model/OrderResponse.js +++ b/src/model/OrderResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/ParentTechnologyType.js b/src/model/ParentTechnologyType.js index 6030d48..6306658 100644 --- a/src/model/ParentTechnologyType.js +++ b/src/model/ParentTechnologyType.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Photo.js b/src/model/Photo.js index 461db40..c70e92d 100644 --- a/src/model/Photo.js +++ b/src/model/Photo.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/PlaceOrderRequest.js b/src/model/PlaceOrderRequest.js index dc5e82e..efe6a63 100644 --- a/src/model/PlaceOrderRequest.js +++ b/src/model/PlaceOrderRequest.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Project.js b/src/model/Project.js index f8bc371..f18c071 100644 --- a/src/model/Project.js +++ b/src/model/Project.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com @@ -20,9 +20,7 @@ class Project { name, description, country, - developer, - averagePricePerTonneCentsUsd, - remainingMassG, + projectPartner, technologyType, highlights, inventory @@ -34,9 +32,7 @@ class Project { name, description, country, - developer, - averagePricePerTonneCentsUsd, - remainingMassG, + projectPartner, technologyType, highlights, inventory @@ -50,9 +46,7 @@ class Project { name, description, country, - developer, - averagePricePerTonneCentsUsd, - remainingMassG, + projectPartner, technologyType, highlights, inventory @@ -62,9 +56,7 @@ class Project { obj['name'] = name; obj['description'] = description; obj['country'] = country; - obj['developer'] = developer; - obj['average_price_per_tonne_cents_usd'] = averagePricePerTonneCentsUsd; - obj['remaining_mass_g'] = remainingMassG; + obj['project_partner'] = projectPartner; obj['technology_type'] = technologyType; obj['highlights'] = highlights; obj['inventory'] = inventory; @@ -96,10 +88,6 @@ class Project { ); } - if (data.hasOwnProperty('type')) { - obj['type'] = ApiClient.convertToType(data['type'], 'String'); - } - if (data.hasOwnProperty('mechanism')) { obj['mechanism'] = ApiClient.convertToType(data['mechanism'], 'String'); } @@ -120,28 +108,17 @@ class Project { obj['longitude'] = ApiClient.convertToType(data['longitude'], 'Number'); } - if (data.hasOwnProperty('developer')) { - obj['developer'] = ApiClient.convertToType(data['developer'], 'String'); + if (data.hasOwnProperty('project_partner')) { + obj['project_partner'] = ApiClient.convertToType( + data['project_partner'], + 'String' + ); } if (data.hasOwnProperty('photos')) { obj['photos'] = ApiClient.convertToType(data['photos'], [Photo]); } - if (data.hasOwnProperty('average_price_per_tonne_cents_usd')) { - obj['average_price_per_tonne_cents_usd'] = ApiClient.convertToType( - data['average_price_per_tonne_cents_usd'], - 'Number' - ); - } - - if (data.hasOwnProperty('remaining_mass_g')) { - obj['remaining_mass_g'] = ApiClient.convertToType( - data['remaining_mass_g'], - 'Number' - ); - } - if (data.hasOwnProperty('verifier')) { obj['verifier'] = ApiClient.convertToType(data['verifier'], 'String'); } @@ -188,8 +165,6 @@ Project.prototype['name'] = undefined; Project.prototype['description'] = undefined; -Project.prototype['type'] = undefined; - Project.prototype['mechanism'] = undefined; Project.prototype['country'] = undefined; @@ -200,14 +175,10 @@ Project.prototype['latitude'] = undefined; Project.prototype['longitude'] = undefined; -Project.prototype['developer'] = undefined; +Project.prototype['project_partner'] = undefined; Project.prototype['photos'] = undefined; -Project.prototype['average_price_per_tonne_cents_usd'] = undefined; - -Project.prototype['remaining_mass_g'] = undefined; - Project.prototype['verifier'] = undefined; Project.prototype['standard'] = undefined; diff --git a/src/model/ProjectListRequest.js b/src/model/ProjectListRequest.js deleted file mode 100644 index fe29caa..0000000 --- a/src/model/ProjectListRequest.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Patch API V1 - * The core API used to integrate with Patch's service - * - * Contact: developers@usepatch.com - */ - -import ApiClient from '../ApiClient'; - -class ProjectListRequest { - constructor() { - ProjectListRequest.initialize(this); - } - - static initialize(obj) {} - - static constructFromObject(data, obj) { - if (data) { - obj = obj || new ProjectListRequest(); - - if (data.hasOwnProperty('page')) { - obj['page'] = ApiClient.convertToType(data['page'], 'Number'); - } - - if (data.hasOwnProperty('country')) { - obj['country'] = ApiClient.convertToType(data['country'], 'String'); - } - - if (data.hasOwnProperty('type')) { - obj['type'] = ApiClient.convertToType(data['type'], 'String'); - } - } - return obj; - } -} - -ProjectListRequest.prototype['page'] = undefined; - -ProjectListRequest.prototype['country'] = undefined; - -ProjectListRequest.prototype['type'] = undefined; - -export default ProjectListRequest; diff --git a/src/model/ProjectListResponse.js b/src/model/ProjectListResponse.js index 3bb5441..06e5e3b 100644 --- a/src/model/ProjectListResponse.js +++ b/src/model/ProjectListResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/ProjectResponse.js b/src/model/ProjectResponse.js index f4f210f..f7f8d15 100644 --- a/src/model/ProjectResponse.js +++ b/src/model/ProjectResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Sdg.js b/src/model/Sdg.js index bf05ca9..6dff76e 100644 --- a/src/model/Sdg.js +++ b/src/model/Sdg.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/Standard.js b/src/model/Standard.js index 3d92fcf..500d3e8 100644 --- a/src/model/Standard.js +++ b/src/model/Standard.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/TechnologyType.js b/src/model/TechnologyType.js index b201c46..19cfcec 100644 --- a/src/model/TechnologyType.js +++ b/src/model/TechnologyType.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/TechnologyTypeListResponse.js b/src/model/TechnologyTypeListResponse.js index 5c5c024..904ecd3 100644 --- a/src/model/TechnologyTypeListResponse.js +++ b/src/model/TechnologyTypeListResponse.js @@ -1,5 +1,5 @@ /** - * Patch API V1 + * Patch API V2 * The core API used to integrate with Patch's service * * Contact: engineering@usepatch.com diff --git a/src/model/UpdateOrderLineItemRequest.js b/src/model/UpdateOrderLineItemRequest.js new file mode 100644 index 0000000..de52e1a --- /dev/null +++ b/src/model/UpdateOrderLineItemRequest.js @@ -0,0 +1,58 @@ +/** + * Patch API V2 + * The core API used to integrate with Patch's service + * + * Contact: engineering@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class UpdateOrderLineItemRequest { + constructor() { + UpdateOrderLineItemRequest.initialize(this); + } + + static initialize(obj) {} + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new UpdateOrderLineItemRequest(); + + if (data.hasOwnProperty('vintage_year')) { + obj['vintage_year'] = ApiClient.convertToType( + data['vintage_year'], + 'Number' + ); + } + + if (data.hasOwnProperty('price')) { + obj['price'] = ApiClient.convertToType(data['price'], 'Number'); + } + + if (data.hasOwnProperty('currency')) { + obj['currency'] = ApiClient.convertToType(data['currency'], 'String'); + } + + if (data.hasOwnProperty('amount')) { + obj['amount'] = ApiClient.convertToType(data['amount'], 'Number'); + } + + if (data.hasOwnProperty('unit')) { + obj['unit'] = ApiClient.convertToType(data['unit'], 'String'); + } + } + return obj; + } +} + +UpdateOrderLineItemRequest.prototype['vintage_year'] = undefined; + +UpdateOrderLineItemRequest.prototype['price'] = undefined; + +UpdateOrderLineItemRequest.prototype['currency'] = undefined; + +UpdateOrderLineItemRequest.prototype['amount'] = undefined; + +UpdateOrderLineItemRequest.prototype['unit'] = undefined; + +export default UpdateOrderLineItemRequest; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index 35b0ebd..2fa4a58 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -14,7 +14,7 @@ describe('Estimates Integration', function () { estimateId ); expect(retrieveEstimateResponse.data.id).to.equal(estimateId); - expect(retrieveEstimateResponse.data.order.state).to.equal('draft'); + expect(retrieveEstimateResponse.data.order.state).to.equal('reserved'); const retrieveEstimatesResponse = await patch.estimates.retrieveEstimates({ page: 1 diff --git a/test/integration/orders.test.js b/test/integration/orders.test.js index d5606aa..f25df47 100644 --- a/test/integration/orders.test.js +++ b/test/integration/orders.test.js @@ -5,7 +5,10 @@ const biomass_test_project_id = 'pro_test_c3a9feba769fc7a8806377266ca9ff6a'; describe('Orders Integration', function () { it('supports create, place, cancel, retrieve and list', async function () { - const createOrderResponse = await patch.orders.createOrder({ mass_g: 100 }); + const createOrderResponse = await patch.orders.createOrder({ + amount: 100, + unit: 'g' + }); const orderId = createOrderResponse.data.id; const retrieveOrderResponse = await patch.orders.retrieveOrder(orderId); @@ -19,28 +22,31 @@ describe('Orders Integration', function () { it('supports creating an order with a project_id', async function () { const { data } = await patch.orders.createOrder({ - total_price_cents_usd: 100, + total_price: 100, + currency: 'USD', project_id: biomass_test_project_id }); - expect(data.price_cents_usd + data.patch_fee_cents_usd).to.eq(100); + expect(data.price + data.patch_fee).to.eq(100); }); it('supports creating an order with issued_to', async function () { const issuedTo = { email: 'issuee@companyc.com', name: 'Bob Dylan' }; const { data } = await patch.orders.createOrder({ - total_price_cents_usd: 100, + total_price: 100, + currency: 'USD', issued_to: issuedTo }); - expect(data.price_cents_usd + data.patch_fee_cents_usd).to.eq(100); + expect(data.price + data.patch_fee).to.eq(100); expect(data.issued_to.email).to.equal(issuedTo.email); expect(data.issued_to.name).to.equal(issuedTo.name); }); it('supports placing orders in a `draft` state', async function () { const estimateResponse = await patch.orders.createOrder({ - mass_g: 100, + amount: 100, + unit: 'g', state: 'draft' }); @@ -50,16 +56,16 @@ describe('Orders Integration', function () { const placeOrderResponse = await patch.orders.placeOrder(orderId); expect(placeOrderResponse.data.created_at).to.be.an.instanceOf(Date); expect(placeOrderResponse.data.production).to.equal(false); - expect(placeOrderResponse.data.mass_g).to.equal(100); + expect(placeOrderResponse.data.amount).to.equal(100); }); - it('supports placing orders in a `draft` state with issued_to', async function () { + it('supports placing orders in a `reserved` state with issued_to', async function () { const estimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100, create_order: true }); const orderId = estimateResponse.data.order.id; - expect(estimateResponse.data.order.state).to.equal('draft'); + expect(estimateResponse.data.order.state).to.equal('reserved'); const issuedTo = { email: 'issuee@companyc.com', name: 'Bob Dylan' }; @@ -68,32 +74,32 @@ describe('Orders Integration', function () { }); expect(placeOrderResponse.data.created_at).to.be.an.instanceOf(Date); expect(placeOrderResponse.data.production).to.equal(false); - expect(placeOrderResponse.data.mass_g).to.equal(100); + expect(placeOrderResponse.data.amount).to.equal(100); expect(placeOrderResponse.data.issued_to.email).to.equal(issuedTo.email); expect(placeOrderResponse.data.issued_to.name).to.equal(issuedTo.name); }); - it('supports placing orders in a `draft` state using an estimate', async function () { + it('supports placing orders in a `reserved` state using an estimate', async function () { const estimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100, create_order: true }); const orderId = estimateResponse.data.order.id; - expect(estimateResponse.data.order.state).to.equal('draft'); + expect(estimateResponse.data.order.state).to.equal('reserved'); const placeOrderResponse = await patch.orders.placeOrder(orderId); expect(placeOrderResponse.data.created_at).to.be.an.instanceOf(Date); expect(placeOrderResponse.data.production).to.equal(false); - expect(placeOrderResponse.data.mass_g).to.equal(100); + expect(placeOrderResponse.data.amount).to.equal(100); }); - it('supports cancelling orders in a `draft` state', async function () { + it('supports cancelling orders in a `reserved` state', async function () { const estimateResponse = await patch.estimates.createMassEstimate({ mass_g: 100, create_order: true }); const orderId = estimateResponse.data.order.id; - expect(estimateResponse.data.order.state).to.equal('draft'); + expect(estimateResponse.data.order.state).to.equal('reserved'); const placeOrderResponse = await patch.orders.cancelOrder(orderId); expect(placeOrderResponse.data.state).to.equal('cancelled'); @@ -101,7 +107,8 @@ describe('Orders Integration', function () { it('supports creating and querying orders by metadata', async function () { const createOrderResponse = await patch.orders.createOrder({ - mass_g: 100, + amount: 100, + unit: 'g', metadata: { external_id: 'order-123' } }); @@ -118,7 +125,8 @@ describe('Orders Integration', function () { it('supports create orders with a vintage year', async function () { const createOrderResponse = await patch.orders.createOrder({ - mass_g: 100, + amount: 100, + unit: 'g', vintage_year: 2022 }); @@ -134,7 +142,7 @@ describe('Orders Integration', function () { expect(createOrderResponse.success).to.equal(true); expect(createOrderResponse.data.amount).to.equal(100); expect(createOrderResponse.data.unit).to.equal('g'); - expect(createOrderResponse.data.inventory[0].unit).to.equal('g'); + expect(createOrderResponse.data.line_items[0].unit).to.equal('g'); }); it('supports create orders with a total price and currency', async function () { @@ -149,4 +157,62 @@ describe('Orders Integration', function () { ).to.be.within(99, 101); expect(createOrderResponse.data.currency).to.equal('EUR'); }); + + it('supports creating an empty draft order and adding/editing line items', async function () { + const createOrderResponse = await patch.orders.createOrder({ + state: 'draft' + }); + + expect(createOrderResponse.success).to.equal(true); + expect(createOrderResponse.data.price).to.equal(0); + expect(createOrderResponse.data.amount).to.equal(0); + expect(createOrderResponse.data.line_items.length).to.equal(0); + + // Add project to order + const orderId = createOrderResponse.data.id; + + const createLineItemResponse = + await patch.orderlineitems.createOrderLineItem(orderId, { + project_id: biomass_test_project_id + }); + + expect(createLineItemResponse.success).to.equal(true); + expect(createLineItemResponse.data.amount).to.equal(0); + + // Update amount on line item + const lineItemId = createLineItemResponse.data.id; + const updateOrderLineItemResponse = + await patch.orderlineitems.updateOrderLineItem(orderId, lineItemId, { + amount: 100000, + unit: 'g' + }); + + expect(updateOrderLineItemResponse.success).to.equal(true); + expect(updateOrderLineItemResponse.data.id).to.equal(lineItemId); + expect(updateOrderLineItemResponse.data.amount).to.equal(100000); + expect(updateOrderLineItemResponse.data.price).to.be.greaterThan(0); + + // Fetch order and check line item matches + let retrieveOrderResponse = await patch.orders.retrieveOrder(orderId); + expect(retrieveOrderResponse.data.id).to.equal(orderId); + expect(retrieveOrderResponse.data.line_items.length).to.equal(1); + expect(retrieveOrderResponse.data.line_items[0].id).to.equal(lineItemId); + expect(retrieveOrderResponse.data.line_items[0].amount).to.equal(100000); + + // Delete line item + const deleteLineItemResponse = + await patch.orderlineitems.deleteOrderLineItem(orderId, lineItemId); + expect(deleteLineItemResponse.success).to.equal(true); + expect(deleteLineItemResponse.data).to.equal(lineItemId); + + // Fetch order and see it has no line items + retrieveOrderResponse = await patch.orders.retrieveOrder(orderId); + expect(retrieveOrderResponse.data.id).to.equal(orderId); + expect(retrieveOrderResponse.data.line_items.length).to.equal(0); + + // Delete order + const deleteOrderResponse = await patch.orders.deleteOrder(orderId); + expect(deleteOrderResponse.success).to.equal(true); + expect(deleteOrderResponse.data).to.equal(orderId); + }); }); diff --git a/test/integration/projects.test.js b/test/integration/projects.test.js index 2c2674e..0c3bc5c 100644 --- a/test/integration/projects.test.js +++ b/test/integration/projects.test.js @@ -79,7 +79,11 @@ describe('Project Integration', function () { minimumAvailableMass }); data.map((project) => { - expect(project.remaining_mass_g >= minimumAvailableMass).to.be.true; + const remainingMass = project.inventory.reduce( + (acc, inv) => acc + inv.amount_available, + 0 + ); + expect(remainingMass >= minimumAvailableMass).to.be.true; }); }); }); diff --git a/yarn.lock b/yarn.lock index 7ef2605..c26fb54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1645,11 +1645,6 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" -"fsevents@~2.3.2": - "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" - "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - "version" "2.3.2" - "function-bind@^1.1.1": "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz"