mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// utils/personalInfo.util.js
|
||||
|
||||
/**
|
||||
* Computes full_name, full_address, full_number
|
||||
* from a personal_info object before saving to DB.
|
||||
*
|
||||
* @param {Object} personalInfo
|
||||
* @returns {Object} enriched personal_info
|
||||
*/
|
||||
function enrichPersonalInfo(personalInfo = {}) {
|
||||
if (!personalInfo || typeof personalInfo !== 'object') return personalInfo;
|
||||
|
||||
const pi = { ...personalInfo };
|
||||
|
||||
// ── Full Name ────────────────────────────────────────────────────────────────
|
||||
if (pi.name) {
|
||||
const { last_name, given_name, middle_name, extension_name } = pi.name;
|
||||
|
||||
pi.name = {
|
||||
...pi.name,
|
||||
full_name: [
|
||||
last_name ? `${last_name},` : null,
|
||||
given_name,
|
||||
middle_name,
|
||||
extension_name,
|
||||
]
|
||||
.filter((v) => v && v.trim() !== '')
|
||||
.join(' '),
|
||||
};
|
||||
}
|
||||
|
||||
// ── Full Addresses ───────────────────────────────────────────────────────────
|
||||
if (Array.isArray(pi.addresses)) {
|
||||
pi.addresses = pi.addresses.map((addr) => ({
|
||||
...addr,
|
||||
full_address: [
|
||||
addr.street,
|
||||
addr.city,
|
||||
addr.state,
|
||||
addr.country,
|
||||
addr.zip,
|
||||
]
|
||||
.filter((v) => v && v.trim() !== '')
|
||||
.join(', '),
|
||||
}));
|
||||
}
|
||||
|
||||
// ── Full Phone Numbers ───────────────────────────────────────────────────────
|
||||
if (Array.isArray(pi.phone_number)) {
|
||||
pi.phone_number = pi.phone_number.map((phone) => ({
|
||||
...phone,
|
||||
full_number: `${phone.country_code || ''}${phone.number || ''}`,
|
||||
}));
|
||||
}
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
module.exports = { enrichPersonalInfo };
|
||||
Reference in New Issue
Block a user