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

Bhbc 841 #108

Merged
merged 29 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1c142c1
database release.0.7
Mar 10, 2021
cd9fc19
database release.0.7
Mar 10, 2021
5ce58d2
fixed wrong source
Mar 10, 2021
e81c8e6
Merge branch 'dev' into bhbc-841
cgarrettjones Mar 10, 2021
10c4c3d
fix linting issues
Mar 10, 2021
4881c20
Merge branch 'bhbc-841' of https://github.com/bcgov/biohubbc into bhb…
Mar 10, 2021
4463f18
adjusted geometry type to allow multiple shapes
Mar 10, 2021
fdfbd13
"swapping in boolean datatype"
Mar 11, 2021
a78812d
Merge branch 'dev' into bhbc-841
cgarrettjones Mar 11, 2021
42d4102
database release.0.7
Mar 10, 2021
0307ead
database release.0.7
Mar 10, 2021
a722540
fixed wrong source
Mar 10, 2021
5755826
fix linting issues
Mar 10, 2021
d058225
adjusted geometry type to allow multiple shapes
Mar 10, 2021
3216ece
initial API changes to accomodate save project
anissa-agahchen Mar 11, 2021
dfd3a10
"swapping in boolean datatype"
Mar 11, 2021
e74a946
app is working with new database models
anissa-agahchen Mar 11, 2021
bf08f07
Merge branch 'testCharlie841' into bhbc-841
anissa-agahchen Mar 11, 2021
92a80cd
fixed iucn and project permit issues in create project
anissa-agahchen Mar 11, 2021
efda025
formatting and lint
anissa-agahchen Mar 11, 2021
f89dab0
updated tests
anissa-agahchen Mar 11, 2021
8dabfb5
Update database/src/migrations/release.0.7/create_spatial_extensions.…
sdevalapurkar Mar 11, 2021
f87ce86
Update database/src/migrations/release.0.7/populate_activity.sql
sdevalapurkar Mar 11, 2021
2abf91d
Update database/src/migrations/release.0.7/populate_climate_change_in…
sdevalapurkar Mar 11, 2021
847be3c
Update database/src/migrations/release.0.7/populate_user_identity_sou…
sdevalapurkar Mar 11, 2021
4a982f6
Update database/src/migrations/release.0.7/populate_project_type.sql
sdevalapurkar Mar 11, 2021
b77a260
add missing tests
sdevalapurkar Mar 11, 2021
dfa2667
Update api/package.json
sdevalapurkar Mar 11, 2021
b00f597
Update api/src/queries/project-queries.ts
sdevalapurkar Mar 11, 2021
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
33 changes: 9 additions & 24 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@typescript-eslint/parser": "~3.7.1",
"chai": "~4.2.0",
"del": "~6.0.0",
"eslint": "~7.5.0",
"eslint": "^7.5.0",
sdevalapurkar marked this conversation as resolved.
Show resolved Hide resolved
sdevalapurkar marked this conversation as resolved.
Show resolved Hide resolved
"eslint-config-prettier": "~6.11.0",
"eslint-plugin-prettier": "~3.1.4",
"gulp": "~4.0.2",
Expand Down
11 changes: 0 additions & 11 deletions api/src/models/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('PostProjectData', () => {
expect(projectPostData.name).to.equal(null);
});

it('sets scientific_collection_permit_number', function () {
expect(projectPostData.scientific_collection_permit_number).to.equal(null);
});

it('sets management_recovery_action', function () {
expect(projectPostData.management_recovery_action).to.equal(null);
});
Expand All @@ -40,7 +36,6 @@ describe('PostProjectData', () => {

const obj = {
project_name: 'name_test_data',
scientific_collection_permit_number: 'scientific_collection_permit_number_test_data',
management_recovery_action: 'management_recovery_action_test_data',
start_date: 'start_date_test_data',
end_date: 'end_date_test_data',
Expand All @@ -55,12 +50,6 @@ describe('PostProjectData', () => {
expect(projectPostData.name).to.equal('name_test_data');
});

it('sets scientific_collection_permit_number', function () {
expect(projectPostData.scientific_collection_permit_number).to.equal(
'scientific_collection_permit_number_test_data'
);
});

it('sets management_recovery_action', function () {
expect(projectPostData.management_recovery_action).to.equal('management_recovery_action_test_data');
});
Expand Down
12 changes: 5 additions & 7 deletions api/src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const defaultLog = getLogger('models/project');
*/
export interface IProject {
id: number;
pt_id: number;
name: string;
objectives: string;
scientific_collection_permit_number: string;
management_recovery_action: string;
location_description: string;
start_date: string;
Expand Down Expand Up @@ -52,7 +52,7 @@ export interface IProjectFundingAgency {
}

/**
* An interface representing the funding angency table.
* An interface representing the funding agency table.
*
* @export
* @interface IFundingAgency
Expand Down Expand Up @@ -171,7 +171,7 @@ export class PostCoordinatorData {
}

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

Expand Down Expand Up @@ -207,8 +207,7 @@ export class PostPermitData {
*/
export class PostProjectData {
name: string;
type: string;
scientific_collection_permit_number: string;
type: number;
management_recovery_action: string;
start_date: string;
end_date: string;
Expand All @@ -218,8 +217,7 @@ export class PostProjectData {
defaultLog.debug({ label: 'PostProjectData', message: 'params', obj });

this.name = obj?.project_name || null;
this.type = obj?.type || null;
this.scientific_collection_permit_number = obj?.scientific_collection_permit_number || null;
this.type = obj?.project_type;
this.management_recovery_action = obj?.management_recovery_action || null;
this.start_date = obj?.start_date || null;
this.end_date = obj?.end_date || null;
Expand Down
5 changes: 1 addition & 4 deletions api/src/openapi/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const projectPostBody = {
type: 'object',
properties: {
permit_number: {
type: 'number'
type: 'string'
},
sampling_conducted: {
type: 'string'
Expand All @@ -60,9 +60,6 @@ export const projectPostBody = {
objectives: {
type: 'string'
},
scientific_collection_permit_number: {
type: 'string'
},
management_recovery_action: {
type: 'string'
},
Expand Down
42 changes: 40 additions & 2 deletions api/src/paths/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { WRITE_ROLES } from '../constants/roles';
import { getDBConnection, IDBConnection } from '../database/db';
import { PostFundingSource, PostProjectObject } from '../models/project';
import { PostFundingSource, PostProjectObject, IPostPermit } from '../models/project';
import { projectPostBody, projectResponseBody } from '../openapi/schemas/project';
import {
postAncillarySpeciesSQL,
Expand All @@ -11,7 +11,8 @@ import {
postProjectIndigenousNationSQL,
postProjectRegionSQL,
postProjectSQL,
postProjectStakeholderPartnershipSQL
postProjectStakeholderPartnershipSQL,
postProjectPermitSQL
} from '../queries/project-queries';
import { getLogger } from '../utils/logger';
import { logRequest } from '../utils/path-utils';
Expand Down Expand Up @@ -84,6 +85,7 @@ function createProject(): RequestHandler {
try {
const postProjectSQLStatement = postProjectSQL({
...sanitizedProjectPostData.project,
...sanitizedProjectPostData.permit,
...sanitizedProjectPostData.location,
...sanitizedProjectPostData.objectives,
...sanitizedProjectPostData.coordinator
Expand Down Expand Up @@ -159,6 +161,13 @@ function createProject(): RequestHandler {
)
);

// Handle project permits
await Promise.all(
sanitizedProjectPostData.permit.permits.map((permit: IPostPermit) =>
insertPermitNumber(permit.permit_number, projectId, permit.sampling_conducted, connection)
)
);

await connection.commit();
} catch (error) {
await connection.rollback();
Expand Down Expand Up @@ -338,3 +347,32 @@ export const insertStakeholderPartnership = async (

return result.id;
};

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

if (!sqlStatement) {
throw {
status: 400,
message: 'Failed to build SQL statement'
};
}

const response = await connection.query(sqlStatement.text, sqlStatement.values);

const result = (response && response.rows && response.rows[0]) || null;

if (!result || !result.id) {
throw {
status: 400,
message: 'Failed to insert into project_permit table'
};
}

return result.id;
};
30 changes: 24 additions & 6 deletions api/src/queries/project-queries.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import { PostProjectData, PostLocationData, PostCoordinatorData, PostObjectivesData } from '../models/project';
import {
PostProjectData,
PostLocationData,
PostCoordinatorData,
PostObjectivesData,
PostPermitData
} from '../models/project';
import { getProjectSQL, getProjectsSQL, postProjectSQL, postProjectRegionSQL } from './project-queries';

describe('postProjectSQL', () => {
describe('Null project param provided', () => {
it('returns null', () => {
// force the function to accept a null value
const response = postProjectSQL(
(null as unknown) as PostProjectData & PostLocationData & PostCoordinatorData & PostObjectivesData
(null as unknown) as PostProjectData &
PostLocationData &
PostCoordinatorData &
PostObjectivesData &
PostPermitData
);

expect(response).to.be.null;
Expand All @@ -19,7 +29,6 @@ describe('postProjectSQL', () => {
const projectData = {
name: 'name_test_data',
objectives: 'objectives_test_data',
scientific_collection_permit_number: 'scientific_collection_permit_number_test_data',
management_recovery_action: 'management_recovery_action_test_data',
start_date: 'start_date_test_data',
end_date: 'end_date_test_data',
Expand All @@ -45,17 +54,24 @@ describe('postProjectSQL', () => {
caveats: 'a caveat maybe'
};

const permitData = {
permit_number: '123',
sampling_conducted: true
};

const postProjectData = new PostProjectData(projectData);
const postCoordinatorData = new PostCoordinatorData(coordinatorData);
const postObjectivesData = new PostObjectivesData(objectivesData);
const postPermitData = new PostPermitData(permitData);

it('returns a SQLStatement', () => {
const postLocationData = new PostLocationData(locationData);
const response = postProjectSQL({
...postProjectData,
...postCoordinatorData,
...postLocationData,
...postObjectivesData
...postObjectivesData,
...postPermitData
});

expect(response).to.not.be.null;
Expand Down Expand Up @@ -92,7 +108,8 @@ describe('postProjectSQL', () => {
...postProjectData,
...postCoordinatorData,
...postLocationData,
...postObjectivesData
...postObjectivesData,
...postPermitData
});

expect(response).to.not.be.null;
Expand Down Expand Up @@ -143,7 +160,8 @@ describe('postProjectSQL', () => {
...postProjectData,
...postCoordinatorData,
...postLocationData,
...postObjectivesData
...postObjectivesData,
...postPermitData
});

expect(response).to.not.be.null;
Expand Down
Loading