From 732ad289a7876155124301bc29fb8cedee6f5654 Mon Sep 17 00:00:00 2001 From: Samy Ouyahia Date: Fri, 18 Oct 2024 10:46:19 +0200 Subject: [PATCH] Added vehicle and additional data to create inspection request --- packages/network/README.md | 15 ++++++++ .../network/src/api/inspection/mappers.ts | 36 ++++++++++++++++++- packages/network/src/api/models/vehicle.ts | 1 + .../data/apiInspectionPost.data.json | 33 +++++++++++++++-- .../inspection/data/apiInspectionPost.data.ts | 31 +++++++++++++++- .../test/api/inspection/mappers.test.ts | 4 ++- packages/types/src/api.ts | 9 +++-- 7 files changed, 121 insertions(+), 8 deletions(-) diff --git a/packages/network/README.md b/packages/network/README.md index 46906a5e7..82b9c6b35 100644 --- a/packages/network/README.md +++ b/packages/network/README.md @@ -41,6 +41,21 @@ every entity that has been fetched using this API call. |-----------|----------------------|-----------------------------|----------| | options | GetInspectionOptions | The options of the request. | ✔️ | + +### createInspection +```typescript +import { MonkApi } from '@monkvision/network'; + +MonkApi.createInspection(options, apiConfig); +``` + +Create a new inspection. This request does not modify the local state. To fetch the inspection details, use the +`getInspection` request after creating one, using the ID returned by this request. + +| Parameter | Type | Description | Required | +|-----------|-------------------------|-----------------------------|----------| +| options | CreateInspectionOptions | The options of the request. | ✔️ | + ### addImage ```typescript import { MonkApi } from '@monkvision/network'; diff --git a/packages/network/src/api/inspection/mappers.ts b/packages/network/src/api/inspection/mappers.ts index c8a872093..252fc93e8 100644 --- a/packages/network/src/api/inspection/mappers.ts +++ b/packages/network/src/api/inspection/mappers.ts @@ -497,7 +497,40 @@ function getTasksOptions(options: CreateInspectionOptions): ApiTasksComponent { export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspectionPost { return { tasks: getTasksOptions(options), - vehicle: options.vehicleType ? { vehicle_type: options.vehicleType } : undefined, + vehicle: options.vehicle + ? { + brand: options.vehicle.brand, + model: options.vehicle.model, + plate: options.vehicle.plate, + vehicle_type: options.vehicle.type, + mileage: + options.vehicle.mileageUnit && options.vehicle.mileageValue + ? { + value: options.vehicle.mileageValue, + unit: options.vehicle.mileageUnit, + } + : undefined, + market_value: + options.vehicle.marketValueUnit && options.vehicle.marketValue + ? { + value: options.vehicle.marketValue, + unit: options.vehicle.marketValueUnit, + } + : undefined, + vin: options.vehicle.vin, + color: options.vehicle.color, + exterior_cleanliness: options.vehicle.exteriorCleanliness, + interior_cleanliness: options.vehicle.interiorCleanliness, + date_of_circulation: options.vehicle.dateOfCirculation, + duplicate_keys: options.vehicle.duplicateKeys, + expertise_requested: options.vehicle.expertiseRequested, + car_registration: options.vehicle.carRegistration, + vehicle_quotation: options.vehicle.vehicleQuotation, + trade_in_offer: options.vehicle.tradeInOffer, + owner_info: options.vehicle.ownerInfo, + additional_data: options.vehicle.additionalData, + } + : undefined, damage_severity: { output_format: 'toyota' }, pricing: options.usePricingV2 ? { output_format: 'toyota' } : undefined, additional_data: { @@ -507,6 +540,7 @@ export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspe damage_detection_version: 'v2', use_dynamic_crops: options.useDynamicCrops ?? true, is_video_capture: options.isVideoCapture ?? false, + ...options.additionalData, }, }; } diff --git a/packages/network/src/api/models/vehicle.ts b/packages/network/src/api/models/vehicle.ts index cfab8f160..95ca3093f 100644 --- a/packages/network/src/api/models/vehicle.ts +++ b/packages/network/src/api/models/vehicle.ts @@ -62,4 +62,5 @@ export interface ApiVehiclePostPatch { car_registration?: boolean; vehicle_quotation?: number; trade_in_offer?: number; + additional_data?: ApiAdditionalData; } diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.json b/packages/network/test/api/inspection/data/apiInspectionPost.data.json index bb244d084..ede8e3baa 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.json +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.json @@ -17,7 +17,34 @@ } }, "vehicle": { - "vehicle_type": "hatchback" + "brand": "brand", + "model": "model", + "plate": "plate", + "vehicle_type": "hatchback", + "mileage": { + "unit": "mileageUnit", + "value": 34 + }, + "market_value": { + "unit": "marketValueUnit", + "value": 45 + }, + "vin": "vin", + "color": "color", + "exterior_cleanliness": "exteriorCleanliness", + "interior_cleanliness": "interiorCleanliness", + "date_of_circulation": "dateOfCirculation", + "duplicate_keys": "duplicateKeys", + "expertise_requested": "expertiseRequested", + "car_registration": "carRegistration", + "vehicle_quotation": "vehicleQuotation", + "trade_in_offer": "tradeInOffer", + "owner_info": { + "test": "data" + }, + "additional_data": { + "additional": "data" + } }, "damage_severity": { "output_format": "toyota" @@ -28,6 +55,8 @@ "additional_data": { "damage_detection_version": "v2", "use_dynamic_crops": true, - "is_video_capture": true + "is_video_capture": true, + "test": "uno", + "test2": "dos" } } diff --git a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts index ba7a394bf..6f67af953 100644 --- a/packages/network/test/api/inspection/data/apiInspectionPost.data.ts +++ b/packages/network/test/api/inspection/data/apiInspectionPost.data.ts @@ -11,8 +11,37 @@ export default { generateSubimageParts: true, }, ], - vehicleType: 'hatchback', + vehicle: { + brand: 'brand', + model: 'model', + plate: 'plate', + type: 'hatchback', + mileageUnit: 'mileageUnit', + mileageValue: 34, + marketValueUnit: 'marketValueUnit', + marketValue: 45, + vin: 'vin', + color: 'color', + exteriorCleanliness: 'exteriorCleanliness', + interiorCleanliness: 'interiorCleanliness', + dateOfCirculation: 'dateOfCirculation', + duplicateKeys: 'duplicateKeys', + expertiseRequested: 'expertiseRequested', + carRegistration: 'carRegistration', + vehicleQuotation: 'vehicleQuotation', + tradeInOffer: 'tradeInOffer', + ownerInfo: { + test: 'data', + }, + additionalData: { + additional: 'data', + }, + }, useDynamicCrops: true, usePricingV2: true, isVideoCapture: true, + additionalData: { + test: 'uno', + test2: 'dos', + }, }; diff --git a/packages/network/test/api/inspection/mappers.test.ts b/packages/network/test/api/inspection/mappers.test.ts index c10794bdd..58bda76e8 100644 --- a/packages/network/test/api/inspection/mappers.test.ts +++ b/packages/network/test/api/inspection/mappers.test.ts @@ -17,7 +17,9 @@ describe('Inspection API Mappers', () => { describe('ApiInspectionPost mapper', () => { it('should properly map the ApiInspectionGet object', () => { - const result = mapApiInspectionPost(apiInspectionPostData as CreateInspectionOptions); + const result = mapApiInspectionPost( + apiInspectionPostData as unknown as CreateInspectionOptions, + ); (apiInspectionPostMapped.additional_data as any).user_agent = expect.any(String); (apiInspectionPostMapped.additional_data as any).monk_sdk_version = sdkVersion; expect(result).toEqual(apiInspectionPostMapped); diff --git a/packages/types/src/api.ts b/packages/types/src/api.ts index 46cd8ab14..346c0a2c7 100644 --- a/packages/types/src/api.ts +++ b/packages/types/src/api.ts @@ -1,5 +1,4 @@ -import { TaskName } from './state'; -import { VehicleType } from './sights'; +import { AdditionalData, TaskName, Vehicle } from './state'; /** * Enumeration of the API permissions included in the Monk authentication token. @@ -119,7 +118,7 @@ export interface CreateInspectionOptions { /** * Additional details about the vehicle of the inspection (vehicle type, VIN etc.). */ - vehicleType?: VehicleType; + vehicle?: Vehicle; /** * Boolean indicating if the API should generate dynamic crops or not. * @@ -138,4 +137,8 @@ export interface CreateInspectionOptions { * @default false */ isVideoCapture?: boolean; + /** + * Additional data of the inspection. + */ + additionalData?: AdditionalData; }