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

Add permit type field to permit section (create, view, and edit) #251

Merged
merged 4 commits into from
Apr 22, 2021
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
4 changes: 4 additions & 0 deletions api/src/models/project-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ describe('PostPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
}
]
Expand All @@ -337,6 +338,7 @@ describe('PostPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: true
}
]);
Expand All @@ -350,6 +352,7 @@ describe('PostPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'false'
}
]
Expand All @@ -363,6 +366,7 @@ describe('PostPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: false
}
]);
Expand Down
2 changes: 2 additions & 0 deletions api/src/models/project-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class PostCoordinatorData {

export interface IPostPermit {
permit_number: string;
permit_type: string;
sampling_conducted: boolean;
}

Expand All @@ -81,6 +82,7 @@ export class PostPermitData {
obj.permits.map((item: any) => {
return {
permit_number: item.permit_number,
permit_type: item.permit_type,
sampling_conducted: (item.sampling_conducted === 'true' && true) || false
};
})) ||
Expand Down
8 changes: 8 additions & 0 deletions api/src/models/project-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ describe('GetPermitData', () => {
const permits = [
{
number: '1',
type: 'permit type',
sampling_conducted: true
}
];
Expand All @@ -479,6 +480,7 @@ describe('GetPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
}
]);
Expand All @@ -491,6 +493,7 @@ describe('GetPermitData', () => {
const permits = [
{
number: '1',
type: 'permit type',
sampling_conducted: false
}
];
Expand All @@ -503,6 +506,7 @@ describe('GetPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'false'
}
]);
Expand Down Expand Up @@ -558,6 +562,7 @@ describe('PutPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
}
]
Expand All @@ -571,6 +576,7 @@ describe('PutPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: true
}
]);
Expand All @@ -584,6 +590,7 @@ describe('PutPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'false'
}
]
Expand All @@ -597,6 +604,7 @@ describe('PutPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: false
}
]);
Expand Down
4 changes: 4 additions & 0 deletions api/src/models/project-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class PutFundingSource {

export interface IPutPermit {
permit_number: string;
permit_type: string;
sampling_conducted: boolean;
}

Expand All @@ -324,6 +325,7 @@ export class PutPermitData {
obj.permits.map((item: any) => {
return {
permit_number: item.permit_number,
permit_type: item.permit_type,
sampling_conducted: (item.sampling_conducted === 'true' && true) || false
};
})) ||
Expand All @@ -333,6 +335,7 @@ export class PutPermitData {

interface IGetPermit {
permit_number: string;
permit_type: string;
sampling_conducted: string;
}

Expand All @@ -357,6 +360,7 @@ export class GetPermitData {
permitData.map((item: any) => {
return {
permit_number: item.number,
permit_type: item.type,
sampling_conducted: item.sampling_conducted ? 'true' : 'false'
};
})) ||
Expand Down
4 changes: 4 additions & 0 deletions api/src/models/project-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ describe('GetPermitData', () => {
const permits = [
{
number: '1',
type: 'permit type',
sampling_conducted: true
}
];
Expand All @@ -523,6 +524,7 @@ describe('GetPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: true
}
]);
Expand All @@ -535,6 +537,7 @@ describe('GetPermitData', () => {
const permits = [
{
number: '1',
type: 'permit type',
sampling_conducted: false
}
];
Expand All @@ -547,6 +550,7 @@ describe('GetPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: false
}
]);
Expand Down
2 changes: 2 additions & 0 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class GetProjectData {

export interface IGetPermit {
permit_number: string;
permit_type: string;
sampling_conducted: boolean;
}

Expand All @@ -58,6 +59,7 @@ export class GetPermitData {
permitData.map((item: any) => {
return {
permit_number: item.number,
permit_type: item.type,
sampling_conducted: item.sampling_conducted
};
})) ||
Expand Down
11 changes: 9 additions & 2 deletions api/src/paths/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ function createProject(): RequestHandler {
promises.push(
Promise.all(
sanitizedProjectPostData.permit.permits.map((permit: IPostPermit) =>
insertPermitNumber(permit.permit_number, projectId, permit.sampling_conducted, connection)
insertPermitNumber(
permit.permit_number,
permit.permit_type,
projectId,
permit.sampling_conducted,
connection
)
)
)
);
Expand Down Expand Up @@ -360,11 +366,12 @@ export const insertStakeholderPartnership = async (

export const insertPermitNumber = async (
permit_number: string,
permit_type: string,
project_id: number,
sampling_conducted: boolean,
connection: IDBConnection
): Promise<number> => {
const sqlStatement = postProjectPermitSQL(permit_number, project_id, sampling_conducted);
const sqlStatement = postProjectPermitSQL(permit_number, permit_type, project_id, sampling_conducted);

if (!sqlStatement) {
throw new HTTP400('Failed to build SQL insert statement');
Expand Down
2 changes: 1 addition & 1 deletion api/src/paths/project/{projectId}/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export const updateProjectPermitData = async (

const insertPermitPromises =
putPermitData?.permits?.map((permit: IPutPermit) =>
insertPermitNumber(permit.permit_number, projectId, permit.sampling_conducted, connection)
insertPermitNumber(permit.permit_number, permit.permit_type, projectId, permit.sampling_conducted, connection)
) || [];

await Promise.all(insertPermitPromises);
Expand Down
12 changes: 9 additions & 3 deletions api/src/queries/project/project-create-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,27 @@ describe('postProjectClimateChangeInitiativeSQL', () => {
describe('postProjectPermitSQL', () => {
describe('with invalid parameters', () => {
it('returns null when no permit number', () => {
const response = postProjectPermitSQL((null as unknown) as string, 1, true);
const response = postProjectPermitSQL((null as unknown) as string, 'type', 1, true);

expect(response).to.be.null;
});

it('returns null when no permit type', () => {
const response = postProjectPermitSQL('123', (null as unknown) as string, 1, true);

expect(response).to.be.null;
});

it('returns null when no project id', () => {
const response = postProjectPermitSQL('123', (null as unknown) as number, true);
const response = postProjectPermitSQL('123', 'type', (null as unknown) as number, true);

expect(response).to.be.null;
});
});

describe('with valid parameters', () => {
it('returns a SQLStatement when all fields are passed in as expected', () => {
const response = postProjectPermitSQL('123', 123, true);
const response = postProjectPermitSQL('123', 'type', 123, true);

expect(response).to.not.be.null;
expect(response?.values).to.deep.include('123');
Expand Down
6 changes: 5 additions & 1 deletion api/src/queries/project/project-create-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,29 +341,33 @@ export const postProjectIndigenousNationSQL = (indigenousNationId: number, proje
*/
export const postProjectPermitSQL = (
permit_number: string,
permit_type: string,
projectId: number,
sampling_conducted: boolean
): SQLStatement | null => {
defaultLog.debug({
label: 'postProjectPermitSQL',
message: 'params',
permit_number,
permit_type,
sampling_conducted,
projectId
});

if (!permit_number || !projectId) {
if (!permit_number || !permit_type || !projectId) {
return null;
}

const sqlStatement: SQLStatement = SQL`
INSERT INTO project_permit (
p_id,
number,
type,
sampling_conducted
) VALUES (
${projectId},
${permit_number},
${permit_type},
${sampling_conducted}
)
RETURNING
Expand Down
1 change: 1 addition & 0 deletions api/src/queries/project/project-update-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const getPermitsByProjectSQL = (projectId: number): SQLStatement | null =
const sqlStatement = SQL`
SELECT
number,
type,
sampling_conducted
FROM
project_permit
Expand Down
1 change: 1 addition & 0 deletions api/src/queries/project/project-view-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const getProjectPermitsSQL = (projectId: number): SQLStatement | null =>
const sqlStatement = SQL`
SELECT
number,
type,
sampling_conducted
FROM
project_permit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,78 @@ exports[`CreateProjectPage removes the extra project steps if all permits are ma
</div>
<div
class="MuiBox-root MuiBox-root-94"
>
<div
class="MuiFormControl-root"
style="width: 100%;"
>
<label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required"
data-shrink="false"
id="permit_type"
>
Permit Type
<span
aria-hidden="true"
class="MuiFormLabel-asterisk MuiInputLabel-asterisk"
>
 *
</span>
</label>
<div
class="MuiInputBase-root MuiOutlinedInput-root MuiInputBase-formControl"
>
<div
aria-haspopup="listbox"
aria-label="Permit Type"
aria-labelledby="permit_type permits.[0].permit_type"
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input"
id="permits.[0].permit_type"
role="button"
tabindex="0"
>
<span>
</span>
</div>
<input
aria-hidden="true"
class="MuiSelect-nativeInput"
name="permits.[0].permit_type"
required=""
tabindex="-1"
value=""
/>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSelect-icon MuiSelect-iconOutlined"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M7 10l5 5 5-5z"
/>
</svg>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-90 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-92"
>
<span>
Permit Type
</span>
</legend>
</fieldset>
</div>
<p
class="MuiFormHelperText-root MuiFormHelperText-contained Mui-required"
/>
</div>
</div>
<div
class="MuiBox-root MuiBox-root-95"
>
<div
class="MuiFormControl-root"
Expand Down Expand Up @@ -350,7 +422,7 @@ exports[`CreateProjectPage removes the extra project steps if all permits are ma
</div>
</div>
<div
class="MuiBox-root MuiBox-root-95"
class="MuiBox-root MuiBox-root-96"
>
<button
aria-label="remove permit"
Expand Down
Loading