From 53c7281cb30bd3edb98e7499c95c1087ed343f90 Mon Sep 17 00:00:00 2001 From: David Ly Date: Thu, 7 Nov 2024 22:50:45 +0100 Subject: [PATCH] Enable pricing via tasks --- documentation/src/utils/schemas.ts | 10 ++++-- .../network/src/api/inspection/mappers.ts | 24 +++++++++++++- packages/network/src/api/models/inspection.ts | 5 +-- packages/network/src/api/models/task.ts | 9 +++++ .../data/apiInspectionPost.data.json | 7 ++-- .../inspection/data/apiInspectionPost.data.ts | 2 +- packages/types/src/api.ts | 33 +++++++++++++++---- 7 files changed, 72 insertions(+), 18 deletions(-) diff --git a/documentation/src/utils/schemas.ts b/documentation/src/utils/schemas.ts index 005da5c15..7dd033f02 100644 --- a/documentation/src/utils/schemas.ts +++ b/documentation/src/utils/schemas.ts @@ -11,6 +11,7 @@ import { SteeringWheelPosition, TaskName, VehicleType, + BusinessClients, } from '@monkvision/types'; import { sights } from '@monkvision/sights'; import { flatten } from '@monkvision/common'; @@ -191,10 +192,16 @@ export const CreateHinlTaskOptionsSchema = z.object({ callbacks: z.array(TaskCallbackOptionsSchema).optional(), }); +export const CreatePricingTaskOptionsSchema = z.object({ + name: z.literal(TaskName.PRICING), + outputFormat: z.nativeEnum(BusinessClients).optional(), +}); + export const InspectionCreateTaskSchema = z .nativeEnum(TaskName) .or(CreateDamageDetectionTaskOptionsSchema) - .or(CreateDamageDetectionTaskOptionsSchema); + .or(CreateHinlTaskOptionsSchema) + .or(CreatePricingTaskOptionsSchema); export const AdditionalDataSchema = z.record(z.string(), z.unknown()); @@ -225,7 +232,6 @@ export const CreateInspectionOptionsSchema = z.object({ tasks: z.array(InspectionCreateTaskSchema), vehicle: InspectionCreateVehicleSchema.optional(), useDynamicCrops: z.boolean().optional(), - usePricingV2: z.boolean().optional(), additionalData: AdditionalDataSchema.optional(), }); diff --git a/packages/network/src/api/inspection/mappers.ts b/packages/network/src/api/inspection/mappers.ts index de96d30bd..004e547ce 100644 --- a/packages/network/src/api/inspection/mappers.ts +++ b/packages/network/src/api/inspection/mappers.ts @@ -4,6 +4,7 @@ import { CreateDamageDetectionTaskOptions, CreateHinlTaskOptions, CreateInspectionOptions, + CreatePricingTaskOptions, CurrencyCode, CustomSeverityValue, Damage, @@ -40,6 +41,7 @@ import { ApiInspectionGet, ApiInspectionPost, ApiPartSeverityValue, + ApiPricingTaskPostComponent, ApiPricingV2Details, ApiRenderedOutput, ApiSeverityResult, @@ -486,12 +488,33 @@ function getImagesOCROptions( : undefined; } +function getPricingOptions( + options: CreateInspectionOptions, +): ApiPricingTaskPostComponent | undefined { + if (options.tasks.includes(TaskName.PRICING)) { + return { + status: ProgressStatus.TODO, + output_format: 'default', + }; + } + const taskOptions = options.tasks.find( + (task) => typeof task === 'object' && task.name === TaskName.PRICING, + ) as CreatePricingTaskOptions | undefined; + return taskOptions + ? { + status: ProgressStatus.TODO, + output_format: taskOptions.outputFormat ?? 'default', + } + : undefined; +} + function getTasksOptions(options: CreateInspectionOptions): ApiTasksComponent { return { damage_detection: getDamageDetectionOptions(options), wheel_analysis: getWheelAnalysisOptions(options), images_ocr: getImagesOCROptions(options), human_in_the_loop: getHumanInTheLoopOptions(options), + pricing: getPricingOptions(options), }; } @@ -534,7 +557,6 @@ export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspe } : undefined, damage_severity: { output_format: 'default' }, - pricing: options.usePricingV2 ? { output_format: 'default' } : undefined, additional_data: { user_agent: navigator.userAgent, connection: navigator.connection, diff --git a/packages/network/src/api/models/inspection.ts b/packages/network/src/api/models/inspection.ts index db7128293..118b2df50 100644 --- a/packages/network/src/api/models/inspection.ts +++ b/packages/network/src/api/models/inspection.ts @@ -4,7 +4,7 @@ import type { ApiImagePost, ApiImages } from './image'; import type { ApiParts } from './part'; import type { ApiPricingV2 } from './pricingV2'; import type { ApiSeverityResults } from './severityResult'; -import type { ApiTasks } from './task'; +import type { ApiBusinessClients, ApiTasks } from './task'; import type { ApiVehicleComponent } from './vehicle'; import type { ApiWheelAnalysis } from './wheelAnalysis'; import { ApiVehiclePostPatch } from './vehicle'; @@ -29,8 +29,6 @@ export interface ApiInspectionGet { wheel_analysis?: ApiWheelAnalysis; } -export type ApiBusinessClients = 'default' | 'toyota' | 'veb'; - export interface ApiDamageSeverity { output_format: ApiBusinessClients; } @@ -41,5 +39,4 @@ export interface ApiInspectionPost { images?: ApiImagePost[]; vehicle?: ApiVehiclePostPatch; damage_severity?: ApiDamageSeverity; - pricing?: ApiDamageSeverity; } diff --git a/packages/network/src/api/models/task.ts b/packages/network/src/api/models/task.ts index ee4da4512..5dd031410 100644 --- a/packages/network/src/api/models/task.ts +++ b/packages/network/src/api/models/task.ts @@ -1,3 +1,5 @@ +export type ApiBusinessClients = 'default' | 'toyota' | 'veb' | 'tesla'; + export interface ApiImageInTask { image_id: string; } @@ -107,9 +109,16 @@ export interface ApiHinlTaskPostComponent { callbacks?: ApiCallbacks; } +export interface ApiPricingTaskPostComponent { + status?: ApiTaskPostProgressStatus; + callbacks?: ApiCallbacks; + output_format?: ApiBusinessClients; +} + export interface ApiTasksComponent { damage_detection?: ApiDamageDetectionTaskPostComponent; wheel_analysis?: ApiWheelAnalysisTaskPostComponent; images_ocr?: ApiImagesOCRTaskPostComponent; human_in_the_loop?: ApiHinlTaskPostComponent; + pricing?: ApiPricingTaskPostComponent; } diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.json b/packages/network/test/api/inspection/data/apiInspectionPost.data.json index 2e5a4be80..87dd3af51 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.json +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.json @@ -14,6 +14,10 @@ "wheel_analysis": { "status": "NOT_STARTED", "use_longshots": true + }, + "pricing": { + "status": "TODO", + "output_format": "default" } }, "vehicle": { @@ -50,9 +54,6 @@ "damage_severity": { "output_format": "default" }, - "pricing": { - "output_format": "default" - }, "additional_data": { "damage_detection_version": "v2", "use_dynamic_crops": true, diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts index 2982a306d..688545bb4 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts @@ -10,6 +10,7 @@ export default { generateSubimageDamages: true, generateSubimageParts: true, }, + TaskName.PRICING, ], vehicle: { brand: 'brand', @@ -39,7 +40,6 @@ export default { }, }, useDynamicCrops: true, - usePricingV2: true, isVideoCapture: true, additionalData: { test: 'uno', diff --git a/packages/types/src/api.ts b/packages/types/src/api.ts index 980cbb549..b3689bf3b 100644 --- a/packages/types/src/api.ts +++ b/packages/types/src/api.ts @@ -23,6 +23,16 @@ export enum MonkApiPermission { INSPECTION_WRITE_ORGANIZATION = 'monk_core_api:inspections:write_organization', } +/** + * Enumeration of Monk response format. + */ +export enum BusinessClients { + DEFAULT = 'default', + TOYOTA = 'toyota', + VEB = 'veb', + TESLA = 'tesla', +} + /** * Options used to specify a callback that will be called by the API when a task is complete. */ @@ -97,6 +107,20 @@ export interface CreateHinlTaskOptions { callbacks?: TaskCallbackOptions[]; } +/** + * Additional options that you can specify when adding the pricing task to an inspection. + */ +export interface CreatePricingTaskOptions { + /** + * The name of the task : `TaskName.PRICING`. + */ + name: TaskName.PRICING; + /** + * The client's output format. + */ + outputFormat?: BusinessClients; +} + /** * The tasks of the inspection to be created. It is either simply the name of the task to add, or an object with the * task name as well as additional configuration options for the task. @@ -104,7 +128,8 @@ export interface CreateHinlTaskOptions { export type InspectionCreateTask = | TaskName | CreateDamageDetectionTaskOptions - | CreateHinlTaskOptions; + | CreateHinlTaskOptions + | CreatePricingTaskOptions; /** * Options that can be specified when creating a new inspection. @@ -125,12 +150,6 @@ export interface CreateInspectionOptions { * @default true */ useDynamicCrops?: boolean; - /** - * Boolean indicating if the pricing V2 (format Toyota) should be enabled or not. - * - * @default false - */ - usePricingV2?: boolean; /** * Boolean indicating if the inspection to create will be used with the VideoCapture workflow or not. *