Skip to content

Commit

Permalink
Create initial Permits defined in SHAS intake form
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed Jan 25, 2024
1 parent 2906d69 commit 3aff95d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 9 deletions.
76 changes: 72 additions & 4 deletions app/src/services/chefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import config from 'config';
import { getChefsApiKey, isTruthy } from '../components/utils';
import prisma from '../db/dataConnection';
import { submission } from '../db/models';
import { v4 as uuidv4 } from 'uuid';

import type { AxiosInstance, AxiosRequestConfig } from 'axios';
import type { ChefsSubmissionForm, SubmissionSearchParameters } from '../types';
Expand All @@ -25,6 +26,12 @@ function chefsAxios(formId: string, options: AxiosRequestConfig = {}): AxiosInst
}

const service = {
/**
* @function getSubmission
* Gets a full data export for the requested CHEFS form
* @param {string} [formId] CHEFS form id
* @returns {Promise<object>} The result of running the get operation
*/
getFormExport: async (formId: string) => {
try {
const response = await chefsAxios(formId).get(`forms/${formId}/export`, {
Expand All @@ -36,6 +43,14 @@ const service = {
}
},

/**
* @function getSubmission
* Gets a specific submission from the PCNS database
* The record will be pulled from CHEFS and created if it does not first exist
* @param {string} [formId] CHEFS form id
* @param {string} [formSubmissionId] CHEFS form submission id
* @returns {Promise<object>} The result of running the findUnique operation
*/
getSubmission: async (formId: string, submissionId: string) => {
try {
// Check if record exists in our db
Expand All @@ -59,18 +74,19 @@ const service = {
financiallySupportedHousingCoop: isTruthy(submission.isHousingCooperativeSupported)
};

// get greatest of multiple Units data
// Get greatest of multiple Units data
const unitTypes = [submission.singleFamilyUnits, submission.multiFamilyUnits, submission.multiFamilyUnits1];
const maxUnits = unitTypes.reduce(
(ac, value) => {
// get max integer from value (eg: '1-49' returns 49)
// Get max integer from value (eg: '1-49' returns 49)
const upperRange: number = value ? parseInt(value.toString().replace(/(.*)-/, '').trim()) : 0;
// compare with accumulator
// Compare with accumulator
return upperRange > ac.upperRange ? { value: value, upperRange: upperRange } : ac;
},
{ upperRange: 0 } // initial value
{ upperRange: 0 } // Initial value
).value;

// Create submission
await prisma.submission.create({
data: {
submissionId: response.submission.id,
Expand All @@ -92,6 +108,45 @@ const service = {
submittedBy: response.submission.createdBy
}
});

// Mapping of SHAS intake permit names to PCNS types
const shasPermitMapping = new Map<string, string>([
['archaeologySiteAlterationPermit', 'Alteration'],
['archaeologyHeritageInspectionPermit', 'Inspection'],
['archaeologyInvestigationPermit', 'Investigation'],
['forestsPrivateTimberMark', 'Private Timber Mark'],
['forestsOccupantLicenceToCut', 'Occupant Licence To Cut'],
['landsCrownLandTenure', 'Commercial General'],
['roadwaysHighwayUsePermit', 'Highway Use Permit'],
['siteRemediation', 'Contaminated Sites Remediation'],
['subdividingLandOutsideAMunicipality', 'Rural Subdivision'],
['waterChangeApprovalForWorkInAndAboutAStream', 'Change Approval for Work in and About a Stream'],
['waterLicence', 'Water Licence'],
['waterNotificationOfAuthorizedChangesInAndAboutAStream', 'Notification'],
['waterShortTermUseApproval', 'Use Approval'],
['waterRiparianAreasProtection', 'New'],
['waterRiparianAreasProtection', 'New']
]);

// Create Permits defined in SHAS intake form
const permitTypes = await prisma.permit_type.findMany();
const c = submission.permitGrid
.map((x: { previousPermitType: string; previousTrackingNumber2: string }) => {
const permit = permitTypes.find((y) => y.type === shasPermitMapping.get(x.previousPermitType));
if (permit) {
return {
permitId: uuidv4(),
permitTypeId: permit.permitTypeId,
submissionId: response.submission.id,
trackingId: x.previousTrackingNumber2
};
}
})
.filter((x: unknown) => !!x);

await prisma.permit.createMany({
data: c
});
}

const result = await prisma.submission.findUnique({
Expand All @@ -109,6 +164,13 @@ const service = {
}
},

/**
* @function getSubmissionStatus
* Gets a specific submission status from CHEFS
* @param {string} [formId] CHEFS form id
* @param {string} [formSubmissionId] CHEFS form submission id
* @returns {Promise<object>} The result of running the get operation
*/
getSubmissionStatus: async (formId: string, formSubmissionId: string) => {
try {
return (await chefsAxios(formId).get(`submissions/${formSubmissionId}/status`)).data;
Expand Down Expand Up @@ -140,6 +202,12 @@ const service = {
return result.map((x) => submission.fromPrismaModel(x));
},

/**
* @function updateSubmission
* Updates a specific submission
* @param {ChefsSubmissionForm} [params.data] Submission to update
* @returns {Promise<object>}
*/
updateSubmission: async (data: ChefsSubmissionForm) => {
try {
await prisma.submission.update({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/form/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = {
placeholder?: string;
disabled?: boolean;
options: Array<any> | undefined;
optionLabel?: string;
optionLabel?: string | ((data: any) => string);
bold?: boolean;
loading?: boolean;
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/permit/PermitModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { object, string } from 'yup';
import { Calendar, Dropdown, InputText } from '@/components/form';
import { Button, Dialog } from '@/lib/primevue';
import { permitService } from '@/services';
import { PermitAuthorizationStatus, PermitStatus } from '@/utils/constants';
import { PermitAuthorizationStatus, PermitNeeded, PermitStatus } from '@/utils/constants';
import { onMounted } from 'vue';
import type { Ref } from 'vue';
Expand Down Expand Up @@ -118,7 +118,7 @@ onMounted(async () => {
name="permitType"
label="Permit"
:options="permitTypes"
option-label="name"
:option-label="(e) => `${e.businessDomain}: ${e.name}`"
:loading="permitTypes === undefined"
autofocus
@on-change="(e: DropdownChangeEvent) => onPermitTypeChanged(e, setValues)"
Expand All @@ -127,7 +127,7 @@ onMounted(async () => {
class="col-12 lg:col-6"
name="needed"
label="Needed"
:options="['Yes', 'Under investigation', 'No']"
:options="PermitNeeded"
/>
<Dropdown
class="col-12 lg:col-6"
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { APPLICATION_STATUS_LIST, INTAKE_STATUS_LIST, PERMIT_STATUS, PERMIT_AUTHORIZATION_STATUS } from '@/utils/enums';
import {
APPLICATION_STATUS_LIST,
INTAKE_STATUS_LIST,
PERMIT_STATUS,
PERMIT_NEEDED,
PERMIT_AUTHORIZATION_STATUS
} from '@/utils/enums';

/**
* Default string delimiter
Expand Down Expand Up @@ -73,6 +79,8 @@ export const PermitAuthorizationStatus = [
PERMIT_AUTHORIZATION_STATUS.NONE
];

export const PermitNeeded = [PERMIT_NEEDED.YES, PERMIT_NEEDED.UNDER_INVESTIGATION, PERMIT_NEEDED.NO];

export const PermitStatus = [PERMIT_STATUS.NEW, PERMIT_STATUS.APPLIED, PERMIT_STATUS.COMPLETED];

/**
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export const enum PERMIT_AUTHORIZATION_STATUS {
NONE = 'None'
}

export const enum PERMIT_NEEDED {
YES = 'Yes',
UNDER_INVESTIGATION = 'Under investigation',
NO = 'No'
}

export const enum PERMIT_STATUS {
NEW = 'New',
APPLIED = 'Applied',
Expand Down

0 comments on commit 3aff95d

Please sign in to comment.