@@ -205,7 +205,7 @@ class EquipmentCategory extends BaseModel {
205
205
name = "" ;
206
206
constructor ( data ) {
207
207
super ( data ) ;
208
- this . name = data ?. attributes ?. name ?? "" ;
208
+ this . name = data ?. attributes ?. name ?? data ?. name ?? "" ;
209
209
}
210
210
jsonApiMapping ( ) {
211
211
return {
@@ -259,13 +259,27 @@ class EquipmentExposure extends BaseModel {
259
259
coordinates : locationData . coordinates ?? [ ]
260
260
} ;
261
261
}
262
+ if ( data ?. location ) {
263
+ const locationData = data . location ;
264
+ this . location = {
265
+ type : locationData . type ?? "" ,
266
+ coordinates : locationData . coordinates ?? [ ]
267
+ } ;
268
+ }
262
269
if ( data ?. attributes ?. ppe ) {
263
- const ppeData = data . attributes . ppe ;
270
+ const ppeData = data . attributes ? .ppe ;
264
271
this . ppe = {
265
272
mask : ppeData . ppe ?. mask ?? false ,
266
273
ear_defenders : ppeData . ppe ?. ear_defenders ?? false
267
274
} ;
268
275
}
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
+ }
269
283
}
270
284
}
271
285
@@ -598,7 +612,7 @@ class EquipmentManufacturer extends BaseModel {
598
612
static relationships = [ ] ;
599
613
constructor ( data ) {
600
614
super ( data ) ;
601
- this . name = data ?. attributes ?. name ?? "" ;
615
+ this . name = data ?. attributes ?. name ?? data ?. name ?? "" ;
602
616
}
603
617
jsonApiMapping ( ) {
604
618
return {
@@ -922,6 +936,11 @@ class CustomerAccount extends BaseModel {
922
936
constructor ( data ) {
923
937
super ( data ) ;
924
938
}
939
+ jsonApiMapping ( ) {
940
+ return {
941
+ relationships : [ "contacts" , "properties" ]
942
+ } ;
943
+ }
925
944
}
926
945
927
946
// src/models/CustomerInteraction.ts
@@ -1070,6 +1089,53 @@ class WorkOrder extends BaseModel {
1070
1089
}
1071
1090
}
1072
1091
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
+
1073
1139
// src/models/OperationTemplate.ts
1074
1140
class OperationTemplate extends BaseModel {
1075
1141
type = "operation-templates" ;
@@ -1255,73 +1321,30 @@ class JsonApiSerializer {
1255
1321
this . modelMap = modelMap ;
1256
1322
}
1257
1323
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 ) ;
1307
1325
}
1308
1326
buildUpdatePayload ( model ) {
1327
+ return this . buildPayload ( model , true ) ;
1328
+ }
1329
+ buildPayload ( model , isUpdate ) {
1309
1330
const ModelClass = this . modelMap [ model . type ] ;
1310
1331
if ( ! ModelClass ) {
1311
1332
console . warn ( `No model class found for type: ${ model . type } ` ) ;
1312
- return this . buildDefaultPayload ( model ) ;
1333
+ return this . buildDefaultPayload ( model , isUpdate ) ;
1313
1334
}
1314
1335
const prototype = ModelClass . prototype ;
1315
1336
if ( typeof prototype . jsonApiMapping === "function" ) {
1316
1337
const mapping = prototype . jsonApiMapping . call ( model ) ;
1317
1338
const payload = {
1318
1339
data : {
1319
- id : model . id ,
1320
1340
type : model . type ,
1321
1341
attributes : { } ,
1322
1342
relationships : { }
1323
1343
}
1324
1344
} ;
1345
+ if ( isUpdate && model . id ) {
1346
+ payload . data . id = model . id ;
1347
+ }
1325
1348
prototype . constructor . relationships . forEach ( ( relationship ) => {
1326
1349
if ( relationship . type === "array" ) {
1327
1350
const value = model [ relationship . name ] ;
@@ -1339,7 +1362,7 @@ class JsonApiSerializer {
1339
1362
payload . data . relationships [ relationship . name ] = {
1340
1363
data : {
1341
1364
type : relationship . modelType ,
1342
- id : value . id
1365
+ id : typeof value === "string" ? value : value . id
1343
1366
}
1344
1367
} ;
1345
1368
}
@@ -1355,7 +1378,7 @@ class JsonApiSerializer {
1355
1378
}
1356
1379
return payload ;
1357
1380
}
1358
- return this . buildDefaultPayload ( model ) ;
1381
+ return this . buildDefaultPayload ( model , isUpdate ) ;
1359
1382
}
1360
1383
buildRelationshipPayload ( model , relationships ) {
1361
1384
const ModelClass = this . modelMap [ model . type ] ;
@@ -1367,19 +1390,20 @@ class JsonApiSerializer {
1367
1390
type : model . type ,
1368
1391
id : relationship . id
1369
1392
} ) ) ;
1370
- const payload = {
1371
- data
1372
- } ;
1373
- return payload ;
1393
+ return { data } ;
1374
1394
}
1375
- buildDefaultPayload ( model ) {
1395
+ buildDefaultPayload ( model , includeId ) {
1376
1396
const { type, id, meta, links, included, _relationships, ...attributes } = model ;
1377
- return {
1397
+ const payload = {
1378
1398
data : {
1379
1399
type : model . type ,
1380
1400
attributes
1381
1401
}
1382
1402
} ;
1403
+ if ( includeId && id ) {
1404
+ payload . data . id = id ;
1405
+ }
1406
+ return payload ;
1383
1407
}
1384
1408
}
1385
1409
@@ -1788,6 +1812,13 @@ class VehicleInventoryCheckService extends BaseService {
1788
1812
}
1789
1813
}
1790
1814
1815
+ // src/services/AppointmentsService.ts
1816
+ class AppointmentsService extends BaseService {
1817
+ constructor ( client ) {
1818
+ super ( client , "/v3/orgs/:orgId/appointments" ) ;
1819
+ }
1820
+ }
1821
+
1791
1822
// src/Client.ts
1792
1823
class Client {
1793
1824
config ;
@@ -1862,6 +1893,9 @@ class Client {
1862
1893
forms ( ) {
1863
1894
return new FormsService ( this ) ;
1864
1895
}
1896
+ appointments ( ) {
1897
+ return new AppointmentsService ( this ) ;
1898
+ }
1865
1899
teams ( ) {
1866
1900
return new TeamsService ( this ) ;
1867
1901
}
@@ -2024,52 +2058,6 @@ class ClientConfig {
2024
2058
this . authDomain = config . authDomain || "https://auth.ctrl-hub.com" ;
2025
2059
}
2026
2060
}
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
- }
2073
2061
export {
2074
2062
WorkOrder ,
2075
2063
VehicleSpecification ,
0 commit comments