@defra/fcp-sfd-frontend-engine 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +167 -2
- package/dist/index.js +167 -2
- package/package.json +1 -1
- package/src/mutations/mutations.js +3 -1
- package/src/mutations/personal/update-customer-details.js +40 -0
- package/src/services/build-fix-success-message-service.js +95 -0
- package/src/services/personal/build-customer-fix-update-variables-service.js +76 -0
- package/src/services/services.js +5 -1
package/dist/index.cjs
CHANGED
|
@@ -923,6 +923,48 @@ var updateBusinessAddressMutation = `
|
|
|
923
923
|
}
|
|
924
924
|
`;
|
|
925
925
|
|
|
926
|
+
// src/mutations/personal/update-customer-details.js
|
|
927
|
+
var updateCustomerDetailsMutation = `
|
|
928
|
+
mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
|
|
929
|
+
updateCustomerAllFields(input: $input) {
|
|
930
|
+
success
|
|
931
|
+
customer {
|
|
932
|
+
info {
|
|
933
|
+
name {
|
|
934
|
+
first
|
|
935
|
+
middle
|
|
936
|
+
last
|
|
937
|
+
}
|
|
938
|
+
dateOfBirth
|
|
939
|
+
phone {
|
|
940
|
+
mobile
|
|
941
|
+
landline
|
|
942
|
+
}
|
|
943
|
+
email {
|
|
944
|
+
address
|
|
945
|
+
}
|
|
946
|
+
address {
|
|
947
|
+
line1
|
|
948
|
+
line2
|
|
949
|
+
line3
|
|
950
|
+
line4
|
|
951
|
+
line5
|
|
952
|
+
buildingNumberRange
|
|
953
|
+
buildingName
|
|
954
|
+
flatName
|
|
955
|
+
street
|
|
956
|
+
city
|
|
957
|
+
county
|
|
958
|
+
postalCode
|
|
959
|
+
country
|
|
960
|
+
uprn
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
`;
|
|
967
|
+
|
|
926
968
|
// src/mutations/mutations.js
|
|
927
969
|
var mutations = {
|
|
928
970
|
updateBusinessEmail: updateBusinessEmailMutation,
|
|
@@ -933,7 +975,8 @@ var mutations = {
|
|
|
933
975
|
updateCustomerDob: updateCustomerDobMutation,
|
|
934
976
|
updateCustomerPhone: updateCustomerPhoneMutation,
|
|
935
977
|
updateCustomerEmail: updateCustomerEmailMutation,
|
|
936
|
-
updateCustomerAddress: updateCustomerAddressMutation
|
|
978
|
+
updateCustomerAddress: updateCustomerAddressMutation,
|
|
979
|
+
updateCustomerDetails: updateCustomerDetailsMutation
|
|
937
980
|
};
|
|
938
981
|
|
|
939
982
|
// src/presenters/base-presenter.js
|
|
@@ -1639,6 +1682,126 @@ var setFixSessionDataService = (yar, sessionData, payload, journeyKey, updateKey
|
|
|
1639
1682
|
yar.set(journeyKey, sessionData);
|
|
1640
1683
|
};
|
|
1641
1684
|
|
|
1685
|
+
// src/services/build-fix-success-message-service.js
|
|
1686
|
+
var LABEL_MAPS = {
|
|
1687
|
+
personal: {
|
|
1688
|
+
name: "full name",
|
|
1689
|
+
email: "personal email address",
|
|
1690
|
+
phone: "personal phone numbers",
|
|
1691
|
+
dob: "date of birth",
|
|
1692
|
+
address: "personal address"
|
|
1693
|
+
},
|
|
1694
|
+
business: {
|
|
1695
|
+
name: "business name",
|
|
1696
|
+
email: "business email address",
|
|
1697
|
+
phone: "business phone numbers",
|
|
1698
|
+
vat: "business vat number",
|
|
1699
|
+
address: "business address"
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var PROPERTY_MAPS = {
|
|
1703
|
+
personal: {
|
|
1704
|
+
name: "changePersonalName",
|
|
1705
|
+
email: "changePersonalEmail",
|
|
1706
|
+
phone: "changePersonalPhoneNumbers",
|
|
1707
|
+
dob: "changePersonalDob",
|
|
1708
|
+
address: "changePersonalAddress"
|
|
1709
|
+
},
|
|
1710
|
+
business: {
|
|
1711
|
+
name: "changeBusinessName",
|
|
1712
|
+
email: "changeBusinessEmail",
|
|
1713
|
+
phone: "changeBusinessPhoneNumbers",
|
|
1714
|
+
vat: "changeBusinessVat",
|
|
1715
|
+
address: "changeBusinessAddress"
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
var buildFixSuccessMessageService = (type, details) => {
|
|
1719
|
+
const { orderedSectionsToFix } = details;
|
|
1720
|
+
const changes = loopThroughSections(type, details, orderedSectionsToFix);
|
|
1721
|
+
if (changes.length === 0) {
|
|
1722
|
+
return null;
|
|
1723
|
+
}
|
|
1724
|
+
if (changes.length === 1) {
|
|
1725
|
+
return {
|
|
1726
|
+
type: "text",
|
|
1727
|
+
value: `You have updated your ${changes[0]}`
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
return {
|
|
1731
|
+
type: "html",
|
|
1732
|
+
value: `
|
|
1733
|
+
<h3 class="govuk-notification-banner__heading">
|
|
1734
|
+
You have updated your:
|
|
1735
|
+
</h3>
|
|
1736
|
+
<ul class="govuk-list govuk-list--bullet">
|
|
1737
|
+
${changes.map((change) => `<li>${change}</li>`).join("")}
|
|
1738
|
+
</ul>
|
|
1739
|
+
`
|
|
1740
|
+
};
|
|
1741
|
+
};
|
|
1742
|
+
var loopThroughSections = (type, details, orderedSectionsToFix) => {
|
|
1743
|
+
const changes = [];
|
|
1744
|
+
const labelMap = LABEL_MAPS[type];
|
|
1745
|
+
const propertyMap = PROPERTY_MAPS[type];
|
|
1746
|
+
for (const section of orderedSectionsToFix) {
|
|
1747
|
+
if (details[propertyMap[section]]) {
|
|
1748
|
+
changes.push(labelMap[section]);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
return changes;
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
// src/services/personal/build-customer-fix-update-variables-service.js
|
|
1755
|
+
var buildCustomerFixUpdateVariablesService = (personalDetails) => {
|
|
1756
|
+
const { orderedSectionsToFix, crn } = personalDetails;
|
|
1757
|
+
const input = { crn };
|
|
1758
|
+
if (orderedSectionsToFix.includes("name") && personalDetails.changePersonalName) {
|
|
1759
|
+
Object.assign(input, buildNameInput(personalDetails.changePersonalName));
|
|
1760
|
+
}
|
|
1761
|
+
if (orderedSectionsToFix.includes("email") && personalDetails.changePersonalEmail) {
|
|
1762
|
+
Object.assign(input, buildEmailInput(personalDetails.changePersonalEmail));
|
|
1763
|
+
}
|
|
1764
|
+
if (orderedSectionsToFix.includes("phone") && personalDetails.changePersonalPhoneNumbers) {
|
|
1765
|
+
Object.assign(input, buildPhoneInput(personalDetails.changePersonalPhoneNumbers));
|
|
1766
|
+
}
|
|
1767
|
+
if (orderedSectionsToFix.includes("dob") && personalDetails.changePersonalDob) {
|
|
1768
|
+
Object.assign(input, buildDobInput(personalDetails.changePersonalDob));
|
|
1769
|
+
}
|
|
1770
|
+
if (orderedSectionsToFix.includes("address") && personalDetails.changePersonalAddress) {
|
|
1771
|
+
Object.assign(input, { address: buildManualAddress(personalDetails.changePersonalAddress) });
|
|
1772
|
+
}
|
|
1773
|
+
return { input };
|
|
1774
|
+
};
|
|
1775
|
+
var buildPhoneInput = (change) => {
|
|
1776
|
+
return {
|
|
1777
|
+
phone: {
|
|
1778
|
+
landline: change.personalTelephone ?? null,
|
|
1779
|
+
mobile: change.personalMobile ?? null
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
var buildEmailInput = (change) => {
|
|
1784
|
+
return {
|
|
1785
|
+
email: {
|
|
1786
|
+
address: change.personalEmail
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
};
|
|
1790
|
+
var buildNameInput = (change) => {
|
|
1791
|
+
return {
|
|
1792
|
+
first: change.first,
|
|
1793
|
+
middle: change.middle ?? null,
|
|
1794
|
+
last: change.last
|
|
1795
|
+
};
|
|
1796
|
+
};
|
|
1797
|
+
var buildDobInput = (change) => {
|
|
1798
|
+
const { day, month, year } = change;
|
|
1799
|
+
return {
|
|
1800
|
+
// DAL expects dateOfBirth as YYYY-MM-DD e.g. '1990-04-05' not '1990-4-5'
|
|
1801
|
+
dateOfBirth: `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
|
|
1802
|
+
};
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1642
1805
|
// src/services/services.js
|
|
1643
1806
|
var services = {
|
|
1644
1807
|
addressLookup: addressLookupService,
|
|
@@ -1647,7 +1810,9 @@ var services = {
|
|
|
1647
1810
|
checkInterrupterJourneySession: checkInterrupterJourneySessionService,
|
|
1648
1811
|
initialiseFixJourney: initialiseFixJourneyService,
|
|
1649
1812
|
validateFixDetails: validateFixDetailsService,
|
|
1650
|
-
setFixSessionData: setFixSessionDataService
|
|
1813
|
+
setFixSessionData: setFixSessionDataService,
|
|
1814
|
+
buildFixSuccessMessage: buildFixSuccessMessageService,
|
|
1815
|
+
buildCustomerFixUpdateVariables: buildCustomerFixUpdateVariablesService
|
|
1651
1816
|
};
|
|
1652
1817
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1653
1818
|
0 && (module.exports = {
|
package/dist/index.js
CHANGED
|
@@ -882,6 +882,48 @@ var updateBusinessAddressMutation = `
|
|
|
882
882
|
}
|
|
883
883
|
`;
|
|
884
884
|
|
|
885
|
+
// src/mutations/personal/update-customer-details.js
|
|
886
|
+
var updateCustomerDetailsMutation = `
|
|
887
|
+
mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
|
|
888
|
+
updateCustomerAllFields(input: $input) {
|
|
889
|
+
success
|
|
890
|
+
customer {
|
|
891
|
+
info {
|
|
892
|
+
name {
|
|
893
|
+
first
|
|
894
|
+
middle
|
|
895
|
+
last
|
|
896
|
+
}
|
|
897
|
+
dateOfBirth
|
|
898
|
+
phone {
|
|
899
|
+
mobile
|
|
900
|
+
landline
|
|
901
|
+
}
|
|
902
|
+
email {
|
|
903
|
+
address
|
|
904
|
+
}
|
|
905
|
+
address {
|
|
906
|
+
line1
|
|
907
|
+
line2
|
|
908
|
+
line3
|
|
909
|
+
line4
|
|
910
|
+
line5
|
|
911
|
+
buildingNumberRange
|
|
912
|
+
buildingName
|
|
913
|
+
flatName
|
|
914
|
+
street
|
|
915
|
+
city
|
|
916
|
+
county
|
|
917
|
+
postalCode
|
|
918
|
+
country
|
|
919
|
+
uprn
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
`;
|
|
926
|
+
|
|
885
927
|
// src/mutations/mutations.js
|
|
886
928
|
var mutations = {
|
|
887
929
|
updateBusinessEmail: updateBusinessEmailMutation,
|
|
@@ -892,7 +934,8 @@ var mutations = {
|
|
|
892
934
|
updateCustomerDob: updateCustomerDobMutation,
|
|
893
935
|
updateCustomerPhone: updateCustomerPhoneMutation,
|
|
894
936
|
updateCustomerEmail: updateCustomerEmailMutation,
|
|
895
|
-
updateCustomerAddress: updateCustomerAddressMutation
|
|
937
|
+
updateCustomerAddress: updateCustomerAddressMutation,
|
|
938
|
+
updateCustomerDetails: updateCustomerDetailsMutation
|
|
896
939
|
};
|
|
897
940
|
|
|
898
941
|
// src/presenters/base-presenter.js
|
|
@@ -1598,6 +1641,126 @@ var setFixSessionDataService = (yar, sessionData, payload, journeyKey, updateKey
|
|
|
1598
1641
|
yar.set(journeyKey, sessionData);
|
|
1599
1642
|
};
|
|
1600
1643
|
|
|
1644
|
+
// src/services/build-fix-success-message-service.js
|
|
1645
|
+
var LABEL_MAPS = {
|
|
1646
|
+
personal: {
|
|
1647
|
+
name: "full name",
|
|
1648
|
+
email: "personal email address",
|
|
1649
|
+
phone: "personal phone numbers",
|
|
1650
|
+
dob: "date of birth",
|
|
1651
|
+
address: "personal address"
|
|
1652
|
+
},
|
|
1653
|
+
business: {
|
|
1654
|
+
name: "business name",
|
|
1655
|
+
email: "business email address",
|
|
1656
|
+
phone: "business phone numbers",
|
|
1657
|
+
vat: "business vat number",
|
|
1658
|
+
address: "business address"
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
var PROPERTY_MAPS = {
|
|
1662
|
+
personal: {
|
|
1663
|
+
name: "changePersonalName",
|
|
1664
|
+
email: "changePersonalEmail",
|
|
1665
|
+
phone: "changePersonalPhoneNumbers",
|
|
1666
|
+
dob: "changePersonalDob",
|
|
1667
|
+
address: "changePersonalAddress"
|
|
1668
|
+
},
|
|
1669
|
+
business: {
|
|
1670
|
+
name: "changeBusinessName",
|
|
1671
|
+
email: "changeBusinessEmail",
|
|
1672
|
+
phone: "changeBusinessPhoneNumbers",
|
|
1673
|
+
vat: "changeBusinessVat",
|
|
1674
|
+
address: "changeBusinessAddress"
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
var buildFixSuccessMessageService = (type, details) => {
|
|
1678
|
+
const { orderedSectionsToFix } = details;
|
|
1679
|
+
const changes = loopThroughSections(type, details, orderedSectionsToFix);
|
|
1680
|
+
if (changes.length === 0) {
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
if (changes.length === 1) {
|
|
1684
|
+
return {
|
|
1685
|
+
type: "text",
|
|
1686
|
+
value: `You have updated your ${changes[0]}`
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
return {
|
|
1690
|
+
type: "html",
|
|
1691
|
+
value: `
|
|
1692
|
+
<h3 class="govuk-notification-banner__heading">
|
|
1693
|
+
You have updated your:
|
|
1694
|
+
</h3>
|
|
1695
|
+
<ul class="govuk-list govuk-list--bullet">
|
|
1696
|
+
${changes.map((change) => `<li>${change}</li>`).join("")}
|
|
1697
|
+
</ul>
|
|
1698
|
+
`
|
|
1699
|
+
};
|
|
1700
|
+
};
|
|
1701
|
+
var loopThroughSections = (type, details, orderedSectionsToFix) => {
|
|
1702
|
+
const changes = [];
|
|
1703
|
+
const labelMap = LABEL_MAPS[type];
|
|
1704
|
+
const propertyMap = PROPERTY_MAPS[type];
|
|
1705
|
+
for (const section of orderedSectionsToFix) {
|
|
1706
|
+
if (details[propertyMap[section]]) {
|
|
1707
|
+
changes.push(labelMap[section]);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return changes;
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// src/services/personal/build-customer-fix-update-variables-service.js
|
|
1714
|
+
var buildCustomerFixUpdateVariablesService = (personalDetails) => {
|
|
1715
|
+
const { orderedSectionsToFix, crn } = personalDetails;
|
|
1716
|
+
const input = { crn };
|
|
1717
|
+
if (orderedSectionsToFix.includes("name") && personalDetails.changePersonalName) {
|
|
1718
|
+
Object.assign(input, buildNameInput(personalDetails.changePersonalName));
|
|
1719
|
+
}
|
|
1720
|
+
if (orderedSectionsToFix.includes("email") && personalDetails.changePersonalEmail) {
|
|
1721
|
+
Object.assign(input, buildEmailInput(personalDetails.changePersonalEmail));
|
|
1722
|
+
}
|
|
1723
|
+
if (orderedSectionsToFix.includes("phone") && personalDetails.changePersonalPhoneNumbers) {
|
|
1724
|
+
Object.assign(input, buildPhoneInput(personalDetails.changePersonalPhoneNumbers));
|
|
1725
|
+
}
|
|
1726
|
+
if (orderedSectionsToFix.includes("dob") && personalDetails.changePersonalDob) {
|
|
1727
|
+
Object.assign(input, buildDobInput(personalDetails.changePersonalDob));
|
|
1728
|
+
}
|
|
1729
|
+
if (orderedSectionsToFix.includes("address") && personalDetails.changePersonalAddress) {
|
|
1730
|
+
Object.assign(input, { address: buildManualAddress(personalDetails.changePersonalAddress) });
|
|
1731
|
+
}
|
|
1732
|
+
return { input };
|
|
1733
|
+
};
|
|
1734
|
+
var buildPhoneInput = (change) => {
|
|
1735
|
+
return {
|
|
1736
|
+
phone: {
|
|
1737
|
+
landline: change.personalTelephone ?? null,
|
|
1738
|
+
mobile: change.personalMobile ?? null
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
};
|
|
1742
|
+
var buildEmailInput = (change) => {
|
|
1743
|
+
return {
|
|
1744
|
+
email: {
|
|
1745
|
+
address: change.personalEmail
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
};
|
|
1749
|
+
var buildNameInput = (change) => {
|
|
1750
|
+
return {
|
|
1751
|
+
first: change.first,
|
|
1752
|
+
middle: change.middle ?? null,
|
|
1753
|
+
last: change.last
|
|
1754
|
+
};
|
|
1755
|
+
};
|
|
1756
|
+
var buildDobInput = (change) => {
|
|
1757
|
+
const { day, month, year } = change;
|
|
1758
|
+
return {
|
|
1759
|
+
// DAL expects dateOfBirth as YYYY-MM-DD e.g. '1990-04-05' not '1990-4-5'
|
|
1760
|
+
dateOfBirth: `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
|
|
1761
|
+
};
|
|
1762
|
+
};
|
|
1763
|
+
|
|
1601
1764
|
// src/services/services.js
|
|
1602
1765
|
var services = {
|
|
1603
1766
|
addressLookup: addressLookupService,
|
|
@@ -1606,7 +1769,9 @@ var services = {
|
|
|
1606
1769
|
checkInterrupterJourneySession: checkInterrupterJourneySessionService,
|
|
1607
1770
|
initialiseFixJourney: initialiseFixJourneyService,
|
|
1608
1771
|
validateFixDetails: validateFixDetailsService,
|
|
1609
|
-
setFixSessionData: setFixSessionDataService
|
|
1772
|
+
setFixSessionData: setFixSessionDataService,
|
|
1773
|
+
buildFixSuccessMessage: buildFixSuccessMessageService,
|
|
1774
|
+
buildCustomerFixUpdateVariables: buildCustomerFixUpdateVariablesService
|
|
1610
1775
|
};
|
|
1611
1776
|
export {
|
|
1612
1777
|
constants,
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { updateCustomerPhoneMutation } from './personal/update-customer-phone.js
|
|
|
7
7
|
import { updateCustomerEmailMutation } from './personal/update-customer-email.js'
|
|
8
8
|
import { updateCustomerAddressMutation } from './personal/update-customer-address.js'
|
|
9
9
|
import { updateBusinessAddressMutation } from './business/update-business-address.js'
|
|
10
|
+
import { updateCustomerDetailsMutation } from './personal/update-customer-details.js'
|
|
10
11
|
|
|
11
12
|
export const mutations = {
|
|
12
13
|
updateBusinessEmail: updateBusinessEmailMutation,
|
|
@@ -17,5 +18,6 @@ export const mutations = {
|
|
|
17
18
|
updateCustomerDob: updateCustomerDobMutation,
|
|
18
19
|
updateCustomerPhone: updateCustomerPhoneMutation,
|
|
19
20
|
updateCustomerEmail: updateCustomerEmailMutation,
|
|
20
|
-
updateCustomerAddress: updateCustomerAddressMutation
|
|
21
|
+
updateCustomerAddress: updateCustomerAddressMutation,
|
|
22
|
+
updateCustomerDetails: updateCustomerDetailsMutation
|
|
21
23
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const updateCustomerDetailsMutation = `
|
|
2
|
+
mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
|
|
3
|
+
updateCustomerAllFields(input: $input) {
|
|
4
|
+
success
|
|
5
|
+
customer {
|
|
6
|
+
info {
|
|
7
|
+
name {
|
|
8
|
+
first
|
|
9
|
+
middle
|
|
10
|
+
last
|
|
11
|
+
}
|
|
12
|
+
dateOfBirth
|
|
13
|
+
phone {
|
|
14
|
+
mobile
|
|
15
|
+
landline
|
|
16
|
+
}
|
|
17
|
+
email {
|
|
18
|
+
address
|
|
19
|
+
}
|
|
20
|
+
address {
|
|
21
|
+
line1
|
|
22
|
+
line2
|
|
23
|
+
line3
|
|
24
|
+
line4
|
|
25
|
+
line5
|
|
26
|
+
buildingNumberRange
|
|
27
|
+
buildingName
|
|
28
|
+
flatName
|
|
29
|
+
street
|
|
30
|
+
city
|
|
31
|
+
county
|
|
32
|
+
postalCode
|
|
33
|
+
country
|
|
34
|
+
uprn
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a success notification message based on which personal or business
|
|
3
|
+
* details were updated by the user.
|
|
4
|
+
*
|
|
5
|
+
* Returns either plain text (for a single change), HTML (for multiple changes),
|
|
6
|
+
* or null (when nothing changed) suitable for rendering inside a GOV.UK
|
|
7
|
+
* notification banner.
|
|
8
|
+
* @module buildFixSuccessMessageService
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const LABEL_MAPS = {
|
|
12
|
+
personal: {
|
|
13
|
+
name: 'full name',
|
|
14
|
+
email: 'personal email address',
|
|
15
|
+
phone: 'personal phone numbers',
|
|
16
|
+
dob: 'date of birth',
|
|
17
|
+
address: 'personal address'
|
|
18
|
+
},
|
|
19
|
+
business: {
|
|
20
|
+
name: 'business name',
|
|
21
|
+
email: 'business email address',
|
|
22
|
+
phone: 'business phone numbers',
|
|
23
|
+
vat: 'business vat number',
|
|
24
|
+
address: 'business address'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const PROPERTY_MAPS = {
|
|
29
|
+
personal: {
|
|
30
|
+
name: 'changePersonalName',
|
|
31
|
+
email: 'changePersonalEmail',
|
|
32
|
+
phone: 'changePersonalPhoneNumbers',
|
|
33
|
+
dob: 'changePersonalDob',
|
|
34
|
+
address: 'changePersonalAddress'
|
|
35
|
+
},
|
|
36
|
+
business: {
|
|
37
|
+
name: 'changeBusinessName',
|
|
38
|
+
email: 'changeBusinessEmail',
|
|
39
|
+
phone: 'changeBusinessPhoneNumbers',
|
|
40
|
+
vat: 'changeBusinessVat',
|
|
41
|
+
address: 'changeBusinessAddress'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const buildFixSuccessMessageService = (type, details) => {
|
|
46
|
+
const { orderedSectionsToFix } = details
|
|
47
|
+
|
|
48
|
+
const changes = loopThroughSections(type, details, orderedSectionsToFix)
|
|
49
|
+
|
|
50
|
+
if (changes.length === 0) {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (changes.length === 1) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'text',
|
|
57
|
+
value: `You have updated your ${changes[0]}`
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
type: 'html',
|
|
63
|
+
value: `
|
|
64
|
+
<h3 class="govuk-notification-banner__heading">
|
|
65
|
+
You have updated your:
|
|
66
|
+
</h3>
|
|
67
|
+
<ul class="govuk-list govuk-list--bullet">
|
|
68
|
+
${changes.map(change => `<li>${change}</li>`).join('')}
|
|
69
|
+
</ul>
|
|
70
|
+
`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const loopThroughSections = (type, details, orderedSectionsToFix) => {
|
|
75
|
+
const changes = []
|
|
76
|
+
|
|
77
|
+
// Pick the personal/business label and property maps for this journey type
|
|
78
|
+
const labelMap = LABEL_MAPS[type]
|
|
79
|
+
const propertyMap = PROPERTY_MAPS[type]
|
|
80
|
+
|
|
81
|
+
// Loop through the ordered sections and check if each section has change data
|
|
82
|
+
for (const section of orderedSectionsToFix) {
|
|
83
|
+
// Only include a section if its change data is actually present
|
|
84
|
+
if (details[propertyMap[section]]) {
|
|
85
|
+
// Store the human-readable label rather than the raw section key
|
|
86
|
+
changes.push(labelMap[section])
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return changes
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
buildFixSuccessMessageService
|
|
95
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds mutation variables for updating a user's personal details via the fix journey.
|
|
3
|
+
* Only includes the sections that actually need updating, using the
|
|
4
|
+
* unified `input` format for the GraphQL mutation.
|
|
5
|
+
*
|
|
6
|
+
* @module buildCustomerFixUpdateVariablesService
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { buildManualAddress } from '../build-address-variables-service.js'
|
|
10
|
+
|
|
11
|
+
const buildCustomerFixUpdateVariablesService = (personalDetails) => {
|
|
12
|
+
const { orderedSectionsToFix, crn } = personalDetails
|
|
13
|
+
|
|
14
|
+
const input = { crn }
|
|
15
|
+
|
|
16
|
+
// Conditionally merge each section into input if it's been updated by the user
|
|
17
|
+
if (orderedSectionsToFix.includes('name') && personalDetails.changePersonalName) {
|
|
18
|
+
Object.assign(input, buildNameInput(personalDetails.changePersonalName))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (orderedSectionsToFix.includes('email') && personalDetails.changePersonalEmail) {
|
|
22
|
+
Object.assign(input, buildEmailInput(personalDetails.changePersonalEmail))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (orderedSectionsToFix.includes('phone') && personalDetails.changePersonalPhoneNumbers) {
|
|
26
|
+
Object.assign(input, buildPhoneInput(personalDetails.changePersonalPhoneNumbers))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (orderedSectionsToFix.includes('dob') && personalDetails.changePersonalDob) {
|
|
30
|
+
Object.assign(input, buildDobInput(personalDetails.changePersonalDob))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (orderedSectionsToFix.includes('address') && personalDetails.changePersonalAddress) {
|
|
34
|
+
Object.assign(input, { address: buildManualAddress(personalDetails.changePersonalAddress) })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { input }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const buildPhoneInput = (change) => {
|
|
41
|
+
return {
|
|
42
|
+
phone: {
|
|
43
|
+
landline: change.personalTelephone ?? null,
|
|
44
|
+
mobile: change.personalMobile ?? null
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const buildEmailInput = (change) => {
|
|
50
|
+
return {
|
|
51
|
+
email: {
|
|
52
|
+
address: change.personalEmail
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const buildNameInput = (change) => {
|
|
58
|
+
return {
|
|
59
|
+
first: change.first,
|
|
60
|
+
middle: change.middle ?? null,
|
|
61
|
+
last: change.last
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const buildDobInput = (change) => {
|
|
66
|
+
const { day, month, year } = change
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
// DAL expects dateOfBirth as YYYY-MM-DD e.g. '1990-04-05' not '1990-4-5'
|
|
70
|
+
dateOfBirth: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
buildCustomerFixUpdateVariablesService
|
|
76
|
+
}
|
package/src/services/services.js
CHANGED
|
@@ -4,6 +4,8 @@ import { checkInterrupterJourneySessionService } from './check-interrupter-journ
|
|
|
4
4
|
import { initialiseFixJourneyService } from './initialise-fix-journey-service.js'
|
|
5
5
|
import { validateFixDetailsService } from './validate-fix-details-service.js'
|
|
6
6
|
import { setFixSessionDataService } from './set-fix-session-data-service.js'
|
|
7
|
+
import { buildFixSuccessMessageService } from './build-fix-success-message-service.js'
|
|
8
|
+
import { buildCustomerFixUpdateVariablesService } from './personal/build-customer-fix-update-variables-service.js'
|
|
7
9
|
|
|
8
10
|
export const services = {
|
|
9
11
|
addressLookup: addressLookupService,
|
|
@@ -12,5 +14,7 @@ export const services = {
|
|
|
12
14
|
checkInterrupterJourneySession: checkInterrupterJourneySessionService,
|
|
13
15
|
initialiseFixJourney: initialiseFixJourneyService,
|
|
14
16
|
validateFixDetails: validateFixDetailsService,
|
|
15
|
-
setFixSessionData: setFixSessionDataService
|
|
17
|
+
setFixSessionData: setFixSessionDataService,
|
|
18
|
+
buildFixSuccessMessage: buildFixSuccessMessageService,
|
|
19
|
+
buildCustomerFixUpdateVariables: buildCustomerFixUpdateVariablesService
|
|
16
20
|
}
|