Skip to content

Commit b92e92e

Browse files
Added vehicle and additional data to create inspection request (#856)
1 parent 609b0e8 commit b92e92e

File tree

7 files changed

+121
-8
lines changed

7 files changed

+121
-8
lines changed

packages/network/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ every entity that has been fetched using this API call.
4141
|-----------|----------------------|-----------------------------|----------|
4242
| options | GetInspectionOptions | The options of the request. | ✔️ |
4343

44+
45+
### createInspection
46+
```typescript
47+
import { MonkApi } from '@monkvision/network';
48+
49+
MonkApi.createInspection(options, apiConfig);
50+
```
51+
52+
Create a new inspection. This request does not modify the local state. To fetch the inspection details, use the
53+
`getInspection` request after creating one, using the ID returned by this request.
54+
55+
| Parameter | Type | Description | Required |
56+
|-----------|-------------------------|-----------------------------|----------|
57+
| options | CreateInspectionOptions | The options of the request. | ✔️ |
58+
4459
### addImage
4560
```typescript
4661
import { MonkApi } from '@monkvision/network';

packages/network/src/api/inspection/mappers.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,40 @@ function getTasksOptions(options: CreateInspectionOptions): ApiTasksComponent {
497497
export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspectionPost {
498498
return {
499499
tasks: getTasksOptions(options),
500-
vehicle: options.vehicleType ? { vehicle_type: options.vehicleType } : undefined,
500+
vehicle: options.vehicle
501+
? {
502+
brand: options.vehicle.brand,
503+
model: options.vehicle.model,
504+
plate: options.vehicle.plate,
505+
vehicle_type: options.vehicle.type,
506+
mileage:
507+
options.vehicle.mileageUnit && options.vehicle.mileageValue
508+
? {
509+
value: options.vehicle.mileageValue,
510+
unit: options.vehicle.mileageUnit,
511+
}
512+
: undefined,
513+
market_value:
514+
options.vehicle.marketValueUnit && options.vehicle.marketValue
515+
? {
516+
value: options.vehicle.marketValue,
517+
unit: options.vehicle.marketValueUnit,
518+
}
519+
: undefined,
520+
vin: options.vehicle.vin,
521+
color: options.vehicle.color,
522+
exterior_cleanliness: options.vehicle.exteriorCleanliness,
523+
interior_cleanliness: options.vehicle.interiorCleanliness,
524+
date_of_circulation: options.vehicle.dateOfCirculation,
525+
duplicate_keys: options.vehicle.duplicateKeys,
526+
expertise_requested: options.vehicle.expertiseRequested,
527+
car_registration: options.vehicle.carRegistration,
528+
vehicle_quotation: options.vehicle.vehicleQuotation,
529+
trade_in_offer: options.vehicle.tradeInOffer,
530+
owner_info: options.vehicle.ownerInfo,
531+
additional_data: options.vehicle.additionalData,
532+
}
533+
: undefined,
501534
damage_severity: { output_format: 'toyota' },
502535
pricing: options.usePricingV2 ? { output_format: 'toyota' } : undefined,
503536
additional_data: {
@@ -507,6 +540,7 @@ export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspe
507540
damage_detection_version: 'v2',
508541
use_dynamic_crops: options.useDynamicCrops ?? true,
509542
is_video_capture: options.isVideoCapture ?? false,
543+
...options.additionalData,
510544
},
511545
};
512546
}

packages/network/src/api/models/vehicle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ export interface ApiVehiclePostPatch {
6262
car_registration?: boolean;
6363
vehicle_quotation?: number;
6464
trade_in_offer?: number;
65+
additional_data?: ApiAdditionalData;
6566
}

packages/network/test/api/inspection/data/apiInspectionPost.data.json

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,34 @@
1717
}
1818
},
1919
"vehicle": {
20-
"vehicle_type": "hatchback"
20+
"brand": "brand",
21+
"model": "model",
22+
"plate": "plate",
23+
"vehicle_type": "hatchback",
24+
"mileage": {
25+
"unit": "mileageUnit",
26+
"value": 34
27+
},
28+
"market_value": {
29+
"unit": "marketValueUnit",
30+
"value": 45
31+
},
32+
"vin": "vin",
33+
"color": "color",
34+
"exterior_cleanliness": "exteriorCleanliness",
35+
"interior_cleanliness": "interiorCleanliness",
36+
"date_of_circulation": "dateOfCirculation",
37+
"duplicate_keys": "duplicateKeys",
38+
"expertise_requested": "expertiseRequested",
39+
"car_registration": "carRegistration",
40+
"vehicle_quotation": "vehicleQuotation",
41+
"trade_in_offer": "tradeInOffer",
42+
"owner_info": {
43+
"test": "data"
44+
},
45+
"additional_data": {
46+
"additional": "data"
47+
}
2148
},
2249
"damage_severity": {
2350
"output_format": "toyota"
@@ -28,6 +55,8 @@
2855
"additional_data": {
2956
"damage_detection_version": "v2",
3057
"use_dynamic_crops": true,
31-
"is_video_capture": true
58+
"is_video_capture": true,
59+
"test": "uno",
60+
"test2": "dos"
3261
}
3362
}

packages/network/test/api/inspection/data/apiInspectionPost.data.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,37 @@ export default {
1111
generateSubimageParts: true,
1212
},
1313
],
14-
vehicleType: 'hatchback',
14+
vehicle: {
15+
brand: 'brand',
16+
model: 'model',
17+
plate: 'plate',
18+
type: 'hatchback',
19+
mileageUnit: 'mileageUnit',
20+
mileageValue: 34,
21+
marketValueUnit: 'marketValueUnit',
22+
marketValue: 45,
23+
vin: 'vin',
24+
color: 'color',
25+
exteriorCleanliness: 'exteriorCleanliness',
26+
interiorCleanliness: 'interiorCleanliness',
27+
dateOfCirculation: 'dateOfCirculation',
28+
duplicateKeys: 'duplicateKeys',
29+
expertiseRequested: 'expertiseRequested',
30+
carRegistration: 'carRegistration',
31+
vehicleQuotation: 'vehicleQuotation',
32+
tradeInOffer: 'tradeInOffer',
33+
ownerInfo: {
34+
test: 'data',
35+
},
36+
additionalData: {
37+
additional: 'data',
38+
},
39+
},
1540
useDynamicCrops: true,
1641
usePricingV2: true,
1742
isVideoCapture: true,
43+
additionalData: {
44+
test: 'uno',
45+
test2: 'dos',
46+
},
1847
};

packages/network/test/api/inspection/mappers.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('Inspection API Mappers', () => {
1717

1818
describe('ApiInspectionPost mapper', () => {
1919
it('should properly map the ApiInspectionGet object', () => {
20-
const result = mapApiInspectionPost(apiInspectionPostData as CreateInspectionOptions);
20+
const result = mapApiInspectionPost(
21+
apiInspectionPostData as unknown as CreateInspectionOptions,
22+
);
2123
(apiInspectionPostMapped.additional_data as any).user_agent = expect.any(String);
2224
(apiInspectionPostMapped.additional_data as any).monk_sdk_version = sdkVersion;
2325
expect(result).toEqual(apiInspectionPostMapped);

packages/types/src/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TaskName } from './state';
2-
import { VehicleType } from './sights';
1+
import { AdditionalData, TaskName, Vehicle } from './state';
32

43
/**
54
* Enumeration of the API permissions included in the Monk authentication token.
@@ -119,7 +118,7 @@ export interface CreateInspectionOptions {
119118
/**
120119
* Additional details about the vehicle of the inspection (vehicle type, VIN etc.).
121120
*/
122-
vehicleType?: VehicleType;
121+
vehicle?: Vehicle;
123122
/**
124123
* Boolean indicating if the API should generate dynamic crops or not.
125124
*
@@ -138,4 +137,8 @@ export interface CreateInspectionOptions {
138137
* @default false
139138
*/
140139
isVideoCapture?: boolean;
140+
/**
141+
* Additional data of the inspection.
142+
*/
143+
additionalData?: AdditionalData;
141144
}

0 commit comments

Comments
 (0)