Skip to content

Instantly share code, notes, and snippets.

@gecugamo
Last active January 21, 2026 23:33
Show Gist options
  • Select an option

  • Save gecugamo/6f54ec7e0f13f928b96faf85d00bb74f to your computer and use it in GitHub Desktop.

Select an option

Save gecugamo/6f54ec7e0f13f928b96faf85d00bb74f to your computer and use it in GitHub Desktop.
Persistable Required Fields with Instanced Attribute Payload
const payload = {
attributes: [
{
attribute_id: "address_zipcode",
attribute_hash: "45486028e8690603de6e69c2a772584ad1a81429a07777ee10ecb4369e506980",
value: "91403"
},
{
attribute_id: "address_zipcode",
attribute_hash: "584ad1a81429a07777ee10ecb4369e50698045486028e8690603de6e69c2a772",
value: "60062"
},
{
attribute_id: "coverage_animal_liability",
attribute_hash: "973580bc00e13b09b07b5de224d4d8b725a8f5dd86221947bf0d4a6b6a53ccaf",
value: 0
},
{
attribute_id: "coverage_coverage_a",
attribute_hash: "2264c3e3494ecd803ce28340e809fabfed469505f28aac7e2dafd663996a6232",
value: 1323000
},
{
attribute_id: "coverage_coverage_c",
attribute_hash: "5c6fa540593b1664635d548f9b72d91d73951746d20563eb83681d044e6eedfa",
value: "25%"
},
{
attribute_id: "coverage_coverage_e",
attribute_hash: "87f965561fcd49390dda5b8f02c6649cb2fcde3883ffd0dd7bc9cc7350248861",
value: 300000
},
{
attribute_id: "coverage_coverage_f",
attribute_hash: "74a1dc28bc1c0062198dce71a19da403db751f3d114deb7803e873595bf8cebd",
value: 1000
},
{
attribute_id: "coverage_earthquake_coverage",
attribute_hash: "ba63e33bf5c01b85fb98e881536856cc9a5bff7cd071cea6d95778e11f0e9dcb",
value: false
},
],
errors: []
};
const attributesByName = Object.groupBy(payload.attributes, ({ attribute_id }) => attribute_id);
const peristableRequiredFields = Object.entries(attributesByName).reduce((result, [name, data]) => {
if (data.length === 1) {
result[name] = data[0].value;
} else {
data.forEach((item) => {
result[`${name}_${item.attribute_hash}`] = item.value;
});
}
return result;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment