Skip to content

Commit

Permalink
Update the pricing V2 types to reflect methodology changes in API
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Nov 28, 2024
1 parent 7abfa7f commit 5820ba5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 51 deletions.
13 changes: 10 additions & 3 deletions packages/network/src/api/inspection/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
ApiInspectionPost,
ApiPartSeverityValue,
ApiPricingTaskPostComponent,
ApiPricingV2,
ApiPricingV2Details,
type ApiRelatedImages,
ApiRenderedOutput,
Expand Down Expand Up @@ -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 };
}
Expand Down Expand Up @@ -589,6 +595,7 @@ function getPricingOptions(
status: ProgressStatus.TODO,
output_format: taskOptions.outputFormat ?? 'default',
config: taskOptions.config,
methodology: taskOptions.methodology,
}
: undefined;
}
Expand Down
14 changes: 13 additions & 1 deletion packages/network/src/api/models/pricingV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ export interface ApiPricingV2Details {

export type ApiDetails = Record<string, ApiPricingV2Details>;

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;
Expand Down
3 changes: 3 additions & 0 deletions packages/network/src/api/models/task.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ApiPricingMethodology } from './pricingV2';

export type ApiBusinessClients = 'default' | 'toyota' | 'veb' | 'tesla';

export interface ApiImageInTask {
Expand Down Expand Up @@ -114,6 +116,7 @@ export interface ApiPricingTaskPostComponent {
callbacks?: ApiCallbacks;
output_format?: ApiBusinessClients;
config?: string;
methodology?: ApiPricingMethodology;
}

export interface ApiTasksComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"pricing": {
"status": "TODO",
"output_format": "veb",
"config": "config"
"config": "config",
"methodology": "flat_rate"
}
},
"vehicle": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BusinessClients, TaskName } from '@monkvision/types';
import { BusinessClients, PricingMethodology, TaskName } from '@monkvision/types';

export default {
tasks: [
Expand All @@ -14,6 +14,7 @@ export default {
name: TaskName.PRICING,
outputFormat: BusinessClients.VEB,
config: 'config',
methodology: PricingMethodology.FLAT_RATE,
},
],
vehicle: {
Expand Down
23 changes: 22 additions & 1 deletion packages/types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 5820ba5

Please sign in to comment.