cityssm/parking-ticket-system

View on GitHub
helpers/functions.owner.ts

Summary

Maintainability
A
0 mins
Test Coverage
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable sonarjs/no-nested-template-literals */

import type { ReconciliationRecord } from '../database/parkingDB/getOwnershipReconciliationRecords.js'
import type { LicencePlateOwner } from '../types/recordTypes.js'

export function getFormattedOwnerAddress(
  owner: LicencePlateOwner | ReconciliationRecord
): string {
  const fieldPrefix = 'ownerName1' in owner ? '' : 'owner_'

  return `${owner[`${fieldPrefix}ownerName1`] as string}\n
      ${
        owner[`${fieldPrefix}ownerName2`] &&
        owner[`${fieldPrefix}ownerName2`] !== ''
          ? `${owner[`${fieldPrefix}ownerName2`] as string}\n`
          : ''
      }${owner[`${fieldPrefix}ownerAddress`] as string}\n
      ${owner[`${fieldPrefix}ownerCity`] as string}, ${
    owner[`${fieldPrefix}ownerProvince`] as string
  }  ${owner[`${fieldPrefix}ownerPostalCode`] as string}`
}