Skip to content

Commit

Permalink
fix: trims fname/lname on save and dob -> numbers (#4027)
Browse files Browse the repository at this point in the history
* fix: trims fname/lname on save and dob -> numbers

* trim existing data

* fix: now saving household member data correctly

* fix: migration to remove spaces from rulekeys

* fix: updates to migration

* fix: var update per eric
  • Loading branch information
YazeedLoonat authored Apr 19, 2024
1 parent 76d1075 commit 42b26e0
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 162 deletions.
93 changes: 93 additions & 0 deletions api/prisma/migrations/10_dob_fields_to_int/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
converts `birth_month`, `birth_day`, `birth_year` columns from strings to integers for the "applicant" and "household_member" tables
*/

-- AlterTable applicant
ALTER TABLE "applicant" ADD COLUMN "birth_year_temp" INTEGER;
ALTER TABLE "applicant" ADD COLUMN "birth_month_temp" INTEGER;
ALTER TABLE "applicant" ADD COLUMN "birth_day_temp" INTEGER;

UPDATE "applicant" SET
"birth_year_temp" = CASE WHEN "birth_year" = NULL THEN NULL ELSE "birth_year" :: Integer END,
"birth_month_temp" = CASE WHEN "birth_month" = NULL THEN NULL ELSE "birth_month" :: Integer END,
"birth_day_temp" = CASE WHEN "birth_day" = NULL THEN NULL ELSE "birth_day" :: Integer END;

ALTER TABLE "applicant" DROP COLUMN "birth_year";
ALTER TABLE "applicant" DROP COLUMN "birth_month";
ALTER TABLE "applicant" DROP COLUMN "birth_day";

ALTER TABLE "applicant" ADD COLUMN "birth_year" INTEGER;
ALTER TABLE "applicant" ADD COLUMN "birth_month" INTEGER;
ALTER TABLE "applicant" ADD COLUMN "birth_day" INTEGER;

UPDATE "applicant" SET
"birth_year" = "birth_year_temp",
"birth_month" = "birth_month_temp",
"birth_day" = "birth_day_temp",
"first_name" = TRIM("first_name"),
"last_name" = TRIM("last_name");

ALTER TABLE "applicant" DROP COLUMN "birth_year_temp";
ALTER TABLE "applicant" DROP COLUMN "birth_month_temp";
ALTER TABLE "applicant" DROP COLUMN "birth_day_temp";

-- AlterTable household_member
ALTER TABLE "household_member" ADD COLUMN "birth_year_temp" INTEGER;
ALTER TABLE "household_member" ADD COLUMN "birth_month_temp" INTEGER;
ALTER TABLE "household_member" ADD COLUMN "birth_day_temp" INTEGER;

UPDATE "household_member" SET
"birth_year_temp" = CASE WHEN "birth_year" = NULL THEN NULL ELSE "birth_year" :: Integer END,
"birth_month_temp" = CASE WHEN "birth_month" = NULL THEN NULL ELSE "birth_month" :: Integer END,
"birth_day_temp" = CASE WHEN "birth_day" = NULL THEN NULL ELSE "birth_day" :: Integer END;

ALTER TABLE "household_member" DROP COLUMN "birth_year";
ALTER TABLE "household_member" DROP COLUMN "birth_month";
ALTER TABLE "household_member" DROP COLUMN "birth_day";

ALTER TABLE "household_member" ADD COLUMN "birth_year" INTEGER;
ALTER TABLE "household_member" ADD COLUMN "birth_month" INTEGER;
ALTER TABLE "household_member" ADD COLUMN "birth_day" INTEGER;

UPDATE "household_member" SET
"birth_year" = "birth_year_temp",
"birth_month" = "birth_month_temp",
"birth_day" = "birth_day_temp",
"first_name" = TRIM("first_name"),
"last_name" = TRIM("last_name");

ALTER TABLE "household_member" DROP COLUMN "birth_year_temp";
ALTER TABLE "household_member" DROP COLUMN "birth_month_temp";
ALTER TABLE "household_member" DROP COLUMN "birth_day_temp";


-- Unify AFS
UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, ' ', '');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-01-', '-1-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-02-', '-2-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-03-', '-3-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-04-', '-4-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-05-', '-5-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-06-', '-6-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-07-', '-7-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-08-', '-8-');

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, '-09-', '-9-');
12 changes: 6 additions & 6 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ model Applicant {
firstName String? @map("first_name")
middleName String? @map("middle_name")
lastName String? @map("last_name")
birthMonth String? @map("birth_month")
birthDay String? @map("birth_day")
birthYear String? @map("birth_year")
birthMonth Int? @map("birth_month")
birthDay Int? @map("birth_day")
birthYear Int? @map("birth_year")
emailAddress String? @map("email_address")
noEmail Boolean? @map("no_email")
phoneNumber String? @map("phone_number")
Expand Down Expand Up @@ -296,9 +296,9 @@ model HouseholdMember {
firstName String? @map("first_name")
middleName String? @map("middle_name")
lastName String? @map("last_name")
birthMonth String? @map("birth_month")
birthDay String? @map("birth_day")
birthYear String? @map("birth_year")
birthMonth Int? @map("birth_month")
birthDay Int? @map("birth_day")
birthYear Int? @map("birth_year")
sameAddress YesNoEnum? @map("same_address")
relationship String?
workInRegion YesNoEnum? @map("work_in_region")
Expand Down
6 changes: 3 additions & 3 deletions api/prisma/seed-helpers/application-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export const applicantFactory = (
phoneNumberType: 'home',
noPhone: false,
workInRegion: YesNoEnum.no,
birthDay: `${randomBirthDay()}`, // no zeros
birthMonth: `${randomBirthMonth()}`, // no zeros
birthYear: `${randomBirthYear()}`,
birthDay: randomBirthDay(), // no zeros
birthMonth: randomBirthMonth(), // no zeros
birthYear: randomBirthYear(),
applicantAddress: {
create: addressFactory(),
},
Expand Down
6 changes: 3 additions & 3 deletions api/prisma/seed-helpers/household-member-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const householdMemberFactorySingle =
middleName: randomNoun(),
lastName: lastName,
// Question: why are these strings?
birthMonth: randomBirthMonth().toString(),
birthDay: randomBirthDay().toString(),
birthYear: randomBirthYear().toString(),
birthMonth: randomBirthMonth(),
birthDay: randomBirthDay(),
birthYear: randomBirthYear(),
sameAddress: randomYesNo,
// Question: should this be an enum?
relationship: randomAdjective(),
Expand Down
12 changes: 6 additions & 6 deletions api/src/services/application-flagged-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,15 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
householdMember: {
some: {
birthMonth: {
in: birthMonths,
in: birthMonths.map((val) => Number(val)),
},
},
},
},
{
applicant: {
birthMonth: {
in: birthMonths,
in: birthMonths.map((val) => Number(val)),
},
},
},
Expand All @@ -811,15 +811,15 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
householdMember: {
some: {
birthDay: {
in: birthDays,
in: birthDays.map((val) => Number(val)),
},
},
},
},
{
applicant: {
birthDay: {
in: birthDays,
in: birthDays.map((val) => Number(val)),
},
},
},
Expand All @@ -831,15 +831,15 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
householdMember: {
some: {
birthYear: {
in: birthYears,
in: birthYears.map((val) => Number(val)),
},
},
},
},
{
applicant: {
birthYear: {
in: birthYears,
in: birthYears.map((val) => Number(val)),
},
},
},
Expand Down
40 changes: 40 additions & 0 deletions api/src/services/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,17 @@ export class ApplicationService {
...dto.applicant.applicantWorkAddress,
},
},
firstName: dto.applicant.firstName?.trim(),
lastName: dto.applicant.lastName?.trim(),
birthDay: dto.applicant.birthDay
? Number(dto.applicant.birthDay)
: undefined,
birthMonth: dto.applicant.birthMonth
? Number(dto.applicant.birthMonth)
: undefined,
birthYear: dto.applicant.birthYear
? Number(dto.applicant.birthYear)
: undefined,
},
}
: undefined,
Expand Down Expand Up @@ -621,6 +632,15 @@ export class ApplicationService {
...member.householdMemberWorkAddress,
},
},
firstName: member.firstName?.trim(),
lastName: member.lastName?.trim(),
birthDay: member.birthDay ? Number(member.birthDay) : undefined,
birthMonth: member.birthMonth
? Number(member.birthMonth)
: undefined,
birthYear: member.birthYear
? Number(member.birthYear)
: undefined,
})),
}
: undefined,
Expand Down Expand Up @@ -711,6 +731,17 @@ export class ApplicationService {
...dto.applicant.applicantWorkAddress,
},
},
firstName: dto.applicant.firstName?.trim(),
lastName: dto.applicant.lastName?.trim(),
birthDay: dto.applicant.birthDay
? Number(dto.applicant.birthDay)
: undefined,
birthMonth: dto.applicant.birthMonth
? Number(dto.applicant.birthMonth)
: undefined,
birthYear: dto.applicant.birthYear
? Number(dto.applicant.birthYear)
: undefined,
},
}
: undefined,
Expand Down Expand Up @@ -784,6 +815,15 @@ export class ApplicationService {
...member.householdMemberWorkAddress,
},
},
firstName: member.firstName?.trim(),
lastName: member.lastName?.trim(),
birthDay: member.birthDay ? Number(member.birthDay) : undefined,
birthMonth: member.birthMonth
? Number(member.birthMonth)
: undefined,
birthYear: member.birthYear
? Number(member.birthYear)
: undefined,
})),
}
: undefined,
Expand Down
Loading

0 comments on commit 42b26e0

Please sign in to comment.