@@ -617,16 +617,22 @@ class Property extends BaseModel {
617
617
pressure_tests = { source : "" , id : "" } ;
618
618
mprn = 0 ;
619
619
mpan = 0 ;
620
- static relationships = [ ] ;
620
+ static relationships = [
621
+ {
622
+ name : "pressure_tests" ,
623
+ type : "array" ,
624
+ modelType : "pressure-tests"
625
+ }
626
+ ] ;
621
627
constructor ( data ) {
622
628
super ( data ) ;
623
- this . uprn = data ?. attributes ?. uprn ?? data . uprn ?? 0 ;
624
- this . location = data ?. attributes ?. location ?? data . location ?? { type : "" , coordinates : [ ] } ;
625
- this . address = data ?. attributes ?. address ?? data . address ?? { description : "" , department : "" , organisation : "" , number : "" , name : "" , thoroughfare : "" , dependent_thoroughfare : "" , post_town : "" , postcode : "" , pobox : "" , country : "" } ;
626
- this . psr = data ?. attributes ?. psr ?? data . psr ?? { indicator : false , priority : 0 , notes : "" , contact : "" } ;
627
- this . pressure_tests = data ?. attributes ?. pressure_tests ?? data . pressure_tests ?? { source : "" , id : "" } ;
628
- this . mprn = data ?. attributes ?. mprn ?? data . mprn ?? 0 ;
629
- this . mpan = data ?. attributes ?. mpan ?? data . mpan ?? 0 ;
629
+ this . uprn = data ?. attributes ?. uprn ?? data ? .uprn ?? 0 ;
630
+ this . location = data ?. attributes ?. location ?? data ? .location ?? { type : "" , coordinates : [ ] } ;
631
+ this . address = data ?. attributes ?. address ?? data ? .address ?? { description : "" , department : "" , organisation : "" , number : "" , name : "" , thoroughfare : "" , dependent_thoroughfare : "" , post_town : "" , postcode : "" , pobox : "" , country : "" } ;
632
+ this . psr = data ?. attributes ?. psr ?? data ? .psr ?? { indicator : false , priority : 0 , notes : "" , contact : "" } ;
633
+ this . pressure_tests = data ?. attributes ?. pressure_tests ?? data ? .pressure_tests ?? { source : "" , id : "" } ;
634
+ this . mprn = data ?. attributes ?. mprn ?? data ? .mprn ?? 0 ;
635
+ this . mpan = data ?. attributes ?. mpan ?? data ? .mpan ?? 0 ;
630
636
}
631
637
}
632
638
@@ -853,22 +859,25 @@ class FormVersion extends BaseModel {
853
859
}
854
860
}
855
861
856
- // src/models/Customer.ts
857
- class Customer extends BaseModel {
858
- type = "customers" ;
859
- name = "" ;
862
+ // src/models/Contact.ts
863
+ class Contact extends BaseModel {
864
+ type = "contacts" ;
865
+ salutation = "" ;
866
+ first_name = "" ;
867
+ last_name = "" ;
860
868
telephone = "" ;
861
869
email = "" ;
862
- property = "" ;
863
870
jsonApiMapping ( ) {
864
871
return {
865
- attributes : [ "name" , "telephone" , "email" , "property" ] ,
866
- relationships : {
867
- model : "customer-interactions"
868
- }
872
+ attributes : [ "salutation" , "first_name" , "last_name" , "telephone" , "email" ]
869
873
} ;
870
874
}
871
875
static relationships = [
876
+ {
877
+ name : "customer_accounts" ,
878
+ type : "array" ,
879
+ modelType : "customer-accounts"
880
+ } ,
872
881
{
873
882
name : "representative" ,
874
883
type : "array" ,
@@ -882,10 +891,36 @@ class Customer extends BaseModel {
882
891
] ;
883
892
constructor ( data ) {
884
893
super ( data ) ;
885
- this . name = data ?. attributes ?. name ?? data ?. name ?? "" ;
894
+ this . salutation = data ?. attributes ?. salutation ?? data ?. salutation ?? "" ;
895
+ this . first_name = data ?. attributes ?. first_name ?? data ?. first_name ?? "" ;
896
+ this . last_name = data ?. attributes ?. last_name ?? data ?. last_name ?? "" ;
886
897
this . telephone = data ?. attributes ?. telephone ?? data ?. telephone ?? "" ;
887
898
this . email = data ?. attributes ?. email ?? data ?. email ?? "" ;
888
- this . property = data ?. attributes ?. property ?? data ?. property ?? "" ;
899
+ }
900
+ }
901
+
902
+ // src/models/CustomerAccount.ts
903
+ class CustomerAccount extends BaseModel {
904
+ type = "customer-accounts" ;
905
+ static relationships = [
906
+ {
907
+ name : "properties" ,
908
+ type : "array" ,
909
+ modelType : "properties"
910
+ } ,
911
+ {
912
+ name : "contacts" ,
913
+ type : "array" ,
914
+ modelType : "contacts"
915
+ } ,
916
+ {
917
+ name : "interactions" ,
918
+ type : "array" ,
919
+ modelType : "customer-interactions"
920
+ }
921
+ ] ;
922
+ constructor ( data ) {
923
+ super ( data ) ;
889
924
}
890
925
}
891
926
@@ -899,11 +934,17 @@ class CustomerInteraction extends BaseModel {
899
934
status = "" ;
900
935
notes = "" ;
901
936
representative ;
937
+ property ;
938
+ contact ;
939
+ customer_account ;
902
940
jsonApiMapping ( ) {
903
941
return {
904
942
attributes : [ "method" , "direction" , "date_time" , "contacted" , "status" , "notes" ] ,
905
943
relationships : {
906
- representative : "users"
944
+ representative : "users" ,
945
+ property : "properties" ,
946
+ contact : "contacts" ,
947
+ customer_account : "customer-accounts"
907
948
}
908
949
} ;
909
950
}
@@ -912,6 +953,21 @@ class CustomerInteraction extends BaseModel {
912
953
name : "representative" ,
913
954
type : "single" ,
914
955
modelType : "users"
956
+ } ,
957
+ {
958
+ name : "property" ,
959
+ type : "single" ,
960
+ modelType : "properties"
961
+ } ,
962
+ {
963
+ name : "contact" ,
964
+ type : "single" ,
965
+ modelType : "contacts"
966
+ } ,
967
+ {
968
+ name : "customer_account" ,
969
+ type : "single" ,
970
+ modelType : "customer-accounts"
915
971
}
916
972
] ;
917
973
constructor ( data ) {
@@ -1032,10 +1088,24 @@ class OperationTemplate extends BaseModel {
1032
1088
}
1033
1089
}
1034
1090
1091
+ // src/models/Street.ts
1092
+ class Street extends BaseModel {
1093
+ type = "streets" ;
1094
+ usrn = 0 ;
1095
+ location = { type : "" , coordinates : [ ] } ;
1096
+ static relationships = [ ] ;
1097
+ constructor ( data ) {
1098
+ super ( data ) ;
1099
+ this . usrn = data ?. attributes ?. usrn ?? data . usrn ?? 0 ;
1100
+ this . location = data ?. attributes ?. location ?? data . location ?? { type : "" , coordinates : [ ] } ;
1101
+ }
1102
+ }
1103
+
1035
1104
// src/utils/Hydrator.ts
1036
1105
class Hydrator {
1037
1106
modelMap = {
1038
- customers : Customer ,
1107
+ contacts : Contact ,
1108
+ "customer-accounts" : CustomerAccount ,
1039
1109
"customer-interactions" : CustomerInteraction ,
1040
1110
"equipment-categories" : EquipmentCategory ,
1041
1111
"equipment-items" : Equipment ,
@@ -1054,6 +1124,7 @@ class Hydrator {
1054
1124
schemes : Scheme ,
1055
1125
"service-accounts" : ServiceAccount ,
1056
1126
"service-account-keys" : ServiceAccountKey ,
1127
+ streets : Street ,
1057
1128
submissions : Submission ,
1058
1129
teams : Team ,
1059
1130
users : User ,
@@ -1214,7 +1285,7 @@ class JsonApiSerializer {
1214
1285
payload . data . relationships [ key ] = {
1215
1286
data : {
1216
1287
type : relationshipType ,
1217
- id : relationshipValue
1288
+ id : relationshipValue . id ?? relationshipValue
1218
1289
}
1219
1290
} ;
1220
1291
}
@@ -1266,6 +1337,21 @@ class JsonApiSerializer {
1266
1337
}
1267
1338
return this . buildDefaultPayload ( model ) ;
1268
1339
}
1340
+ buildRelationshipPayload ( model , relationships ) {
1341
+ const ModelClass = this . modelMap [ model . type ] ;
1342
+ if ( ! ModelClass ) {
1343
+ console . warn ( `No model class found for type: ${ model . type } ` ) ;
1344
+ return { data : [ ] } ;
1345
+ }
1346
+ const data = relationships . filter ( ( relationship ) => relationship . id !== undefined ) . map ( ( relationship ) => ( {
1347
+ type : model . type ,
1348
+ id : relationship . id
1349
+ } ) ) ;
1350
+ const payload = {
1351
+ data
1352
+ } ;
1353
+ return payload ;
1354
+ }
1269
1355
buildDefaultPayload ( model ) {
1270
1356
const { type, id, meta, links, included, _relationships, ...attributes } = model ;
1271
1357
return {
@@ -1601,17 +1687,35 @@ class VehicleModelSpecificationService extends BaseService {
1601
1687
}
1602
1688
}
1603
1689
1604
- // src/services/CustomersService .ts
1605
- class CustomersService extends BaseService {
1690
+ // src/services/ContactsService .ts
1691
+ class ContactsService extends BaseService {
1606
1692
constructor ( client ) {
1607
- super ( client , "/v3/orgs/:orgId/customers" ) ;
1693
+ super ( client , "/v3/orgs/:orgId/contacts" ) ;
1694
+ }
1695
+ }
1696
+
1697
+ // src/services/CustomerAccountsService.ts
1698
+ class CustomerAccountsService extends BaseService {
1699
+ constructor ( client , customerAccountId ) {
1700
+ const endpoint = customerAccountId ? `/v3/orgs/:orgId/customer-accounts/${ customerAccountId } ` : `/v3/orgs/:orgId/customer-accounts` ;
1701
+ super ( client , endpoint ) ;
1702
+ }
1703
+ async patchProperties ( properties ) {
1704
+ const jsonApiSerializer = new JsonApiSerializer ( this . hydrator . getModelMap ( ) ) ;
1705
+ const payload = jsonApiSerializer . buildRelationshipPayload ( new Property , properties ) ;
1706
+ return await this . client . makePatchRequest ( `${ this . endpoint } /relationships/properties` , payload ) ;
1707
+ }
1708
+ async patchContacts ( contacts ) {
1709
+ const jsonApiSerializer = new JsonApiSerializer ( this . hydrator . getModelMap ( ) ) ;
1710
+ const payload = jsonApiSerializer . buildRelationshipPayload ( new Contact , contacts ) ;
1711
+ return await this . client . makePatchRequest ( `${ this . endpoint } /relationships/contacts` , payload ) ;
1608
1712
}
1609
1713
}
1610
1714
1611
1715
// src/services/CustomerInteractionsService.ts
1612
1716
class CustomerInteractionsService extends BaseService {
1613
- constructor ( client , customerId ) {
1614
- super ( client , ` /v3/orgs/:orgId/customers/ ${ customerId } / interactions` ) ;
1717
+ constructor ( client ) {
1718
+ super ( client , " /v3/orgs/:orgId/customer- interactions" ) ;
1615
1719
}
1616
1720
}
1617
1721
@@ -1720,11 +1824,14 @@ class Client {
1720
1824
serviceAccountKeys ( ) {
1721
1825
return new ServiceAccountKeysService ( this ) ;
1722
1826
}
1723
- customers ( ) {
1724
- return new CustomersService ( this ) ;
1827
+ customerAccounts ( customerAccountId ) {
1828
+ return new CustomerAccountsService ( this , customerAccountId ) ;
1725
1829
}
1726
- customerInteractions ( customerId ) {
1727
- return new CustomerInteractionsService ( this , customerId ) ;
1830
+ contacts ( ) {
1831
+ return new ContactsService ( this ) ;
1832
+ }
1833
+ customerInteractions ( ) {
1834
+ return new CustomerInteractionsService ( this ) ;
1728
1835
}
1729
1836
serviceAccounts ( ) {
1730
1837
return new ServiceAccountsService ( this ) ;
@@ -1916,6 +2023,11 @@ class Operation extends BaseModel {
1916
2023
name : "properties" ,
1917
2024
type : "array" ,
1918
2025
modelType : "properties"
2026
+ } ,
2027
+ {
2028
+ name : "streets" ,
2029
+ type : "array" ,
2030
+ modelType : "streets"
1919
2031
}
1920
2032
] ;
1921
2033
constructor ( data ) {
@@ -1953,6 +2065,7 @@ export {
1953
2065
Scheme ,
1954
2066
Role ,
1955
2067
RequestOptions ,
2068
+ Property ,
1956
2069
Permission ,
1957
2070
Operation ,
1958
2071
Log ,
@@ -1965,7 +2078,8 @@ export {
1965
2078
EquipmentCategory ,
1966
2079
Equipment ,
1967
2080
CustomerInteraction ,
1968
- Customer ,
2081
+ CustomerAccount ,
2082
+ Contact ,
1969
2083
ClientConfig ,
1970
2084
Client
1971
2085
} ;
0 commit comments