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

Include additional fields for submission table, UI updates #54

Merged
merged 4 commits into from
Apr 5, 2024
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 .github/environments/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config:
enabled: true
configMap:
FRONTEND_APIPATH: api/v1
# FRONTEND_CHES_BCC: ~
FRONTEND_CHES_BCC: [email protected]
FRONTEND_COMS_APIPATH: https://coms-dev.api.gov.bc.ca/api/v1
FRONTEND_COMS_BUCKETID: 1f9e1451-c130-4804-aeb0-b78b5b109c47
FRONTEND_OIDC_AUTHORITY: https://dev.loginproxy.gov.bc.ca/auth/realms/standard
Expand Down
2 changes: 1 addition & 1 deletion .github/environments/values.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ config:
enabled: true
configMap:
FRONTEND_APIPATH: api/v1
# FRONTEND_CHES_BCC: ~
FRONTEND_CHES_BCC: [email protected]
FRONTEND_COMS_APIPATH: https://coms-test.api.gov.bc.ca/api/v1
FRONTEND_COMS_BUCKETID: a9eabd1d-5f77-4c60-bf6b-83ffa0e21c59
FRONTEND_OIDC_AUTHORITY: https://test.loginproxy.gov.bc.ca/auth/realms/standard
Expand Down
6 changes: 6 additions & 0 deletions app/src/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export const APPLICATION_STATUS_LIST = Object.freeze({
COMPLETED: 'Completed'
});

export const RENTAL_STATUS_LIST = Object.freeze({
YES: 'Yes',
NO: 'No',
UNSURE: 'Unsure'
});

/** Types of notes */
export const NOTE_TYPE_LIST = Object.freeze({
GENERAL: 'General',
Expand Down
26 changes: 26 additions & 0 deletions app/src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ import type { ChefsFormConfig, ChefsFormConfigData, CurrentUser } from '../types

const log = getLogger(module.filename);

/**
* @function camelCaseToTitleCase
* Converts a string to title case that can handle camel case
* @param {string | null} str The string to convert
* @returns {string | null} A string in title case
*/
export function camelCaseToTitleCase(input: string | null): string | null {
if (!input) return input;

Copy link

@jatindersingh93 jatindersingh93 Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be get rid of extra line

const result = input.replace(/([A-Z])/g, ' $1');
return (result.charAt(0).toUpperCase() + result.slice(1)).trim();
}

/**
* @function deDupeUnsure
* Checks if input string is 'unsureunsure' and returns it deduplicated
* Otherwise returns input
* @param {string} str The input string
* @returns {string} Deduplicated input or the input itself
*/
export function deDupeUnsure(str: string | null): string | null {
if (str === 'unsureunsure') {
return 'unsure';
} else return str;
}

/**
* @function addDashesToUuid
* Yields a lowercase uuid `str` that has dashes inserted, or `str` if not a string.
Expand Down
12 changes: 9 additions & 3 deletions app/src/controllers/submission.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config from 'config';
import { NIL, v4 as uuidv4 } from 'uuid';

import { APPLICATION_STATUS_LIST } from '../components/constants';
import { getCurrentIdentity, isTruthy, toTitleCase } from '../components/utils';
import { APPLICATION_STATUS_LIST, RENTAL_STATUS_LIST } from '../components/constants';
import { camelCaseToTitleCase, deDupeUnsure, getCurrentIdentity, isTruthy, toTitleCase } from '../components/utils';
import { submissionService, permitService, userService } from '../services';

import type { NextFunction, Request, Response } from '../interfaces/IExpress';
Expand Down Expand Up @@ -111,18 +111,24 @@ const controller = {
applicationStatus: APPLICATION_STATUS_LIST.NEW,
companyNameRegistered: data.companyNameRegistered,
contactEmail: data.contactEmail,
contactPreference: camelCaseToTitleCase(data.contactPreference),
projectName: data.projectName,
projectDescription: data.projectDescription,
contactPhoneNumber: data.contactPhoneNumber,
contactName: `${data.contactFirstName} ${data.contactLastName}`,
contactApplicantRelationship: camelCaseToTitleCase(data.contactApplicantRelationship),
financiallySupported: Object.values(financiallySupportedValues).includes(true),
...financiallySupportedValues,
intakeStatus: toTitleCase(data.form.status),
locationPIDs: data.parcelID,
latitude: data.latitude,
longitude: data.longitude,
naturalDisaster: data.naturalDisasterInd,
projectName: data.projectName,
queuePriority: parseInt(data.queuePriority),
singleFamilyUnits: maxUnits,
isRentalUnit: data.isRentalUnit
? camelCaseToTitleCase(deDupeUnsure(data.isRentalUnit))
: RENTAL_STATUS_LIST.UNSURE,
streetAddress: data.streetAddress,
submittedAt: data.form.createdAt,
submittedBy: data.form.username,
Expand Down
24 changes: 24 additions & 0 deletions app/src/db/migrations/20240402000000_002-submission-updates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RENTAL_STATUS_LIST } from '../../components/constants';
import type { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
kyle1morel marked this conversation as resolved.
Show resolved Hide resolved
return Promise.resolve().then(() =>
knex.schema.alterTable('submission', function (table) {
table.text('contact_preference');
table.text('contact_applicant_relationship');
table.text('is_rental_unit').notNullable().defaultTo(RENTAL_STATUS_LIST.UNSURE);
table.text('project_description');
})
);
}

export async function down(knex: Knex): Promise<void> {
kyle1morel marked this conversation as resolved.
Show resolved Hide resolved
return Promise.resolve().then(() =>
knex.schema.alterTable('submission', function (table) {
table.dropColumn('project_description');
table.dropColumn('is_rental_unit');
table.dropColumn('contact_applicant_relationship');
table.dropColumn('contact_preference');
})
);
}
8 changes: 8 additions & 0 deletions app/src/db/models/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export default {
activity_id: input.activityId,
assigned_user_id: input.assignedUserId,
project_name: input.projectName,
project_description: input.projectDescription,
submitted_at: new Date(input.submittedAt ?? Date.now()),
submitted_by: input.submittedBy,
location_pids: input.locationPIDs,
contact_name: input.contactName,
contact_applicant_relationship: input.contactApplicantRelationship,
contact_phone_number: input.contactPhoneNumber,
contact_email: input.contactEmail,
contact_preference: input.contactPreference,
company_name_registered: input.companyNameRegistered,
single_family_units: input.singleFamilyUnits,
is_rental_unit: input.isRentalUnit,
street_address: input.streetAddress,
latitude: input.latitude ? new Decimal(input.latitude) : null,
longitude: input.longitude ? new Decimal(input.longitude) : null,
Expand Down Expand Up @@ -70,11 +74,15 @@ export default {
submittedBy: input.submitted_by,
locationPIDs: input.location_pids,
contactName: input.contact_name,
contactApplicantRelationship: input.contact_applicant_relationship,
contactPhoneNumber: input.contact_phone_number,
contactEmail: input.contact_email,
contactPreference: input.contact_preference,
projectName: input.project_name,
projectDescription: input.project_description,
companyNameRegistered: input.company_name_registered,
singleFamilyUnits: input.single_family_units,
isRentalUnit: input.is_rental_unit,
streetAddress: input.street_address,
latitude: input.latitude ? input.latitude.toNumber() : null,
longitude: input.longitude ? input.longitude.toNumber() : null,
Expand Down
6 changes: 5 additions & 1 deletion app/src/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ model submission {
financially_supported_housing_coop Boolean @default(false)
aai_updated Boolean @default(false)
waiting_on String?
bring_forward_date DateTime? @db.Timestamptz(6)
intake_status String?
application_status String?
guidance Boolean @default(false)
Expand All @@ -168,6 +167,11 @@ model submission {
created_at DateTime? @default(now()) @db.Timestamptz(6)
updated_by String?
updated_at DateTime? @db.Timestamptz(6)
bring_forward_date DateTime? @db.Timestamptz(6)
contact_preference String?
contact_applicant_relationship String?
is_rental_unit String @default("Unsure")
project_description String?
activity activity @relation(fields: [activity_id], references: [activity_id], onDelete: Cascade, map: "submission_activity_id_foreign")
user user? @relation(fields: [assigned_user_id], references: [user_id], onDelete: Cascade, map: "submission_assigned_user_id_foreign")
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/services/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const service = {
contact_email: x.contactEmail,
contact_phone_number: x.contactPhoneNumber,
contact_name: x.contactName,
contact_preference: x.contactPreference,
contact_applicant_relationship: x.contactApplicantRelationship,
financially_supported: x.financiallySupported,
financially_supported_bc: x.financiallySupportedBC,
financially_supported_indigenous: x.financiallySupportedIndigenous,
Expand All @@ -67,8 +69,10 @@ const service = {
longitude: parseFloat(x.longitude as unknown as string),
natural_disaster: x.naturalDisaster,
project_name: x.projectName,
project_description: x.projectDescription,
queue_priority: x.queuePriority,
single_family_units: x.singleFamilyUnits,
is_rental_unit: x.isRentalUnit,
street_address: x.streetAddress,
submitted_at: new Date(x.submittedAt ?? Date.now()),
submitted_by: x.submittedBy as string
Expand Down
6 changes: 5 additions & 1 deletion app/src/types/ChefsSubmissionExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export type ChefsSubmissionExport = {
submissionId: string;
confirmationId: string;
contactEmail: string;
contactPreference: string;
projectName: string;
projectDescription: string;
contactPhoneNumber: string;
contactFirstName: string;
contactLastName: string;
contactApplicantRelationship: string;
financiallySupported: boolean;
intakeStatus: string;
isBCHousingSupported: boolean;
Expand All @@ -30,12 +34,12 @@ export type ChefsSubmissionExport = {
latitude: number;
longitude: number;
naturalDisasterInd: boolean;
projectName: string;
companyNameRegistered: string;
queuePriority: string;
singleFamilyUnits: string;
multiFamilyUnits: string;
multiFamilyUnits1: string;
isRentalUnit: string;
streetAddress: string;
guidance: boolean;
statusRequest: boolean;
Expand Down
4 changes: 4 additions & 0 deletions app/src/types/Submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export type Submission = {
locationPIDs: string | null;
companyNameRegistered: string | null;
contactName: string | null;
contactApplicantRelationship: string | null;
contactPhoneNumber: string | null;
contactEmail: string | null;
contactPreference: string | null;
projectName: string | null;
projectDescription: string | null;
singleFamilyUnits: string | null;
isRentalUnit: string;
streetAddress: string | null;
latitude: number | null;
longitude: number | null;
Expand Down
7 changes: 6 additions & 1 deletion app/src/validators/submission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Joi from 'joi';

import { RENTAL_STATUS_LIST } from '../components/constants';
import { activityId, emailJoi, uuidv4 } from './common';
import { validate } from '../middleware/validation';

Expand All @@ -23,15 +24,19 @@ const schema = {
activityId: activityId,
applicationStatus: Joi.string().max(255).required(),
assignedUserId: uuidv4.required(),
projectName: Joi.string().min(0).max(255).allow(null),
submittedAt: Joi.date().required(),
submittedBy: Joi.string().max(255).allow(null),
locationPIDs: Joi.string().min(0).max(255).allow(null),
contactName: Joi.string().min(0).max(255).allow(null),
contactApplicantRelationship: Joi.string().min(0).max(255).allow(null),
contactPhoneNumber: Joi.string().min(0).max(255).allow(null),
contactEmail: emailJoi,
contactPreference: Joi.string().min(0).max(255).allow(null),
projectName: Joi.string().min(0).max(255).allow(null),
projectDescription: Joi.string().min(0).max(255).allow(null),
companyNameRegistered: Joi.string().min(0).max(255).allow(null),
singleFamilyUnits: Joi.string().min(0).max(255).allow(null),
isRentalUnit: Joi.string().valid(...Object.values(RENTAL_STATUS_LIST)),
streetAddress: Joi.string().min(0).max(255).allow(null),
latitude: Joi.number().max(255).allow(null),
longitude: Joi.number().max(255).allow(null),
Expand Down
19 changes: 19 additions & 0 deletions app/tests/unit/controllers/submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const FORM_EXPORT_1 = {
contactPhoneNumber: '1234567890',
contactFirstName: 'ABC',
contactLastName: 'DEF',
contactPreference: 'phoneCall',
contactApplicantRelationship: 'Agent',
financiallySupported: true,
intakeStatus: 'IN PROGRESS',
isBCHousingSupported: true,
Expand All @@ -67,6 +69,7 @@ const FORM_EXPORT_1 = {
singleFamilyUnits: '1-49',
multiFamilyUnits: '',
multiFamilyUnits1: '',
isRentalUnit: 'unsureunsure',
streetAddress: '123 Some Street',
guidance: true,
statusRequest: true,
Expand Down Expand Up @@ -96,6 +99,9 @@ const FORM_EXPORT_2 = {
contactPhoneNumber: '1114448888',
contactFirstName: 'Joe',
contactLastName: 'Smith',
contactPreference: 'Email',
contactApplicantRelationship: 'Agent',

financiallySupported: true,
intakeStatus: 'IN PROGRESS',
isBCHousingSupported: true,
Expand All @@ -107,11 +113,13 @@ const FORM_EXPORT_2 = {
longitude: 178,
naturalDisasterInd: true,
projectName: 'BIG',
projectDescription: 'some project description here',
companyNameRegistered: 'BIGBUILD',
queuePriority: '3',
singleFamilyUnits: '>500',
multiFamilyUnits: '',
multiFamilyUnits1: '',
isRentalUnit: 'yes',
streetAddress: '112 Other Road',
guidance: true,
statusRequest: true,
Expand All @@ -136,6 +144,8 @@ const FORM_SUBMISSION_1: Partial<Submission & { activityId: string; formId: stri
contactEmail: '[email protected]',
contactPhoneNumber: '1234567890',
contactName: 'ABC DEF',
contactPreference: 'Phone Call',
contactApplicantRelationship: 'Agent',
financiallySupported: true,
financiallySupportedBC: true,
financiallySupportedIndigenous: true,
Expand All @@ -149,6 +159,7 @@ const FORM_SUBMISSION_1: Partial<Submission & { activityId: string; formId: stri
projectName: 'PROJ',
queuePriority: 3,
singleFamilyUnits: '1-49',
isRentalUnit: 'Unsure',
streetAddress: '123 Some Street',
submittedAt: FORM_EXPORT_1.form.createdAt,
submittedBy: 'USERABC',
Expand All @@ -165,6 +176,8 @@ const FORM_SUBMISSION_2: Partial<Submission & { activityId: string; formId: stri
contactEmail: '[email protected]',
contactPhoneNumber: '1114448888',
contactName: 'Joe Smith',
contactPreference: 'Email',
contactApplicantRelationship: 'Agent',
financiallySupported: true,
financiallySupportedBC: true,
financiallySupportedIndigenous: true,
Expand All @@ -176,8 +189,10 @@ const FORM_SUBMISSION_2: Partial<Submission & { activityId: string; formId: stri
longitude: 178,
naturalDisaster: true,
projectName: 'BIG',
projectDescription: 'some project description here',
queuePriority: 3,
singleFamilyUnits: '>500',
isRentalUnit: 'Yes',
streetAddress: '112 Other Road',
submittedAt: FORM_EXPORT_2.form.createdAt,
submittedBy: 'USERABC',
Expand Down Expand Up @@ -213,8 +228,12 @@ const SUBMISSION_1 = {
contactName: null,
contactPhoneNumber: null,
contactEmail: null,
contactPreference: null,
contactApplicantRelationship: null,
projectName: null,
projectDescription: null,
singleFamilyUnits: null,
isRentalUnit: 'Unsure',
streetAddress: null,
latitude: null,
longitude: null,
Expand Down
Loading
Loading