From 5820ba5c41e83c036e1e65d7dbf86f7e54b884b7 Mon Sep 17 00:00:00 2001 From: Samy Ouyahia Date: Thu, 28 Nov 2024 11:35:09 +0100 Subject: [PATCH] Update the pricing V2 types to reflect methodology changes in API --- .../network/src/api/inspection/mappers.ts | 13 +++- packages/network/src/api/models/pricingV2.ts | 14 +++- packages/network/src/api/models/task.ts | 3 + .../apiAllInspectionsVerboseGet.data.json | 28 ++++---- .../data/apiInspectionGet.data.json | 64 ++++++++++--------- .../data/apiInspectionPost.data.json | 3 +- .../inspection/data/apiInspectionPost.data.ts | 3 +- packages/types/src/api.ts | 23 ++++++- 8 files changed, 100 insertions(+), 51 deletions(-) diff --git a/packages/network/src/api/inspection/mappers.ts b/packages/network/src/api/inspection/mappers.ts index 89fed8c33..7ef69a592 100644 --- a/packages/network/src/api/inspection/mappers.ts +++ b/packages/network/src/api/inspection/mappers.ts @@ -45,6 +45,7 @@ import { ApiInspectionPost, ApiPartSeverityValue, ApiPricingTaskPostComponent, + ApiPricingV2, ApiPricingV2Details, type ApiRelatedImages, ApiRenderedOutput, @@ -244,9 +245,14 @@ function mapPricingV2(response: ApiInspectionGet | ApiAllInspectionsVerboseGet): if (!response.pricing) { return { pricings, pricingIds }; } - Object.values(response.pricing.details).forEach((details) => { - pricingIds.push(details.id); - pricings.push(mapPricingV2Details(details, response.id)); + Object.values(response.pricing).forEach((value) => { + const pricing = value as ApiPricingV2[keyof ApiPricingV2]; + if (pricing) { + Object.values(pricing.details).forEach((details) => { + pricingIds.push(details.id); + pricings.push(mapPricingV2Details(details, response.id)); + }); + } }); return { pricings, pricingIds }; } @@ -589,6 +595,7 @@ function getPricingOptions( status: ProgressStatus.TODO, output_format: taskOptions.outputFormat ?? 'default', config: taskOptions.config, + methodology: taskOptions.methodology, } : undefined; } diff --git a/packages/network/src/api/models/pricingV2.ts b/packages/network/src/api/models/pricingV2.ts index f680eb4bd..ccee9fd78 100644 --- a/packages/network/src/api/models/pricingV2.ts +++ b/packages/network/src/api/models/pricingV2.ts @@ -27,11 +27,23 @@ export interface ApiPricingV2Details { export type ApiDetails = Record; -export interface ApiPricingV2 { +export type ApiPricingMethodology = 'labor_cost' | 'flat_rate'; + +export interface PricingLaborCostGet { details: ApiDetails; total_price?: number; } +export interface PricingFlatRateGet { + details: ApiDetails; + total_price?: number; +} + +export interface ApiPricingV2 { + labor_cost?: PricingLaborCostGet; + total_price?: PricingFlatRateGet; +} + export interface ApiPricingPostPatch { pricing: number; related_item_type: PricingV2RelatedItemType; diff --git a/packages/network/src/api/models/task.ts b/packages/network/src/api/models/task.ts index 00797ae95..6ad55bb84 100644 --- a/packages/network/src/api/models/task.ts +++ b/packages/network/src/api/models/task.ts @@ -1,3 +1,5 @@ +import { ApiPricingMethodology } from './pricingV2'; + export type ApiBusinessClients = 'default' | 'toyota' | 'veb' | 'tesla'; export interface ApiImageInTask { @@ -114,6 +116,7 @@ export interface ApiPricingTaskPostComponent { callbacks?: ApiCallbacks; output_format?: ApiBusinessClients; config?: string; + methodology?: ApiPricingMethodology; } export interface ApiTasksComponent { diff --git a/packages/network/test/api/inspection/data/apiAllInspectionsVerboseGet.data.json b/packages/network/test/api/inspection/data/apiAllInspectionsVerboseGet.data.json index 874a19383..47ba025a0 100644 --- a/packages/network/test/api/inspection/data/apiAllInspectionsVerboseGet.data.json +++ b/packages/network/test/api/inspection/data/apiAllInspectionsVerboseGet.data.json @@ -96,19 +96,21 @@ "additional_data-1": "additional_data-1" }, "pricing": { - "details": { - "test": { - "id": "id-1", - "hours": { - "test-3": 4 - }, - "operations": ["polishing", "sanding"], - "pricing": 3, - "related_item_id": "related_item_id-1", - "related_item_type": "part" - } - }, - "total_price": 12 + "flat_rate": { + "details": { + "test": { + "id": "id-1", + "hours": { + "test-3": 4 + }, + "operations": ["polishing", "sanding"], + "pricing": 3, + "related_item_id": "related_item_id-1", + "related_item_type": "part" + } + }, + "total_price": 12 + } }, "pdf_url": "pdf_url-1", "plate": "plate-1", diff --git a/packages/network/test/api/inspection/data/apiInspectionGet.data.json b/packages/network/test/api/inspection/data/apiInspectionGet.data.json index d3a1ade48..84efd4cc8 100644 --- a/packages/network/test/api/inspection/data/apiInspectionGet.data.json +++ b/packages/network/test/api/inspection/data/apiInspectionGet.data.json @@ -3941,39 +3941,41 @@ ], "pdf_generation_ready": true, "pricing": { - "details": { - "bumper_back": { - "hours": { - "INGREDIENT": 2, - "PAINT": 2 + "labor_cost": { + "details": { + "bumper_back": { + "hours": { + "INGREDIENT": 2, + "PAINT": 2 + }, + "id": "8bbfcba0-fdee-4268-8bd5-69dffac87aea", + "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", + "operations": ["painting"], + "pricing": 200, + "related_item_id": "fd6dd94c-d202-c9c4-fd07-7b33d524f14e", + "related_item_type": "part" }, - "id": "8bbfcba0-fdee-4268-8bd5-69dffac87aea", - "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", - "operations": ["painting"], - "pricing": 200, - "related_item_id": "fd6dd94c-d202-c9c4-fd07-7b33d524f14e", - "related_item_type": "part" - }, - "roof": { - "hours": null, - "id": "fed5af09-1e6d-0aac-febf-0d76194b3256", - "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", - "operations": null, - "pricing": 200, - "related_item_id": "f78040b7-5562-55cf-f7ea-e2c852446d45", - "related_item_type": "part" + "roof": { + "hours": null, + "id": "fed5af09-1e6d-0aac-febf-0d76194b3256", + "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", + "operations": null, + "pricing": 200, + "related_item_id": "f78040b7-5562-55cf-f7ea-e2c852446d45", + "related_item_type": "part" + }, + "wheel_front_left": { + "hours": null, + "id": "b5d64933-4bce-9e9e-b5bc-eb4c4ce8a61c", + "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", + "operations": null, + "pricing": 100, + "related_item_id": "41c29e52-6780-63e9-41a8-3c2d60a65b63", + "related_item_type": "part" + } }, - "wheel_front_left": { - "hours": null, - "id": "b5d64933-4bce-9e9e-b5bc-eb4c4ce8a61c", - "inspection_id": "5843de96-21d3-282b-5829-7ce926f510a9", - "operations": null, - "pricing": 100, - "related_item_id": "41c29e52-6780-63e9-41a8-3c2d60a65b63", - "related_item_type": "part" - } - }, - "total_price": 500 + "total_price": 500 + } }, "related_inspection_id": null, "severity_results": [ diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.json b/packages/network/test/api/inspection/data/apiInspectionPost.data.json index 771fbcd00..c87254661 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.json +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.json @@ -18,7 +18,8 @@ "pricing": { "status": "TODO", "output_format": "veb", - "config": "config" + "config": "config", + "methodology": "flat_rate" } }, "vehicle": { diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts index 4ab857759..329144c35 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts @@ -1,4 +1,4 @@ -import { BusinessClients, TaskName } from '@monkvision/types'; +import { BusinessClients, PricingMethodology, TaskName } from '@monkvision/types'; export default { tasks: [ @@ -14,6 +14,7 @@ export default { name: TaskName.PRICING, outputFormat: BusinessClients.VEB, config: 'config', + methodology: PricingMethodology.FLAT_RATE, }, ], vehicle: { diff --git a/packages/types/src/api.ts b/packages/types/src/api.ts index 49bd229bb..12fa706ca 100644 --- a/packages/types/src/api.ts +++ b/packages/types/src/api.ts @@ -119,6 +119,20 @@ export interface CreateHinlTaskOptions { callbacks?: TaskCallbackOptions[]; } +/** + * The different methodologies that can be used to calculate pricing values. + */ +export enum PricingMethodology { + /** + * The pricing are calculated using a labor cost matrix (ex: it costs 20 to perform 1h of painting). + */ + LABOR_COST = 'labor_cost', + /** + * The pricing are calculated using a flat rate per damage size (ex: it costs 20 to fix a 10cm scratch on the fender). + */ + FLAT_RATE = 'flat_rate', +} + /** * Additional options that you can specify when adding the pricing task to an inspection. */ @@ -130,13 +144,20 @@ export interface CreatePricingTaskOptions { /** * The client's output format. * - * @default 'BusinessClients.DEFAULT' + * @default BusinessClients.DEFAULT */ outputFormat?: BusinessClients; /** * The custom pricing matrix to use. */ config?: string; + /** + * The methodology used to calculate the pricing values. When the custom pricing matrix has been specified in the + * `config` param. + * + * @default PricingMethodology.LABOR + */ + methodology?: PricingMethodology; } /**