Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dropdown values intake forms, DB migration to convert previous values to new values #231

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/controllers/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const controller = {
if (data.basic) {
basic = {
consentToFeedback: data.basic.consentToFeedback ?? false,
isDevelopedByCompanyOrOrg: data.basic.isDevelopedByCompanyOrOrg,
projectApplicantType: data.basic.projectApplicantType,
isDevelopedInBC: data.basic.isDevelopedInBC,
companyNameRegistered: data.basic.registeredName
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable max-len */
import type { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
return Promise.resolve()
.then(() =>
knex.schema.raw(`update public.contact
set contact_applicant_relationship = case
when contact_applicant_relationship = 'Owner' then 'Property owner'
when contact_applicant_relationship = 'Employee' then 'Project consultant'
when contact_applicant_relationship = 'Agent' then 'Project consultant'
when contact_applicant_relationship = 'Consultant' then 'Project consultant'
else contact_applicant_relationship
end`)
)

.then(() =>
knex.schema.raw(`update public.submission
set is_developed_by_company_or_org = case
when is_developed_by_company_or_org = 'No' then 'Individual'
else 'Business'
end`)
)

.then(() =>
knex.schema.alterTable('submission', (table) => {
table.renameColumn('is_developed_by_company_or_org', 'project_applicant_type');
})
);
}

export async function down(knex: Knex): Promise<void> {
return Promise.resolve()

.then(() =>
knex.schema.alterTable('submission', (table) => {
table.renameColumn('project_applicant_type', 'is_developed_by_company_or_org');
})
)
.then(() =>
knex.schema.raw(`update public.submission
set is_developed_by_company_or_org = case
when is_developed_by_company_or_org = 'Individual' then 'No'
else 'Yes'
end`)
)

.then(() =>
knex.schema.raw(`update public.contact
set contact_applicant_relationship = case
when contact_applicant_relationship = 'Property owner' then 'Owner'
when contact_applicant_relationship = 'Project consultant' then 'Agent'
else contact_applicant_relationship
end`)
);
}
4 changes: 2 additions & 2 deletions app/src/db/models/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
waiting_on: input.waitingOn,
intake_status: input.intakeStatus,
application_status: input.applicationStatus,
is_developed_by_company_or_org: input.isDevelopedByCompanyOrOrg,
project_applicant_type: input.projectApplicantType,
is_developed_in_bc: input.isDevelopedInBC,
multi_family_units: input.multiFamilyUnits,
other_units: input.otherUnits,
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
waitingOn: input.waiting_on,
intakeStatus: input.intake_status,
applicationStatus: input.application_status,
isDevelopedByCompanyOrOrg: input.is_developed_by_company_or_org,
projectApplicantType: input.project_applicant_type,
isDevelopedInBC: input.is_developed_in_bc,
multiFamilyUnits: input.multi_family_units,
otherUnits: input.other_units,
Expand Down
2 changes: 1 addition & 1 deletion app/src/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ model submission {
updated_at DateTime? @db.Timestamptz(6)
has_rental_units String?
project_description String?
is_developed_by_company_or_org String?
project_applicant_type String?
is_developed_in_bc String?
multi_family_units String?
other_units String?
Expand Down
20 changes: 10 additions & 10 deletions app/src/docs/v1.api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ components:
example: [email protected]
contactApplicantRelationship:
type: string
enum: [Owner, Employee, Agent, Consultant, Other]
enum: [Property owner, Project consultant, Other]
jujaga marked this conversation as resolved.
Show resolved Hide resolved
kyle1morel marked this conversation as resolved.
Show resolved Hide resolved
description: Relationship of the contact person to the project
example: Agent
contactPreference:
Expand Down Expand Up @@ -1638,10 +1638,11 @@ components:
type: string
description: Status of the application
example: New
isDevelopedByCompanyOrOrg:
projectApplicantType:
type: string
description: Is the project being developed by a company or organization
example: 'Yes'
enum: [Business, Individual]
description: Are you applying as an individual or as a business?
example: 'Business'
isDevelopedInBC:
type: string
description: Is the project developed in BC?
Expand Down Expand Up @@ -1993,12 +1994,11 @@ components:
basic:
type: object
properties:
isDevelopedByCompanyOrOrg:
type: boolean
description: >-
Indicates if the project is being developed by a company or
organization
example: true
projectApplicantType:
type: string
enum: [Business, Individual]
description: Are you applying as an individual or as a business?
example: 'Business'
isDevelopedInBC:
type: boolean
description: >-
Expand Down
2 changes: 1 addition & 1 deletion app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const service = {
has_applied_provincial_permits: x.hasAppliedProvincialPermits,
housing_coop_description: x.housingCoopDescription,
indigenous_description: x.indigenousDescription,
is_developed_by_company_or_org: x.isDevelopedByCompanyOrOrg,
project_applicant_type: x.projectApplicantType,
is_developed_in_bc: x.isDevelopedInBC,
intake_status: x.intakeStatus,
location_pids: x.locationPIDs,
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/Submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type Submission = {
waitingOn: string | null;
intakeStatus: string | null;
applicationStatus: string | null;
isDevelopedByCompanyOrOrg: string | null;
projectApplicantType: string | null;
isDevelopedInBC: string | null;
multiFamilyUnits: string | null;
otherUnits: string | null;
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/SubmissionIntake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SubmissionIntake = {

basic?: {
consentToFeedback?: boolean;
isDevelopedByCompanyOrOrg?: string | null;
projectApplicantType?: string | null;
isDevelopedInBC?: string | null;
registeredName?: string;
};
Expand Down
5 changes: 3 additions & 2 deletions app/src/utils/constants/housing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PermitAuthorizationStatus,
PermitNeeded,
PermitStatus,
ProjectApplicant,
ProjectLocation,
ProjectRelationship,
SubmissionType
Expand Down Expand Up @@ -72,10 +73,10 @@ export const ORG_BOOK_QUERY_PARAMS = {
revoked: false
};

export const PROJECT_APPLICANT_LIST = [ProjectApplicant.BUSINESS, ProjectApplicant.INDIVIDUAL];

export const PROJECT_RELATIONSHIP_LIST = [
ProjectRelationship.OWNER,
ProjectRelationship.EMPLOYEE,
ProjectRelationship.AGENT,
ProjectRelationship.CONSULTANT,
ProjectRelationship.OTHER
];
Expand Down
11 changes: 7 additions & 4 deletions app/src/utils/enums/housing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ export enum PermitStatus {
PENDING = 'Pending decision'
}

export enum ProjectApplicant {
BUSINESS = 'Business',
INDIVIDUAL = 'Individual'
}

export enum ProjectRelationship {
OWNER = 'Owner',
EMPLOYEE = 'Employee',
AGENT = 'Agent',
CONSULTANT = 'Consultant',
OWNER = 'Property owner',
CONSULTANT = 'Project consultant',
jujaga marked this conversation as resolved.
Show resolved Hide resolved
kyle1morel marked this conversation as resolved.
Show resolved Hide resolved
OTHER = 'Other'
}

Expand Down
16 changes: 8 additions & 8 deletions app/src/validators/basic.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import Joi from 'joi';

import { YES_NO_LIST } from '../utils/constants/application';
import { ENQUIRY_TYPE_LIST } from '../utils/constants/housing';
import { BasicResponse } from '../utils/enums/application';
import { ENQUIRY_TYPE_LIST, PROJECT_APPLICANT_LIST } from '../utils/constants/housing';
import { ProjectApplicant } from '../utils/enums/housing';

export const basicIntake = Joi.object({
consentToFeedback: Joi.boolean(),
isDevelopedByCompanyOrOrg: Joi.string()
projectApplicantType: Joi.string()
.required()
.valid(...YES_NO_LIST),
isDevelopedInBC: Joi.when('isDevelopedByCompanyOrOrg', {
is: BasicResponse.YES,
.valid(...PROJECT_APPLICANT_LIST),
isDevelopedInBC: Joi.when('projectApplicantType', {
is: ProjectApplicant.BUSINESS,
then: Joi.string()
.required()
.valid(...YES_NO_LIST),
otherwise: Joi.string().allow(null)
}),
registeredName: Joi.when('isDevelopedInBC', {
is: Joi.valid(BasicResponse.YES, BasicResponse.NO),
registeredName: Joi.when('projectApplicantType', {
is: ProjectApplicant.BUSINESS,
then: Joi.string().required().max(255).trim(),
otherwise: Joi.string().allow(null)
})
Expand Down
14 changes: 7 additions & 7 deletions app/tests/unit/controllers/submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SUBMISSION_1 = {
contactPhoneNumber: null,
contactEmail: null,
contactPreference: null,
contactApplicantRelationship: null,
contactApplicantRelationship: 'Property owner',
projectName: null,
projectDescription: null,
singleFamilyUnits: null,
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('createSubmission', () => {
body: {
applicant: {},
basic: {
isDevelopedByCompanyOrOrg: true
projectApplicantType: 'Individual'
},
housing: {
projectName: 'TheProject'
Expand All @@ -146,7 +146,7 @@ describe('createSubmission', () => {
expect(createSubmissionSpy).toHaveBeenCalledTimes(1);
expect(createSubmissionSpy).toHaveBeenCalledWith(
expect.objectContaining({
isDevelopedByCompanyOrOrg: true,
projectApplicantType: 'Individual',
projectName: 'TheProject',
projectLocation: 'Some place',
hasAppliedProvincialPermits: true,
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('submitDraft', () => {
body: {
contacts: [{ firstName: 'test', lastName: 'person' }],
basic: {
isDevelopedByCompanyOrOrg: true
projectApplicantType: 'Individual'
},
housing: {
projectName: 'TheProject'
Expand Down Expand Up @@ -436,7 +436,7 @@ describe('submitDraft', () => {
expect(createSubmissionSpy).toHaveBeenCalledTimes(1);
expect(createSubmissionSpy).toHaveBeenCalledWith(
expect.objectContaining({
isDevelopedByCompanyOrOrg: true,
projectApplicantType: 'Individual',
projectName: 'TheProject',
projectLocation: 'Some place',
hasAppliedProvincialPermits: true,
Expand Down Expand Up @@ -558,7 +558,7 @@ describe('updateDraft', () => {
contactFirstName: 'test',
contactLastName: 'person',
basic: {
isDevelopedByCompanyOrOrg: true
projectApplicantType: 'Business'
},
housing: {
projectName: 'TheProject'
Expand Down Expand Up @@ -600,7 +600,7 @@ describe('updateDraft', () => {
contactFirstName: 'test',
contactLastName: 'person',
basic: {
isDevelopedByCompanyOrOrg: true
projectApplicantType: 'Business'
},
housing: {
projectName: 'TheProject'
Expand Down
19 changes: 10 additions & 9 deletions app/tests/unit/validators/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BasicResponse } from '../../../src/utils/enums/application';
import { ProjectApplicant } from '../../../src/utils/enums/housing';
import { basicIntake, basicEnquiry } from '../../../src/validators/basic';

describe('basicIntakeSchema', () => {
it('should validate when isDevelopedByCompanyOrOrg and isDevelopedInBC are valid', () => {
it('should validate when projectApplicantType and isDevelopedInBC are valid', () => {
const data = {
isDevelopedByCompanyOrOrg: BasicResponse.YES,
projectApplicantType: ProjectApplicant.BUSINESS,
isDevelopedInBC: BasicResponse.YES,
registeredName: 'My Company'
};
Expand All @@ -13,9 +14,9 @@ describe('basicIntakeSchema', () => {
expect(result.error).toBeUndefined();
});

it('should throw an error when isDevelopedByCompanyOrOrg is invalid', () => {
it('should throw an error when projectApplicantType is invalid', () => {
const data = {
isDevelopedByCompanyOrOrg: 'invalid',
projectApplicantType: 'invalid',
isDevelopedInBC: BasicResponse.YES,
registeredName: 'My Company'
};
Expand All @@ -26,27 +27,27 @@ describe('basicIntakeSchema', () => {

it('should throw an error when isDevelopedInBC is invalid', () => {
const data = {
isDevelopedByCompanyOrOrg: BasicResponse.YES,
projectApplicantType: ProjectApplicant.BUSINESS,
isDevelopedInBC: 'invalid'
};

const result = basicIntake.validate(data);
expect(result.error).toBeDefined();
});

it('should throw an error when isDevelopedInBC is YES but registeredName is not provided', () => {
it('should throw an error when isDevelopedInBC is BUSINESS but registeredName is not provided', () => {
const data = {
isDevelopedByCompanyOrOrg: BasicResponse.YES,
projectApplicantType: ProjectApplicant.BUSINESS,
isDevelopedInBC: BasicResponse.YES
};

const result = basicIntake.validate(data);
expect(result.error).toBeDefined();
});

it('should throw an error when isDevelopedInBC is NO and registeredName is not provided', () => {
it('should throw an error when isDevelopedInBC is BUSINESS and registeredName is not provided', () => {
const data = {
isDevelopedByCompanyOrOrg: BasicResponse.YES,
projectApplicantType: ProjectApplicant.BUSINESS,
isDevelopedInBC: BasicResponse.NO
};

Expand Down
8 changes: 4 additions & 4 deletions app/tests/unit/validators/contacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('contactsSchema', () => {
firstName: 'John',
lastName: 'Doe',
phoneNumber: '1234567890',
contactApplicantRelationship: 'Employee'
contactApplicantRelationship: 'Project consultant'
}
];
const result = contactsSchema.validate(contacts);
Expand All @@ -60,7 +60,7 @@ describe('contactsSchema', () => {
firstName: 'John',
lastName: 'Doe',
phoneNumber: '1234567890',
contactApplicantRelationship: 'Employee'
contactApplicantRelationship: 'Project consultant'
}
];
const result = contactsSchema.validate(contacts);
Expand All @@ -75,7 +75,7 @@ describe('contactsSchema', () => {
firstName: 'John',
lastName: 'Doe',
phoneNumber: '+1234567890',
contactApplicantRelationship: 'Employee'
contactApplicantRelationship: 'Project consultant'
}
];
const result = contactsSchema.validate(contacts);
Expand All @@ -90,7 +90,7 @@ describe('contactsSchema', () => {
firstName: 'John',
lastName: 'Doe',
phoneNumber: '12345678901',
contactApplicantRelationship: 'Employee'
contactApplicantRelationship: 'Project consultant'
}
];
const result = contactsSchema.validate(contacts);
Expand Down
Loading
Loading