Skip to content

Commit

Permalink
Added vehicle and additional data to create inspection request
Browse files Browse the repository at this point in the history
  • Loading branch information
souyahia-monk committed Oct 18, 2024
1 parent 609b0e8 commit 732ad28
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 8 deletions.
15 changes: 15 additions & 0 deletions packages/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
36 changes: 35 additions & 1 deletion packages/network/src/api/inspection/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
},
};
}
1 change: 1 addition & 0 deletions packages/network/src/api/models/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ export interface ApiVehiclePostPatch {
car_registration?: boolean;
vehicle_quotation?: number;
trade_in_offer?: number;
additional_data?: ApiAdditionalData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};
4 changes: 3 additions & 1 deletion packages/network/test/api/inspection/mappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions packages/types/src/api.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
*
Expand All @@ -138,4 +137,8 @@ export interface CreateInspectionOptions {
* @default false
*/
isVideoCapture?: boolean;
/**
* Additional data of the inspection.
*/
additionalData?: AdditionalData;
}

0 comments on commit 732ad28

Please sign in to comment.