Skip to content

Commit e301e34

Browse files
committed
Run build
1 parent f431889 commit e301e34

11 files changed

+146
-172
lines changed

dist/Client.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { OperationsService } from '@services/OperationsService';
3030
import { OperationTemplatesService } from '@services/OperationTemplatesService';
3131
import { VehicleInspectionService } from '@services/VehicleInspectionService';
3232
import { VehicleInventoryCheckService } from '@services/VehicleInventoryCheckService';
33+
import { AppointmentsService } from '@services/AppointmentsService';
3334
export declare class Client {
3435
readonly config: ClientConfigInterface;
3536
organisation: string;
@@ -51,6 +52,7 @@ export declare class Client {
5152
serviceAccounts(): ServiceAccountsService;
5253
formCategories(): FormCategoriesService;
5354
forms(): FormsService;
55+
appointments(): AppointmentsService;
5456
teams(): TeamsService;
5557
submissions(): SubmissionsService;
5658
permissions(): PermissionsService;

dist/Client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { OperationsService } from '@services/OperationsService';
2929
import { OperationTemplatesService } from '@services/OperationTemplatesService';
3030
import { VehicleInspectionService } from '@services/VehicleInspectionService';
3131
import { VehicleInventoryCheckService } from '@services/VehicleInventoryCheckService';
32+
import { AppointmentsService } from '@services/AppointmentsService';
3233
export class Client {
3334
config;
3435
organisation;
@@ -102,6 +103,9 @@ export class Client {
102103
forms() {
103104
return new FormsService(this);
104105
}
106+
appointments() {
107+
return new AppointmentsService(this);
108+
}
105109
teams() {
106110
return new TeamsService(this);
107111
}

dist/index.js

Lines changed: 96 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class EquipmentCategory extends BaseModel {
205205
name = "";
206206
constructor(data) {
207207
super(data);
208-
this.name = data?.attributes?.name ?? "";
208+
this.name = data?.attributes?.name ?? data?.name ?? "";
209209
}
210210
jsonApiMapping() {
211211
return {
@@ -259,13 +259,27 @@ class EquipmentExposure extends BaseModel {
259259
coordinates: locationData.coordinates ?? []
260260
};
261261
}
262+
if (data?.location) {
263+
const locationData = data.location;
264+
this.location = {
265+
type: locationData.type ?? "",
266+
coordinates: locationData.coordinates ?? []
267+
};
268+
}
262269
if (data?.attributes?.ppe) {
263-
const ppeData = data.attributes.ppe;
270+
const ppeData = data.attributes?.ppe;
264271
this.ppe = {
265272
mask: ppeData.ppe?.mask ?? false,
266273
ear_defenders: ppeData.ppe?.ear_defenders ?? false
267274
};
268275
}
276+
if (data?.ppe) {
277+
const ppeData = data.ppe;
278+
this.ppe = {
279+
mask: ppeData.mask ?? false,
280+
ear_defenders: ppeData.ear_defenders ?? false
281+
};
282+
}
269283
}
270284
}
271285

@@ -598,7 +612,7 @@ class EquipmentManufacturer extends BaseModel {
598612
static relationships = [];
599613
constructor(data) {
600614
super(data);
601-
this.name = data?.attributes?.name ?? "";
615+
this.name = data?.attributes?.name ?? data?.name ?? "";
602616
}
603617
jsonApiMapping() {
604618
return {
@@ -922,6 +936,11 @@ class CustomerAccount extends BaseModel {
922936
constructor(data) {
923937
super(data);
924938
}
939+
jsonApiMapping() {
940+
return {
941+
relationships: ["contacts", "properties"]
942+
};
943+
}
925944
}
926945

927946
// src/models/CustomerInteraction.ts
@@ -1070,6 +1089,53 @@ class WorkOrder extends BaseModel {
10701089
}
10711090
}
10721091

1092+
// src/models/Operation.ts
1093+
class Operation extends BaseModel {
1094+
type = "operations";
1095+
name = "";
1096+
code = "";
1097+
description = "";
1098+
start_date = "";
1099+
end_date = "";
1100+
labels = [];
1101+
uprns = [];
1102+
usrns = [];
1103+
completed = false;
1104+
aborted = false;
1105+
cancelled = false;
1106+
static relationships = [
1107+
{
1108+
name: "properties",
1109+
type: "array",
1110+
modelType: "properties"
1111+
},
1112+
{
1113+
name: "streets",
1114+
type: "array",
1115+
modelType: "streets"
1116+
}
1117+
];
1118+
constructor(data) {
1119+
super(data);
1120+
this.name = data?.attributes?.name ?? data?.name ?? "";
1121+
this.code = data?.attributes?.code ?? data?.code ?? "";
1122+
this.description = data?.attributes?.description ?? data?.description ?? "";
1123+
this.start_date = data?.attributes?.start_date ?? data?.start_date ?? "";
1124+
this.end_date = data?.attributes?.end_date ?? data?.end_date ?? "";
1125+
this.labels = data?.attributes?.labels ?? data?.labels ?? [];
1126+
this.uprns = data?.attributes?.uprns ?? data?.uprns ?? [];
1127+
this.usrns = data?.attributes?.usrns ?? data?.usrns ?? [];
1128+
this.completed = data?.attributes?.completed ?? data?.completed ?? false;
1129+
this.aborted = data?.attributes?.aborted ?? data?.aborted ?? false;
1130+
this.cancelled = data?.attributes?.cancelled ?? data?.cancelled ?? false;
1131+
}
1132+
jsonApiMapping() {
1133+
return {
1134+
attributes: ["name", "code", "description", "start_date", "end_date", "labels", "uprns", "usrns", "completed", "aborted", "cancelled"]
1135+
};
1136+
}
1137+
}
1138+
10731139
// src/models/OperationTemplate.ts
10741140
class OperationTemplate extends BaseModel {
10751141
type = "operation-templates";
@@ -1255,73 +1321,30 @@ class JsonApiSerializer {
12551321
this.modelMap = modelMap;
12561322
}
12571323
buildCreatePayload(model) {
1258-
const ModelClass = this.modelMap[model.type];
1259-
if (!ModelClass) {
1260-
console.warn(`No model class found for type: ${model.type}`);
1261-
return this.buildDefaultPayload(model);
1262-
}
1263-
const prototype = ModelClass.prototype;
1264-
if (typeof prototype.jsonApiMapping === "function") {
1265-
const mapping = prototype.jsonApiMapping.call(model);
1266-
const payload = {
1267-
data: {
1268-
type: model.type,
1269-
attributes: {},
1270-
relationships: {}
1271-
}
1272-
};
1273-
prototype.constructor.relationships.forEach((relationship) => {
1274-
if (relationship.type === "array") {
1275-
const value = model[relationship.name];
1276-
if (value) {
1277-
payload.data.relationships[relationship.name] = {
1278-
data: value.map((item) => ({
1279-
type: relationship.modelType,
1280-
id: item.id
1281-
}))
1282-
};
1283-
}
1284-
} else {
1285-
const value = model[relationship.name];
1286-
if (value) {
1287-
payload.data.relationships[relationship.name] = {
1288-
data: {
1289-
type: relationship.modelType,
1290-
id: value.id
1291-
}
1292-
};
1293-
}
1294-
}
1295-
});
1296-
if (mapping.attributes) {
1297-
mapping.attributes.forEach((attr) => {
1298-
const value = model[attr];
1299-
if (value !== undefined && value !== "") {
1300-
payload.data.attributes[attr] = value;
1301-
}
1302-
});
1303-
}
1304-
return payload;
1305-
}
1306-
return this.buildDefaultPayload(model);
1324+
return this.buildPayload(model, false);
13071325
}
13081326
buildUpdatePayload(model) {
1327+
return this.buildPayload(model, true);
1328+
}
1329+
buildPayload(model, isUpdate) {
13091330
const ModelClass = this.modelMap[model.type];
13101331
if (!ModelClass) {
13111332
console.warn(`No model class found for type: ${model.type}`);
1312-
return this.buildDefaultPayload(model);
1333+
return this.buildDefaultPayload(model, isUpdate);
13131334
}
13141335
const prototype = ModelClass.prototype;
13151336
if (typeof prototype.jsonApiMapping === "function") {
13161337
const mapping = prototype.jsonApiMapping.call(model);
13171338
const payload = {
13181339
data: {
1319-
id: model.id,
13201340
type: model.type,
13211341
attributes: {},
13221342
relationships: {}
13231343
}
13241344
};
1345+
if (isUpdate && model.id) {
1346+
payload.data.id = model.id;
1347+
}
13251348
prototype.constructor.relationships.forEach((relationship) => {
13261349
if (relationship.type === "array") {
13271350
const value = model[relationship.name];
@@ -1339,7 +1362,7 @@ class JsonApiSerializer {
13391362
payload.data.relationships[relationship.name] = {
13401363
data: {
13411364
type: relationship.modelType,
1342-
id: value.id
1365+
id: typeof value === "string" ? value : value.id
13431366
}
13441367
};
13451368
}
@@ -1355,7 +1378,7 @@ class JsonApiSerializer {
13551378
}
13561379
return payload;
13571380
}
1358-
return this.buildDefaultPayload(model);
1381+
return this.buildDefaultPayload(model, isUpdate);
13591382
}
13601383
buildRelationshipPayload(model, relationships) {
13611384
const ModelClass = this.modelMap[model.type];
@@ -1367,19 +1390,20 @@ class JsonApiSerializer {
13671390
type: model.type,
13681391
id: relationship.id
13691392
}));
1370-
const payload = {
1371-
data
1372-
};
1373-
return payload;
1393+
return { data };
13741394
}
1375-
buildDefaultPayload(model) {
1395+
buildDefaultPayload(model, includeId) {
13761396
const { type, id, meta, links, included, _relationships, ...attributes } = model;
1377-
return {
1397+
const payload = {
13781398
data: {
13791399
type: model.type,
13801400
attributes
13811401
}
13821402
};
1403+
if (includeId && id) {
1404+
payload.data.id = id;
1405+
}
1406+
return payload;
13831407
}
13841408
}
13851409

@@ -1788,6 +1812,13 @@ class VehicleInventoryCheckService extends BaseService {
17881812
}
17891813
}
17901814

1815+
// src/services/AppointmentsService.ts
1816+
class AppointmentsService extends BaseService {
1817+
constructor(client) {
1818+
super(client, "/v3/orgs/:orgId/appointments");
1819+
}
1820+
}
1821+
17911822
// src/Client.ts
17921823
class Client {
17931824
config;
@@ -1862,6 +1893,9 @@ class Client {
18621893
forms() {
18631894
return new FormsService(this);
18641895
}
1896+
appointments() {
1897+
return new AppointmentsService(this);
1898+
}
18651899
teams() {
18661900
return new TeamsService(this);
18671901
}
@@ -2024,52 +2058,6 @@ class ClientConfig {
20242058
this.authDomain = config.authDomain || "https://auth.ctrl-hub.com";
20252059
}
20262060
}
2027-
// src/models/Operation.ts
2028-
class Operation extends BaseModel {
2029-
type = "operations";
2030-
name = "";
2031-
code = "";
2032-
description = "";
2033-
start_date = "";
2034-
end_date = "";
2035-
labels = [];
2036-
uprns = [];
2037-
usrns = [];
2038-
completed = false;
2039-
aborted = false;
2040-
cancelled = false;
2041-
static relationships = [
2042-
{
2043-
name: "properties",
2044-
type: "array",
2045-
modelType: "properties"
2046-
},
2047-
{
2048-
name: "streets",
2049-
type: "array",
2050-
modelType: "streets"
2051-
}
2052-
];
2053-
constructor(data) {
2054-
super(data);
2055-
this.name = data?.attributes?.name ?? data?.name ?? "";
2056-
this.code = data?.attributes?.code ?? data?.code ?? "";
2057-
this.description = data?.attributes?.description ?? data?.description ?? "";
2058-
this.start_date = data?.attributes?.start_date ?? data?.start_date ?? "";
2059-
this.end_date = data?.attributes?.end_date ?? data?.end_date ?? "";
2060-
this.labels = data?.attributes?.labels ?? data?.labels ?? [];
2061-
this.uprns = data?.attributes?.uprns ?? data?.uprns ?? [];
2062-
this.usrns = data?.attributes?.usrns ?? data?.usrns ?? [];
2063-
this.completed = data?.attributes?.completed ?? data?.completed ?? false;
2064-
this.aborted = data?.attributes?.aborted ?? data?.aborted ?? false;
2065-
this.cancelled = data?.attributes?.cancelled ?? data?.cancelled ?? false;
2066-
}
2067-
jsonApiMapping() {
2068-
return {
2069-
attributes: ["name", "code", "description", "start_date", "end_date", "labels", "uprns", "usrns", "completed", "aborted", "cancelled"]
2070-
};
2071-
}
2072-
}
20732061
export {
20742062
WorkOrder,
20752063
VehicleSpecification,

dist/models/CustomerAccount.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export declare class CustomerAccount extends BaseModel {
44
type: string;
55
static relationships: RelationshipDefinition[];
66
constructor(data?: any);
7+
jsonApiMapping(): {
8+
relationships: string[];
9+
};
710
}

dist/models/CustomerAccount.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ export class CustomerAccount extends BaseModel {
2121
constructor(data) {
2222
super(data);
2323
}
24+
jsonApiMapping() {
25+
return {
26+
relationships: ['contacts', 'properties'],
27+
};
28+
}
2429
}

dist/models/EquipmentCategory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class EquipmentCategory extends BaseModel {
44
name = '';
55
constructor(data) {
66
super(data);
7-
this.name = data?.attributes?.name ?? '';
7+
this.name = data?.attributes?.name ?? data?.name ?? '';
88
}
99
jsonApiMapping() {
1010
return {

0 commit comments

Comments
 (0)