Skip to content

Commit

Permalink
Merge branch 'dev' into BHBC-620_2
Browse files Browse the repository at this point in the history
  • Loading branch information
anissa-agahchen authored Mar 22, 2021
2 parents 8bf7cd9 + f069c1e commit ca0d7e3
Show file tree
Hide file tree
Showing 32 changed files with 456 additions and 312 deletions.
4 changes: 2 additions & 2 deletions api/src/paths/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ GET.apiDoc = {
id: {
type: 'number'
},
iucn_id: {
iucn1_id: {
type: 'number'
},
name: {
Expand All @@ -195,7 +195,7 @@ GET.apiDoc = {
id: {
type: 'number'
},
iucn1_id: {
iucn2_id: {
type: 'number'
},
name: {
Expand Down
4 changes: 2 additions & 2 deletions api/src/paths/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ export const insertPermitNumber = async (
};

export const insertClassificationDetail = async (
iucn_id: number,
iucn3_id: number,
project_id: number,
connection: IDBConnection
): Promise<number> => {
const sqlStatement = postProjectIUCNSQL(iucn_id, project_id);
const sqlStatement = postProjectIUCNSQL(iucn3_id, project_id);

if (!sqlStatement) {
throw new CustomError(400, 'Failed to build SQL statement');
Expand Down
4 changes: 2 additions & 2 deletions api/src/queries/code-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export const getIUCNConservationActionLevel1ClassificationSQL = (): SQLStatement
* @returns {SQLStatement} sql query object
*/
export const getIUCNConservationActionLevel2SubclassificationSQL = (): SQLStatement =>
SQL`SELECT id, iucn_id, name from iucn_conservation_action_level_2_subclassification;`;
SQL`SELECT id, iucn1_id, name from iucn_conservation_action_level_2_subclassification;`;

/**
* SQL query to fetch IUCN conservation action level 3 sub-classification codes.
*
* @returns {SQLStatement} sql query object
*/
export const getIUCNConservationActionLevel3SubclassificationSQL = (): SQLStatement =>
SQL`SELECT id, iucn1_id, name from iucn_conservation_action_level_3_subclassification;`;
SQL`SELECT id, iucn2_id, name from iucn_conservation_action_level_3_subclassification;`;
22 changes: 11 additions & 11 deletions api/src/queries/project-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,19 +691,19 @@ export const getIUCNActionClassificationByProjectSQL = (projectId: number): SQLS
ical2s.name as subClassification1,
ical3s.name as subClassification2
FROM
project_iucn_action_classificaton as piac
project_iucn_action_classification as piac
LEFT OUTER JOIN
iucn_conservation_action_level_3_subclassification as ical3s
ON
piac.iucn2_id = ical3s.id
piac.iucn3_id = ical3s.id
LEFT OUTER JOIN
iucn_conservation_action_level_2_subclassification as ical2s
ON
ical3s.iucn1_id = ical2s.id
ical3s.iucn2_id = ical2s.id
LEFT OUTER JOIN
iucn_conservation_action_level_1_classification as ical1c
ON
ical2s.iucn_id = ical1c.id
ical2s.iucn1_id = ical1c.id
WHERE
piac.p_id = ${projectId}
GROUP BY
Expand Down Expand Up @@ -777,28 +777,28 @@ export const getFundingSourceByProjectSQL = (projectId: number): SQLStatement |
/**
* SQL query to insert a project IUCN row.
*
* @param iucn_id
* @param iucn3_id
* @param project_id
* @returns {SQLStatement} sql query object
*/
export const postProjectIUCNSQL = (iucn_id: number, project_id: number): SQLStatement | null => {
export const postProjectIUCNSQL = (iucn3_id: number, project_id: number): SQLStatement | null => {
defaultLog.debug({
label: 'postProjectIUCNSQL',
message: 'params',
iucn_id,
iucn3_id,
project_id
});

if (!iucn_id || !project_id) {
if (!iucn3_id || !project_id) {
return null;
}

const sqlStatement: SQLStatement = SQL`
INSERT INTO project_iucn_action_classificaton (
iucn2_id,
INSERT INTO project_iucn_action_classification (
iucn3_id,
p_id
) VALUES (
${iucn_id},
${iucn3_id},
${project_id}
)
RETURNING
Expand Down
4 changes: 2 additions & 2 deletions app/src/features/projects/CreateProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,12 @@ const CreateProjectPage: React.FC = () => {
}
subClassifications1={
codes?.iucn_conservation_action_level_2_subclassification?.map((item) => {
return { value: item.id, iucn_id: item.iucn_id, label: item.name };
return { value: item.id, iucn1_id: item.iucn1_id, label: item.name };
}) || []
}
subClassifications2={
codes?.iucn_conservation_action_level_3_subclassification?.map((item) => {
return { value: item.id, iucn1_id: item.iucn1_id, label: item.name };
return { value: item.id, iucn2_id: item.iucn2_id, label: item.name };
}) || []
}
/>
Expand Down
8 changes: 4 additions & 4 deletions app/src/features/projects/components/ProjectIUCNForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ const classifications: IMultiAutocompleteFieldOption[] = [
const subClassifications1: IIUCNSubClassification1Option[] = [
{
value: 3,
iucn_id: 1,
iucn1_id: 1,
label: 'A Sub-class 1'
},
{
value: 4,
iucn_id: 2,
iucn1_id: 2,
label: 'A Sub-class 1 again'
}
];

const subClassifications2: IIUCNSubClassification2Option[] = [
{
value: 5,
iucn1_id: 3,
iucn2_id: 3,
label: 'A Sub-class 2'
},
{
value: 6,
iucn1_id: 4,
iucn2_id: 4,
label: 'A Sub-class 2 again'
}
];
Expand Down
8 changes: 4 additions & 4 deletions app/src/features/projects/components/ProjectIUCNForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export const ProjectIUCNFormInitialValues: IProjectIUCNForm = {
};

export interface IIUCNSubClassification1Option extends IMultiAutocompleteFieldOption {
iucn_id: number;
iucn1_id: number;
}

export interface IIUCNSubClassification2Option extends IMultiAutocompleteFieldOption {
iucn1_id: number;
iucn2_id: number;
}

export const ProjectIUCNFormYupSchema = yup.object().shape({
Expand Down Expand Up @@ -141,7 +141,7 @@ const ProjectIUCNForm: React.FC<IProjectIUCNFormProps> = (props) => {
inputProps={{ 'aria-label': 'subClassification1' }}>
{props.subClassifications1
// Only show the sub-classification 1 categories whose iucn_id matches the classification id
.filter((item: any) => item.iucn_id === classificationDetail.classification)
.filter((item: any) => item.iucn1_id === classificationDetail.classification)
.map((item: any) => (
<MenuItem key={item.value} value={item.value}>
{item.label}
Expand All @@ -166,7 +166,7 @@ const ProjectIUCNForm: React.FC<IProjectIUCNFormProps> = (props) => {
inputProps={{ 'aria-label': 'subClassification2' }}>
{props.subClassifications2
// Only show the sub-classification 2 categories whose iucn1_id matches the sub-classification 1 iucn_id
.filter((item: any) => item.iucn1_id === classificationDetail.subClassification1)
.filter((item: any) => item.iucn2_id === classificationDetail.subClassification1)
.map((item: any) => (
<MenuItem key={item.value} value={item.value}>
{item.label}
Expand Down
4 changes: 2 additions & 2 deletions app/src/interfaces/useBioHubApi-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,6 @@ export interface IGetAllCodesResponse {
region: ICodeSet;
species: ICodeSet;
iucn_conservation_action_level_1_classification: ICodeSet;
iucn_conservation_action_level_2_subclassification: ICodeSet<{ id: number; iucn_id: number; name: string }>;
iucn_conservation_action_level_3_subclassification: ICodeSet<{ id: number; iucn1_id: number; name: string }>;
iucn_conservation_action_level_2_subclassification: ICodeSet<{ id: number; iucn1_id: number; name: string }>;
iucn_conservation_action_level_3_subclassification: ICodeSet<{ id: number; iucn2_id: number; name: string }>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ const DB_USER_API_PASS = process.env.DB_USER_API_PASS;
const DB_USER_API = process.env.DB_USER_API;

/**
* Apply biohub release 0.7 changes.
* Apply biohub release changes.
*
* @export
* @param {Knex} knex
* @return {*} {Promise<void>}
*/
export async function up(knex: Knex): Promise<void> {
const create_spatial_extensions = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'create_spatial_extensions.psql')
path.join(__dirname, 'release.0.8', 'create_spatial_extensions.psql')
);
const biohub_0_7 = fs.readFileSync(path.join(__dirname, 'release.0.7', 'biohub.0.7.sql'));
const biohub_ddl = fs.readFileSync(path.join(__dirname, 'release.0.8', 'biohub.sql'));
const populate_user_identity_source = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'populate_user_identity_source.sql')
path.join(__dirname, 'release.0.8', 'populate_user_identity_source.sql')
);
const api_set_context = fs.readFileSync(path.join(__dirname, 'release.0.7', 'api_set_context.sql'));
const tr_audit_trigger = fs.readFileSync(path.join(__dirname, 'release.0.7', 'tr_audit_trigger.sql'));
const project_audit_triggers = fs.readFileSync(path.join(__dirname, 'release.0.7', 'project_audit_triggers.sql'));
const api_get_context_user_id = fs.readFileSync(path.join(__dirname, 'release.0.7', 'api_get_context_user_id.sql'));
const tr_journal_trigger = fs.readFileSync(path.join(__dirname, 'release.0.7', 'tr_journal_trigger.sql'));
const project_journal_triggers = fs.readFileSync(path.join(__dirname, 'release.0.7', 'project_journal_triggers.sql'));
const api_set_context = fs.readFileSync(path.join(__dirname, 'release.0.8', 'api_set_context.sql'));
const tr_audit_trigger = fs.readFileSync(path.join(__dirname, 'release.0.8', 'tr_audit_trigger.sql'));
const project_audit_triggers = fs.readFileSync(path.join(__dirname, 'release.0.8', 'project_audit_triggers.sql'));
const api_get_context_user_id = fs.readFileSync(path.join(__dirname, 'release.0.8', 'api_get_context_user_id.sql'));
const tr_journal_trigger = fs.readFileSync(path.join(__dirname, 'release.0.8', 'tr_journal_trigger.sql'));
const project_journal_triggers = fs.readFileSync(path.join(__dirname, 'release.0.8', 'project_journal_triggers.sql'));
const tr_project_funding_source = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'tr_project_funding_source.sql')
path.join(__dirname, 'release.0.8', 'tr_project_funding_source.sql')
);

const populate_first_nations = fs.readFileSync(path.join(__dirname, 'release.0.7', 'populate_first_nations.sql'));
const populate_first_nations = fs.readFileSync(path.join(__dirname, 'release.0.8', 'populate_first_nations.sql'));
const populate_climate_change_initiatives = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'populate_climate_change_initiatives.sql')
path.join(__dirname, 'release.0.8', 'populate_climate_change_initiatives.sql')
);
const populate_management_action_type = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'populate_management_action_type.sql')
path.join(__dirname, 'release.0.8', 'populate_management_action_type.sql')
);
const populate_funding_source = fs.readFileSync(path.join(__dirname, 'release.0.7', 'populate_funding_source.sql'));
const populate_funding_source = fs.readFileSync(path.join(__dirname, 'release.0.8', 'populate_funding_source.sql'));
const populate_investment_action_category = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'populate_investment_action_category.sql')
path.join(__dirname, 'release.0.8', 'populate_investment_action_category.sql')
);
const populate_project_type = fs.readFileSync(path.join(__dirname, 'release.0.7', 'populate_project_type.sql'));
const populate_activity = fs.readFileSync(path.join(__dirname, 'release.0.7', 'populate_activity.sql'));
const populate_project_type = fs.readFileSync(path.join(__dirname, 'release.0.8', 'populate_project_type.sql'));
const populate_activity = fs.readFileSync(path.join(__dirname, 'release.0.8', 'populate_activity.sql'));
const populate_icun_classifications = fs.readFileSync(
path.join(__dirname, 'release.0.7', 'populate_icun_classifications.sql')
path.join(__dirname, 'release.0.8', 'populate_icun_classifications.sql')
);

const project_dapi_views = fs.readFileSync(path.join(__dirname, 'release.0.7', 'project_dapi_views.sql'));
const project_dapi_views = fs.readFileSync(path.join(__dirname, 'release.0.8', 'project_dapi_views.sql'));

await knex.raw(`
-- set up spatial extensions
Expand All @@ -57,7 +57,7 @@ export async function up(knex: Knex): Promise<void> {
create schema if not exists biohub;
set search_path = biohub, public;
${biohub_0_7}
${biohub_ddl}
${populate_user_identity_source}
${api_set_context}
${tr_audit_trigger}
Expand Down
41 changes: 0 additions & 41 deletions database/src/migrations/release.0.7/biohub_admin.0.3.sql

This file was deleted.

Loading

0 comments on commit ca0d7e3

Please sign in to comment.