amplify icon indicating copy to clipboard operation
amplify copied to clipboard

[Function] Refactor to add validations to create_address

Open paramsiddharth opened this issue 2 years ago • 1 comments

User story:

  • this function helps validate the address of the constituent before sending as a lettet
  • Select lines 57-80 in lob.js within server > routes/api
  • We're going to now make

Copilot Prompts

  • Type into chat:
    • [ ] what does this function do
    • [ ] how can I make this more readable
    • [ ] how can I refactor this to be better
  • [ ] See if it makes sense to update this file through whats given:
const { line1, city, state, zip } = address;


if (!line1?.trim() || (!zip?.trim() && (!city?.trim() || !state?.trim()))) {
	throw new Error('Address object must contain a primary line (line1) and either a ZIP code or both city and state');
}


if (zip && typeof zip !== 'string') {
	throw new Error('Address object must contain a string-based ZIP code');
}


if (zip && !VALID_US_ZIP_CODE_MATCH.test(zip.trim())) {
	throw new Error(`Address object contained an invalid ZIP code: ${zip.trim()}`);
}

paramsiddharth avatar Sep 22 '23 15:09 paramsiddharth

Branch: issue-592

Dunridge avatar Dec 12 '23 16:12 Dunridge