Skip to content

Commit 4c3ab24

Browse files
authored
Merge branch 'main' into customer-interactions-tweaks
2 parents c2f0039 + cb9970a commit 4c3ab24

27 files changed

+335
-74
lines changed

dist/Client.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { InternalResponse } from './types/Response';
1111
import { GroupsService } from './services/GroupService';
1212
import { VehiclesService } from './services/VehiclesService';
1313
import { EquipmentService } from './services/EquipmentService';
14+
import { EquipmentExposureService } from './services/EquipmentExposureService';
1415
import { VehicleManufacturersService } from '@services/VehicleManufacturersService';
1516
import { VehicleModelsService } from '@services/VehicleModelsService';
1617
import { VehicleCategoriesService } from '@services/VehicleCategoriesService';
@@ -28,6 +29,7 @@ import { WorkOrdersService } from '@services/WorkOrdersService';
2829
import { OperationsService } from '@services/OperationsService';
2930
import { OperationTemplatesService } from '@services/OperationTemplatesService';
3031
import { VehicleInspectionService } from '@services/VehicleInspectionService';
32+
import { VehicleInventoryCheckService } from '@services/VehicleInventoryCheckService';
3133
export declare class Client {
3234
readonly config: ClientConfigInterface;
3335
organisation: string;
@@ -58,12 +60,14 @@ export declare class Client {
5860
vehicleCategories(): VehicleCategoriesService;
5961
vehicleModels(): VehicleModelsService;
6062
equipment(): EquipmentService;
63+
equipmentExposures(): EquipmentExposureService;
6164
equipmentManufacturers(): EquipmentManufacturersService;
6265
equipmentModels(): EquipmentModelsService;
6366
equipmentCategories(): EquipmentCategoriesService;
6467
properties(): PropertiesService;
6568
vehicleModelSpecifications(): VehicleModelSpecificationService;
6669
vehicleInspections(): VehicleInspectionService;
70+
vehicleInventoryChecks(): VehicleInventoryCheckService;
6771
setOrganisationSlug(organisation: string): void;
6872
substituteOrganisation(url: string): string;
6973
makeDeleteRequest(endpoint: string): Promise<any>;

dist/Client.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ServiceAccountKeysService } from './services/ServiceAccountKeysService'
1010
import { GroupsService } from './services/GroupService';
1111
import { VehiclesService } from './services/VehiclesService';
1212
import { EquipmentService } from './services/EquipmentService';
13+
import { EquipmentExposureService } from './services/EquipmentExposureService';
1314
import { VehicleManufacturersService } from '@services/VehicleManufacturersService';
1415
import { VehicleModelsService } from '@services/VehicleModelsService';
1516
import { VehicleCategoriesService } from '@services/VehicleCategoriesService';
@@ -27,6 +28,7 @@ import { WorkOrdersService } from '@services/WorkOrdersService';
2728
import { OperationsService } from '@services/OperationsService';
2829
import { OperationTemplatesService } from '@services/OperationTemplatesService';
2930
import { VehicleInspectionService } from '@services/VehicleInspectionService';
31+
import { VehicleInventoryCheckService } from '@services/VehicleInventoryCheckService';
3032
export class Client {
3133
config;
3234
organisation;
@@ -127,6 +129,9 @@ export class Client {
127129
equipment() {
128130
return new EquipmentService(this);
129131
}
132+
equipmentExposures() {
133+
return new EquipmentExposureService(this);
134+
}
130135
equipmentManufacturers() {
131136
return new EquipmentManufacturersService(this);
132137
}
@@ -145,6 +150,9 @@ export class Client {
145150
vehicleInspections() {
146151
return new VehicleInspectionService(this);
147152
}
153+
vehicleInventoryChecks() {
154+
return new VehicleInventoryCheckService(this);
155+
}
148156
setOrganisationSlug(organisation) {
149157
this.config.organisationId = organisation;
150158
}
@@ -211,7 +219,7 @@ export class Client {
211219
try {
212220
// @todo switch on cookie, "X-Session-Token" or client_credentials
213221
const fetchResponse = await fetch(url, {
214-
credentials: 'include', // @todo only required for cookie based auth,
222+
credentials: 'include',
215223
headers: headers,
216224
});
217225
let json = await fetchResponse.json();

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { CustomerAccount } from './models/CustomerAccount';
1010
export { CustomerInteraction } from './models/CustomerInteraction';
1111
export { Equipment } from './models/Equipment';
1212
export { EquipmentCategory } from './models/EquipmentCategory';
13+
export { EquipmentExposure } from './models/EquipmentExposure';
1314
export { EquipmentModel } from './models/EquipmentModel';
1415
export { EquipmentManufacturer } from './models/EquipmentManufacturer';
1516
export { Form } from './models/Form';

dist/index.js

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,61 @@ class EquipmentCategory extends BaseModel {
214214
}
215215
}
216216

217+
// src/models/EquipmentExposure.ts
218+
class EquipmentExposure extends BaseModel {
219+
type = "equipment-exposures";
220+
start_time;
221+
end_time;
222+
location = {
223+
type: "Point",
224+
coordinates: [0, 0]
225+
};
226+
ppe = {
227+
mask: false,
228+
ear_defenders: false
229+
};
230+
jsonApiMapping() {
231+
return {
232+
attributes: ["end_time", "location", "ppe", "start_time"],
233+
relationships: {
234+
author: "author",
235+
equipment: "equipment"
236+
}
237+
};
238+
}
239+
static relationships = [
240+
{
241+
name: "author",
242+
type: "single",
243+
modelType: "users"
244+
},
245+
{
246+
name: "equipment",
247+
type: "single",
248+
modelType: "equipment"
249+
}
250+
];
251+
constructor(data) {
252+
super(data);
253+
this.start_time = data?.attributes?.start_time?.id ?? data?.start_time ?? "";
254+
this.end_time = data?.attributes?.end_time ?? data?.end_time ?? "";
255+
if (data?.attributes?.location) {
256+
const locationData = data.attributes.location;
257+
this.location = {
258+
type: locationData.type ?? "",
259+
coordinates: locationData.coordinates ?? []
260+
};
261+
}
262+
if (data?.attributes?.ppe) {
263+
const ppeData = data.attributes.ppe;
264+
this.ppe = {
265+
mask: ppeData.ppe?.mask ?? false,
266+
ear_defenders: ppeData.ppe?.ear_defenders ?? false
267+
};
268+
}
269+
}
270+
}
271+
217272
// src/models/EquipmentModel.ts
218273
class EquipmentModel extends BaseModel {
219274
type = "equipment-models";
@@ -590,7 +645,8 @@ class VehicleInventoryCheck extends BaseModel {
590645
return {
591646
attributes: ["registration", "vin", "description", "colour"],
592647
relationships: {
593-
specification: "vehicle-specifications"
648+
author: "author",
649+
vehicle: "vehicle"
594650
}
595651
};
596652
}
@@ -604,6 +660,11 @@ class VehicleInventoryCheck extends BaseModel {
604660
name: "author",
605661
type: "single",
606662
modelType: "users"
663+
},
664+
{
665+
name: "vehicle",
666+
type: "single",
667+
modelType: "vehicles"
607668
}
608669
];
609670
constructor(data) {
@@ -1048,6 +1109,7 @@ class Hydrator {
10481109
"customer-interactions": CustomerInteraction,
10491110
"equipment-categories": EquipmentCategory,
10501111
"equipment-items": Equipment,
1112+
"equipment-exposures": EquipmentExposure,
10511113
"equipment-models": EquipmentModel,
10521114
"equipment-manufacturers": EquipmentManufacturer,
10531115
forms: Form,
@@ -1506,14 +1568,6 @@ class VehiclesService extends BaseService {
15061568
};
15071569
return await this.client.makePostRequest(enquiryEndpoint, body);
15081570
}
1509-
async inventoryChecks(vehicleId) {
1510-
const includes = "?include=author,equipment,equipment.model,equipment.model.categories,equipment.model.manufacturer";
1511-
const inventoryChecksEndpoint = `${this.endpoint}/${vehicleId}/inventory-checks${includes}`;
1512-
const resp = await this.client.makeGetRequest(inventoryChecksEndpoint);
1513-
const hydrator = new Hydrator;
1514-
resp.data = hydrator.hydrateResponse(resp.data, resp.included);
1515-
return resp;
1516-
}
15171571
async motRecords(vehicleId) {
15181572
const motRecordsEndpoint = `${this.endpoint}/${vehicleId}/mot-records`;
15191573
const resp = await this.client.makeGetRequest(motRecordsEndpoint);
@@ -1530,6 +1584,13 @@ class EquipmentService extends BaseService {
15301584
}
15311585
}
15321586

1587+
// src/services/EquipmentExposureService.ts
1588+
class EquipmentExposureService extends BaseService {
1589+
constructor(client) {
1590+
super(client, "/v3/orgs/:orgId/assets/equipment/exposures");
1591+
}
1592+
}
1593+
15331594
// src/services/VehicleManufacturersService.ts
15341595
class VehicleManufacturersService extends BaseService {
15351596
constructor(client) {
@@ -1700,6 +1761,13 @@ class VehicleInspectionService extends BaseService {
17001761
}
17011762
}
17021763

1764+
// src/services/VehicleInventoryCheckService.ts
1765+
class VehicleInventoryCheckService extends BaseService {
1766+
constructor(client) {
1767+
super(client, "/v3/orgs/:orgId/assets/vehicles/inventory-checks");
1768+
}
1769+
}
1770+
17031771
// src/Client.ts
17041772
class Client {
17051773
config;
@@ -1801,6 +1869,9 @@ class Client {
18011869
equipment() {
18021870
return new EquipmentService(this);
18031871
}
1872+
equipmentExposures() {
1873+
return new EquipmentExposureService(this);
1874+
}
18041875
equipmentManufacturers() {
18051876
return new EquipmentManufacturersService(this);
18061877
}
@@ -1819,6 +1890,9 @@ class Client {
18191890
vehicleInspections() {
18201891
return new VehicleInspectionService(this);
18211892
}
1893+
vehicleInventoryChecks() {
1894+
return new VehicleInventoryCheckService(this);
1895+
}
18221896
setOrganisationSlug(organisation) {
18231897
this.config.organisationId = organisation;
18241898
}
@@ -2000,6 +2074,7 @@ export {
20002074
Form,
20012075
EquipmentModel,
20022076
EquipmentManufacturer,
2077+
EquipmentExposure,
20032078
EquipmentCategory,
20042079
Equipment,
20052080
CustomerInteraction,

dist/models/EquipmentExposure.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { RelationshipDefinition } from '../types/RelationshipDefinition';
2+
import { BaseModel } from '@models/BaseModel';
3+
import type { JsonApiMapping } from '../types/JsonApiMapping';
4+
type Location = {
5+
type: "Point";
6+
coordinates: [number, number];
7+
};
8+
type PPE = {
9+
mask: boolean;
10+
ear_defenders: boolean;
11+
};
12+
export declare class EquipmentExposure extends BaseModel implements Partial<JsonApiMapping> {
13+
type: string;
14+
start_time: string;
15+
end_time: string;
16+
location: Location;
17+
ppe: PPE;
18+
jsonApiMapping(): {
19+
attributes: string[];
20+
relationships: {
21+
author: string;
22+
equipment: string;
23+
};
24+
};
25+
static relationships: RelationshipDefinition[];
26+
constructor(data?: any);
27+
}
28+
export {};

dist/models/EquipmentExposure.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { BaseModel } from '@models/BaseModel';
2+
export class EquipmentExposure extends BaseModel {
3+
type = 'equipment-exposures';
4+
start_time; // ISO date string
5+
end_time; // ISO date string
6+
location = {
7+
type: "Point",
8+
coordinates: [0, 0],
9+
};
10+
ppe = {
11+
mask: false,
12+
ear_defenders: false,
13+
};
14+
jsonApiMapping() {
15+
return {
16+
attributes: ['end_time', 'location', 'ppe', 'start_time'],
17+
relationships: {
18+
author: 'author',
19+
equipment: 'equipment',
20+
},
21+
};
22+
}
23+
static relationships = [
24+
{
25+
name: 'author',
26+
type: 'single',
27+
modelType: 'users',
28+
},
29+
{
30+
name: 'equipment',
31+
type: 'single',
32+
modelType: 'equipment',
33+
},
34+
];
35+
constructor(data) {
36+
super(data);
37+
this.start_time = data?.attributes?.start_time?.id ?? data?.start_time ?? '';
38+
this.end_time = data?.attributes?.end_time ?? data?.end_time ?? '';
39+
if (data?.attributes?.location) {
40+
const locationData = data.attributes.location;
41+
this.location = {
42+
type: locationData.type ?? '',
43+
coordinates: locationData.coordinates ?? []
44+
};
45+
}
46+
if (data?.attributes?.ppe) {
47+
const ppeData = data.attributes.ppe;
48+
this.ppe = {
49+
mask: ppeData.ppe?.mask ?? false,
50+
ear_defenders: ppeData.ppe?.ear_defenders ?? false
51+
};
52+
}
53+
}
54+
}

dist/models/VehicleInventoryCheck.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export declare class VehicleInventoryCheck extends BaseModel implements Partial<
1414
jsonApiMapping(): {
1515
attributes: string[];
1616
relationships: {
17-
specification: string;
17+
author: string;
18+
vehicle: string;
1819
};
1920
};
2021
static relationships: RelationshipDefinition[];

dist/models/VehicleInventoryCheck.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export class VehicleInventoryCheck extends BaseModel {
77
return {
88
attributes: ['registration', 'vin', 'description', 'colour'],
99
relationships: {
10-
specification: 'vehicle-specifications',
10+
author: 'author',
11+
vehicle: 'vehicle',
1112
},
1213
};
1314
}
@@ -22,6 +23,11 @@ export class VehicleInventoryCheck extends BaseModel {
2223
type: 'single',
2324
modelType: 'users',
2425
},
26+
{
27+
name: 'vehicle',
28+
type: 'single',
29+
modelType: 'vehicles',
30+
},
2531
];
2632
constructor(data) {
2733
super(data);

dist/services/BaseService.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ export declare class BaseService<T extends Model> extends RequestBuilder {
1313
constructor(client: Client, endpoint: string);
1414
convertToJsonApi(model: Model): {
1515
data: {
16-
id?: string;
16+
id?: string | undefined;
1717
type: string;
1818
attributes: Record<string, any>;
1919
relationships?: Record<string, {
2020
data: {
2121
type: string;
2222
id: string;
2323
};
24-
}>;
24+
}> | undefined;
2525
};
2626
};
2727
get(): Promise<InternalResponse<T[]>>;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Client } from "Client";
2+
import { BaseService } from "./BaseService";
3+
import { EquipmentExposure } from "@models/EquipmentExposure";
4+
export declare class EquipmentExposureService extends BaseService<EquipmentExposure> {
5+
constructor(client: Client);
6+
}

0 commit comments

Comments
 (0)