amplify
amplify copied to clipboard
[Function] Refactor to add validations to create_address
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()}`);
}
Branch: issue-592