Skip to content

Commit

Permalink
Merge pull request #2943 from bcgov/add_ipma_biocontrol_columns
Browse files Browse the repository at this point in the history
Add ipma biocontrol columns
  • Loading branch information
micheal-w-wells authored Oct 24, 2023
2 parents 097ec9b + ad21404 commit ea5e523
Show file tree
Hide file tree
Showing 8 changed files with 2,529 additions and 144 deletions.
137 changes: 95 additions & 42 deletions api/src/paths/v2/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,27 +262,23 @@ function getActivitiesBySearchFilterCriteria(): RequestHandler {
}

function getActivitiesSQLv2(filterObject: any) {
try
{

let sqlStatement: SQLStatement = SQL``;
sqlStatement = initialWithStatement(sqlStatement);
sqlStatement = additionalCTEStatements(sqlStatement, filterObject);
sqlStatement = selectStatement(sqlStatement, filterObject);
sqlStatement = fromStatement(sqlStatement, filterObject);
sqlStatement = whereStatement(sqlStatement, filterObject);
sqlStatement = groupByStatement(sqlStatement, filterObject);
sqlStatement = orderByStatement(sqlStatement, filterObject);
sqlStatement = limitStatement(sqlStatement, filterObject);
sqlStatement = offSetStatement(sqlStatement, filterObject);

defaultLog.debug({ label: 'getActivitiesBySearchFilterCriteria', message: 'sql', body: sqlStatement });
return sqlStatement;
}

catch(e) {
try {
let sqlStatement: SQLStatement = SQL``;
sqlStatement = initialWithStatement(sqlStatement);
sqlStatement = additionalCTEStatements(sqlStatement, filterObject);
sqlStatement = selectStatement(sqlStatement, filterObject);
sqlStatement = fromStatement(sqlStatement, filterObject);
sqlStatement = whereStatement(sqlStatement, filterObject);
sqlStatement = groupByStatement(sqlStatement, filterObject);
sqlStatement = orderByStatement(sqlStatement, filterObject);
sqlStatement = limitStatement(sqlStatement, filterObject);
sqlStatement = offSetStatement(sqlStatement, filterObject);

defaultLog.debug({ label: 'getActivitiesBySearchFilterCriteria', message: 'sql', body: sqlStatement });
return sqlStatement;
} catch (e) {
defaultLog.debug({ label: 'getActivitiesBySearchFilterCriteria', message: 'error', body: e.message });
throw e
throw e;
}
}

Expand Down Expand Up @@ -449,22 +445,30 @@ function whereStatement(sqlStatement: SQLStatement, filterObject: any) {
switch (filter.field) {
case 'activity_id':
where.append(
`and LOWER(activities.activity_id) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
`and LOWER(activities.activity_id) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'short_id':
where.append(
`and LOWER(activities.short_id) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
`and LOWER(activities.short_id) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'activity_type':
where.append(
`and LOWER(activities.activity_type) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
`and LOWER(activities.activity_type) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'activity_subtype':
where.append(
`and LOWER(activities.activity_subtype) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.activity_subtype) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'activity_date':
Expand All @@ -476,82 +480,131 @@ function whereStatement(sqlStatement: SQLStatement, filterObject: any) {
break;
case 'project_code':
where.append(
`and LOWER((activities.activity_payload::json->'form_data'->'activity_data'->'project_code'::text)::text) ${ filter.operator === 'CONTAINS' ? 'like' : 'not like' } LOWER('%${filter.filter}%') `);
`and LOWER((activities.activity_payload::json->'form_data'->'activity_data'->'project_code'::text)::text) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'jurisdiction_display':
where.append(
`and LOWER(activities.jurisdiction_display) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.jurisdiction_display) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'species_positive_full':
where.append(
`and LOWER(activities.species_positive_full) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.species_positive_full) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'species_negative_full':
where.append(
`and LOWER(activities.species_negative_full) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.species_negative_full) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'has_current_positive':
where.append(
`and activities.current_positive_species ${filter.operator === 'CONTAINS' ? 'is not' : 'is'} null `);
`and activities.current_positive_species ${filter.operator === 'CONTAINS' ? 'is not' : 'is'} null `
);
break;
case 'has_current_negative':
where.append( `and activities.current_negative_species ${filter.operator === 'CONTAINS' ? 'is not' : 'is'} null `
where.append(
`and activities.current_negative_species ${filter.operator === 'CONTAINS' ? 'is not' : 'is'} null `
);
break;
case 'current_positive_species':
where.append(
`and LOWER(activities.current_positive_species) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.current_positive_species) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'current_negative_species':
where.append(
`and LOWER(activities.current_negative_species) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.current_negative_species) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'species_treated_full':
where.append(
`and LOWER(activities.species_treated_full) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.species_treated_full) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'species_biocontrol_full':
where.append(
`and LOWER(activities.species_biocontrol_full) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'created_by':
where.append(
`and LOWER(activities.created_by) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `);
`and LOWER(activities.created_by) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'updated_by':
where.append(
`and LOWER(activities.updated_by) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
`and LOWER(activities.updated_by) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'agency':
where.append(
`and LOWER(activities.agency) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `);
`and LOWER(activities.agency) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'regional_invasive_species_organization_areas':
where.append(
`and LOWER(activities.regional_invasive_species_organization_areas) ${ filter.operator === 'CONTAINS' ? 'like' : 'not like' } LOWER('%${filter.filter}%') `
`and LOWER(activities.regional_invasive_species_organization_areas) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'regional_districts':
where.append(
`and LOWER(activities.regional_districts) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.regional_districts) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'invasive_plant_management_areas':
where.append(
`and LOWER(activities.invasive_plant_management_areas) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'biogeoclimatic_zones':
where.append(
`and LOWER(activities.biogeoclimatic_zones) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${ filter.filter }%') `
`and LOWER(activities.biogeoclimatic_zones) ${
filter.operator === 'CONTAINS' ? 'like' : 'not like'
} LOWER('%${filter.filter}%') `
);
break;
case 'elevation':
where.append(
`and LOWER(activities.elevation) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
`and LOWER(activities.elevation) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
case 'batch_id':
where.append(
`and LOWER(activities.batch_id::text) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${filter.filter}%') `
where.append(
`and LOWER(activities.batch_id::text) ${filter.operator === 'CONTAINS' ? 'like' : 'not like'} LOWER('%${
filter.filter
}%') `
);
break;
default:
Expand Down
Loading

0 comments on commit ea5e523

Please sign in to comment.