Skip to content

Commit

Permalink
fix: add geocoding fields to csv (#3778)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrissDrawing authored Dec 21, 2023
1 parent 2dfe7e3 commit de93fbb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
14 changes: 13 additions & 1 deletion backend/core/src/applications/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dayjs from "dayjs"
import { formatLocalDate } from "../shared/utils/format-local-date"
import { ApplicationSubmissionType } from "../../types"
import { ApplicationSubmissionType, GeocodingValues } from "../../types"
import { isEmpty } from "class-validator"

export const formatApplicationDate = (
Expand All @@ -14,3 +14,15 @@ export const formatApplicationDate = (
}
return dayjs(dateString).format("MM-DD-YYYY hh:mm:ssA")
}

export const formatGeocodingValues = (key: GeocodingValues) => {
switch (key) {
case GeocodingValues.true:
return "Yes"
case GeocodingValues.false:
return "No"
case GeocodingValues.unknown:
default:
return "Needs Manual Verification"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { formatBoolean } from "../../shared/utils/format-boolean"
import { ApplicationMultiselectQuestion } from "../entities/application-multiselect-question.entity"
import { AddressCreateDto } from "../../shared/dto/address.dto"
import { ApplicationReviewStatus } from "../types/application-review-status-enum"
import { formatApplicationDate } from "../helpers"
import { formatApplicationDate, formatGeocodingValues } from "../helpers"
import { GeocodingValues } from "../../shared/types/geocoding-values"

@Injectable({ scope: Scope.REQUEST })
export class ApplicationCsvExporterService {
Expand Down Expand Up @@ -88,20 +89,44 @@ export class ApplicationCsvExporterService {
claimedString = claimedString.concat(`${option.key}, `)
}
if (option.extraData?.length) {
const extraKey = `${root}: ${option.key} - Address`
let extraKey
let extraString = ""
option.extraData.forEach((extra) => {
if (extra.type === "address") {
extraString += `${(extra.value as AddressCreateDto).street}, ${
(extra.value as AddressCreateDto).street2
? `${(extra.value as AddressCreateDto).street2},`
: ""
} ${(extra.value as AddressCreateDto).city}, ${
(extra.value as AddressCreateDto).state
}, ${(extra.value as AddressCreateDto).zipCode}`
}
})
extraData[extraKey] = extraString
const order = [
"address",
"geocodingVerified",
"addressHolderName",
"addressHolderRelationship",
]

option.extraData
.sort((a, b) => order.indexOf(a.key) - order.indexOf(b.key))
.forEach((extra) => {
if (extra.type === "address") {
extraKey = `${root}: ${option.key} - Provided Address`
extraString += `${(extra.value as AddressCreateDto).street}, ${
(extra.value as AddressCreateDto).street2
? `${(extra.value as AddressCreateDto).street2},`
: ""
} ${(extra.value as AddressCreateDto).city}, ${
(extra.value as AddressCreateDto).state
}, ${(extra.value as AddressCreateDto).zipCode}`
}
if (extra.type === "text") {
if (extra.key === "geocodingVerified") {
extraKey = `${root}: ${option.key} - Passed Address Check`
extraString = formatGeocodingValues(extra.value as GeocodingValues)
}
if (extra.key === "addressHolderName") {
extraKey = `${root}: ${option.key} - Name of Address Holder`
extraString = extra.value as string
}
if (extra.key === "addressHolderRelationship") {
extraKey = `${root}: ${option.key} - Relationship to Address Holder`
extraString = extra.value as string
}
}
extraData[extraKey] = extraString
})
}
})
preferenceKeys[root] = 1
Expand Down

0 comments on commit de93fbb

Please sign in to comment.