From af1788abee8f476070425535d44172934a7a992d Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Wed, 3 Apr 2024 10:47:02 -0700 Subject: [PATCH 1/4] Import additional submission fields and edit functionality for them --- app/src/components/utils.ts | 26 +++++++ app/src/controllers/submission.ts | 8 ++- .../20240402000000_002-submission-updates.ts | 23 +++++++ app/src/db/models/submission.ts | 12 +++- app/src/db/prisma/schema.prisma | 4 ++ app/src/services/submission.ts | 4 ++ app/src/types/ChefsSubmissionExport.ts | 6 +- app/src/types/Submission.ts | 4 ++ app/src/validators/submission.ts | 6 +- app/tests/unit/controllers/submission.spec.ts | 17 +++++ .../components/submission/SubmissionForm.vue | 69 ++++++++++++++----- frontend/src/types/Submission.ts | 4 ++ frontend/src/utils/constants.ts | 12 +++- frontend/src/utils/enums.ts | 20 +++++- 14 files changed, 190 insertions(+), 25 deletions(-) create mode 100644 app/src/db/migrations/20240402000000_002-submission-updates.ts diff --git a/app/src/components/utils.ts b/app/src/components/utils.ts index 71166128..588051ff 100644 --- a/app/src/components/utils.ts +++ b/app/src/components/utils.ts @@ -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; + + 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. diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index 9cf47059..6cb2fb87 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -2,7 +2,7 @@ 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 { camelCaseToTitleCase, deDupeUnsure, getCurrentIdentity, isTruthy, toTitleCase } from '../components/utils'; import { submissionService, permitService, userService } from '../services'; import type { NextFunction, Request, Response } from '../interfaces/IExpress'; @@ -111,8 +111,12 @@ 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), @@ -120,9 +124,9 @@ const controller = { latitude: data.latitude, longitude: data.longitude, naturalDisaster: data.naturalDisasterInd, - projectName: data.projectName, queuePriority: parseInt(data.queuePriority), singleFamilyUnits: maxUnits, + isRentalUnit: camelCaseToTitleCase(deDupeUnsure(data.isRentalUnit)), streetAddress: data.streetAddress, submittedAt: data.form.createdAt, submittedBy: data.form.username, diff --git a/app/src/db/migrations/20240402000000_002-submission-updates.ts b/app/src/db/migrations/20240402000000_002-submission-updates.ts new file mode 100644 index 00000000..4c651bc9 --- /dev/null +++ b/app/src/db/migrations/20240402000000_002-submission-updates.ts @@ -0,0 +1,23 @@ +import type { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + return Promise.resolve().then(() => + knex.schema.alterTable('submission', function (table) { + table.text('contact_preference'); + table.text('contact_applicant_relationship'); + table.text('is_rental_unit'); + table.text('project_description'); + }) + ); +} + +export async function down(knex: Knex): Promise { + 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'); + }) + ); +} diff --git a/app/src/db/models/submission.ts b/app/src/db/models/submission.ts index 47294f45..5e9c2c27 100644 --- a/app/src/db/models/submission.ts +++ b/app/src/db/models/submission.ts @@ -16,19 +16,23 @@ type PrismaGraphSubmissionUser = Prisma.submissionGetPayload500', @@ -136,6 +143,8 @@ const FORM_SUBMISSION_1: Partial500', streetAddress: '112 Other Road', @@ -213,8 +226,12 @@ const SUBMISSION_1 = { contactName: null, contactPhoneNumber: null, contactEmail: null, + contactPreference: null, + contactApplicantRelationship: null, projectName: null, + projectDescription: null, singleFamilyUnits: null, + isRentalUnit: null, streetAddress: null, latitude: null, longitude: null, diff --git a/frontend/src/components/submission/SubmissionForm.vue b/frontend/src/components/submission/SubmissionForm.vue index 4d7a760d..45d10534 100644 --- a/frontend/src/components/submission/SubmissionForm.vue +++ b/frontend/src/components/submission/SubmissionForm.vue @@ -15,7 +15,14 @@ import { } from '@/components/form'; import { Button } from '@/lib/primevue'; import { userService } from '@/services'; -import { ApplicationStatusList, IntakeStatusList, QueuePriority, Regex } from '@/utils/constants'; +import { + ApplicationStatusList, + ContactPreferenceList, + IntakeStatusList, + QueuePriority, + Regex, + RentalStatusList +} from '@/utils/constants'; import { INTAKE_STATUS_LIST } from '@/utils/enums'; import { formatJwtUsername } from '@/utils/formatters'; @@ -190,48 +197,55 @@ onBeforeMount(async () => { :disabled="true" /> - + + - { help-text="Optionally provide a number between -114 and -139" :disabled="!props.editable" /> + + + Date: Tue, 2 Apr 2024 14:19:35 -0700 Subject: [PATCH 2/4] Renaming frontend display of certain status types --- app/src/db/models/submission.ts | 4 +--- frontend/src/components/submission/SubmissionForm.vue | 4 ++-- frontend/src/components/submission/SubmissionList.vue | 4 ++-- frontend/src/components/submission/SubmissionStatistics.vue | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/db/models/submission.ts b/app/src/db/models/submission.ts index 5e9c2c27..db014bc3 100644 --- a/app/src/db/models/submission.ts +++ b/app/src/db/models/submission.ts @@ -16,7 +16,7 @@ type PrismaGraphSubmissionUser = Prisma.submissionGetPayload { @@ -417,7 +417,7 @@ onBeforeMount(async () => { diff --git a/frontend/src/components/submission/SubmissionList.vue b/frontend/src/components/submission/SubmissionList.vue index 7e43fe22..2e29d5ed 100644 --- a/frontend/src/components/submission/SubmissionList.vue +++ b/frontend/src/components/submission/SubmissionList.vue @@ -196,7 +196,7 @@ const filters = ref({ @@ -224,7 +224,7 @@ const filters = ref({ diff --git a/frontend/src/components/submission/SubmissionStatistics.vue b/frontend/src/components/submission/SubmissionStatistics.vue index 4fbfcb9c..50d176a0 100644 --- a/frontend/src/components/submission/SubmissionStatistics.vue +++ b/frontend/src/components/submission/SubmissionStatistics.vue @@ -253,7 +253,7 @@ watch( Type: - Enquiry + General Enquiry {{ statistics.inquiry }} {{ getPercentage(statistics.inquiry) }}% @@ -269,7 +269,7 @@ watch( Type: - Emergency + Escalation Request {{ statistics.emergency_assist }} {{ getPercentage(statistics.emergency_assist) }}% From c1dd710721660466a0e5464382f856a7f208a2a2 Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Wed, 3 Apr 2024 16:50:32 -0700 Subject: [PATCH 3/4] Set defaults for isRentalUnit column and associated changes --- app/src/components/constants.ts | 6 ++++++ app/src/controllers/submission.ts | 6 ++++-- .../db/migrations/20240402000000_002-submission-updates.ts | 3 ++- app/src/db/prisma/schema.prisma | 2 +- app/src/types/Submission.ts | 2 +- app/src/validators/submission.ts | 3 ++- app/tests/unit/controllers/submission.spec.ts | 4 +++- frontend/src/components/submission/SubmissionForm.vue | 1 + frontend/src/components/submission/SubmissionList.vue | 6 ++++++ frontend/src/utils/constants.ts | 2 +- 10 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/src/components/constants.ts b/app/src/components/constants.ts index 399d2dd7..47809128 100644 --- a/app/src/components/constants.ts +++ b/app/src/components/constants.ts @@ -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', diff --git a/app/src/controllers/submission.ts b/app/src/controllers/submission.ts index 6cb2fb87..edd03880 100644 --- a/app/src/controllers/submission.ts +++ b/app/src/controllers/submission.ts @@ -1,7 +1,7 @@ import config from 'config'; import { NIL, v4 as uuidv4 } from 'uuid'; -import { APPLICATION_STATUS_LIST } from '../components/constants'; +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'; @@ -126,7 +126,9 @@ const controller = { naturalDisaster: data.naturalDisasterInd, queuePriority: parseInt(data.queuePriority), singleFamilyUnits: maxUnits, - isRentalUnit: camelCaseToTitleCase(deDupeUnsure(data.isRentalUnit)), + isRentalUnit: data.isRentalUnit + ? camelCaseToTitleCase(deDupeUnsure(data.isRentalUnit)) + : RENTAL_STATUS_LIST.UNSURE, streetAddress: data.streetAddress, submittedAt: data.form.createdAt, submittedBy: data.form.username, diff --git a/app/src/db/migrations/20240402000000_002-submission-updates.ts b/app/src/db/migrations/20240402000000_002-submission-updates.ts index 4c651bc9..7ac596d4 100644 --- a/app/src/db/migrations/20240402000000_002-submission-updates.ts +++ b/app/src/db/migrations/20240402000000_002-submission-updates.ts @@ -1,3 +1,4 @@ +import { RENTAL_STATUS_LIST } from '../../components/constants'; import type { Knex } from 'knex'; export async function up(knex: Knex): Promise { @@ -5,7 +6,7 @@ export async function up(knex: Knex): Promise { knex.schema.alterTable('submission', function (table) { table.text('contact_preference'); table.text('contact_applicant_relationship'); - table.text('is_rental_unit'); + table.text('is_rental_unit').notNullable().defaultTo(RENTAL_STATUS_LIST.UNSURE); table.text('project_description'); }) ); diff --git a/app/src/db/prisma/schema.prisma b/app/src/db/prisma/schema.prisma index 671b9110..65898ff8 100644 --- a/app/src/db/prisma/schema.prisma +++ b/app/src/db/prisma/schema.prisma @@ -170,7 +170,7 @@ model submission { updated_at DateTime? @db.Timestamptz(6) contact_preference String? contact_applicant_relationship String? - is_rental_unit 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") diff --git a/app/src/types/Submission.ts b/app/src/types/Submission.ts index 44df42c7..77b350a4 100644 --- a/app/src/types/Submission.ts +++ b/app/src/types/Submission.ts @@ -18,7 +18,7 @@ export type Submission = { projectName: string | null; projectDescription: string | null; singleFamilyUnits: string | null; - isRentalUnit: string | null; + isRentalUnit: string; streetAddress: string | null; latitude: number | null; longitude: number | null; diff --git a/app/src/validators/submission.ts b/app/src/validators/submission.ts index 24e513eb..79c4b773 100644 --- a/app/src/validators/submission.ts +++ b/app/src/validators/submission.ts @@ -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'; @@ -35,7 +36,7 @@ const schema = { 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().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), diff --git a/app/tests/unit/controllers/submission.spec.ts b/app/tests/unit/controllers/submission.spec.ts index 19714caf..3e4bb1af 100644 --- a/app/tests/unit/controllers/submission.spec.ts +++ b/app/tests/unit/controllers/submission.spec.ts @@ -119,6 +119,7 @@ const FORM_EXPORT_2 = { singleFamilyUnits: '>500', multiFamilyUnits: '', multiFamilyUnits1: '', + isRentalUnit: 'yes', streetAddress: '112 Other Road', guidance: true, statusRequest: true, @@ -191,6 +192,7 @@ const FORM_SUBMISSION_2: Partial500', + isRentalUnit: 'Yes', streetAddress: '112 Other Road', submittedAt: FORM_EXPORT_2.form.createdAt, submittedBy: 'USERABC', @@ -231,7 +233,7 @@ const SUBMISSION_1 = { projectName: null, projectDescription: null, singleFamilyUnits: null, - isRentalUnit: null, + isRentalUnit: 'Unsure', streetAddress: null, latitude: null, longitude: null, diff --git a/frontend/src/components/submission/SubmissionForm.vue b/frontend/src/components/submission/SubmissionForm.vue index d438d860..30ba3aff 100644 --- a/frontend/src/components/submission/SubmissionForm.vue +++ b/frontend/src/components/submission/SubmissionForm.vue @@ -60,6 +60,7 @@ const formSchema = object({ contactEmail: string().email().label('Contact Email'), intakeStatus: string().oneOf(IntakeStatusList).label('Intake state'), companyNameRegistered: string().notRequired().label('Company'), + isRentalUnit: string().oneOf(RentalStatusList).label('Rental units'), latitude: number().notRequired().min(48).max(60).label('Latitude'), longitude: number().notRequired().min(-139).max(-114).label('Longitude'), projectName: string().notRequired().label('Project Name'), diff --git a/frontend/src/components/submission/SubmissionList.vue b/frontend/src/components/submission/SubmissionList.vue index 2e29d5ed..83b19285 100644 --- a/frontend/src/components/submission/SubmissionList.vue +++ b/frontend/src/components/submission/SubmissionList.vue @@ -153,6 +153,12 @@ const filters = ref({ :sortable="true" style="min-width: 100px" /> + Date: Fri, 5 Apr 2024 13:21:49 -0700 Subject: [PATCH 4/4] Add default CHES BCC for dev/test environments --- .github/environments/values.dev.yaml | 2 +- .github/environments/values.test.yaml | 2 +- app/src/db/prisma/schema.prisma | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/environments/values.dev.yaml b/.github/environments/values.dev.yaml index e99a1d8b..cc87c801 100644 --- a/.github/environments/values.dev.yaml +++ b/.github/environments/values.dev.yaml @@ -3,7 +3,7 @@ config: enabled: true configMap: FRONTEND_APIPATH: api/v1 - # FRONTEND_CHES_BCC: ~ + FRONTEND_CHES_BCC: NR.CommonServiceShowcase@gov.bc.ca 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 diff --git a/.github/environments/values.test.yaml b/.github/environments/values.test.yaml index 183af524..7895be09 100644 --- a/.github/environments/values.test.yaml +++ b/.github/environments/values.test.yaml @@ -3,7 +3,7 @@ config: enabled: true configMap: FRONTEND_APIPATH: api/v1 - # FRONTEND_CHES_BCC: ~ + FRONTEND_CHES_BCC: NR.CommonServiceShowcase@gov.bc.ca 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 diff --git a/app/src/db/prisma/schema.prisma b/app/src/db/prisma/schema.prisma index 65898ff8..cf8c965e 100644 --- a/app/src/db/prisma/schema.prisma +++ b/app/src/db/prisma/schema.prisma @@ -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) @@ -168,6 +167,7 @@ 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")