Skip to content

Commit

Permalink
SIMSBIOHUB-145: Survey Locations (#1092)
Browse files Browse the repository at this point in the history
* Migration to add new survey locations table

* updated API/ Services to handle multiple 'locations' for a single survey

* updated broken tests

* refactored old code

* Updated front end to pass an array of locations for a survey
  • Loading branch information
al-rosenthal authored Sep 20, 2023
1 parent 429212f commit c62c52b
Show file tree
Hide file tree
Showing 44 changed files with 1,175 additions and 643 deletions.
38 changes: 21 additions & 17 deletions api/src/models/survey-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('PostSurveyObject', () => {
expect(data.purpose_and_methodology).to.equal(null);
});

it('sets location', () => {
expect(data.location).to.equal(null);
it('sets locations', () => {
expect(data.locations).to.eql([]);
});

it('sets agreements', () => {
Expand All @@ -62,7 +62,6 @@ describe('PostSurveyObject', () => {
permit: {},
proprietor: {},
purpose_and_methodology: {},
location: {},
agreements: {}
};

Expand Down Expand Up @@ -90,10 +89,6 @@ describe('PostSurveyObject', () => {
expect(data.purpose_and_methodology).to.instanceOf(PostPurposeAndMethodologyData);
});

it('sets location', () => {
expect(data.location).to.instanceOf(PostLocationData);
});

it('sets agreements', () => {
expect(data.agreements).to.instanceOf(PostAgreementsData);
});
Expand Down Expand Up @@ -393,33 +388,42 @@ describe('PostLocationData', () => {
data = new PostLocationData(null);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal(null);
it('sets name', () => {
expect(data.name).to.equal(null);
});

it('sets description', () => {
expect(data.description).to.equal(null);
});

it('sets geometry', () => {
expect(data.geometry).to.eql([]);
it('sets geojson', () => {
expect(data.geojson).to.eql([]);
});
});

describe('All values provided with first nations id', () => {
let data: PostLocationData;

const obj = {
survey_area_name: 'area_name',
geometry: [{}]
name: 'area name',
description: 'area description',
geojson: [{}]
};

before(() => {
data = new PostLocationData(obj);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal(obj.survey_area_name);
it('sets name', () => {
expect(data.name).to.equal(obj.name);
});

it('sets description', () => {
expect(data.description).to.equal(obj.description);
});

it('sets geometry', () => {
expect(data.geometry).to.eql(obj.geometry);
it('sets geojson', () => {
expect(data.geojson).to.eql(obj.geojson);
});
});
});
Expand Down
14 changes: 8 additions & 6 deletions api/src/models/survey-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PostSurveyObject {
funding_sources: PostFundingSourceData[];
proprietor: PostProprietorData;
purpose_and_methodology: PostPurposeAndMethodologyData;
location: PostLocationData;
locations: PostLocationData[];
agreements: PostAgreementsData;
participants: PostParticipationData[];
partnerships: PostPartnershipsData;
Expand All @@ -25,11 +25,11 @@ export class PostSurveyObject {
this.proprietor = (obj?.proprietor && new PostProprietorData(obj.proprietor)) || null;
this.purpose_and_methodology =
(obj?.purpose_and_methodology && new PostPurposeAndMethodologyData(obj.purpose_and_methodology)) || null;
this.location = (obj?.location && new PostLocationData(obj.location)) || null;
this.agreements = (obj?.agreements && new PostAgreementsData(obj.agreements)) || null;
this.participants =
(obj?.participants?.length && obj.participants.map((p: any) => new PostParticipationData(p))) || [];
this.partnerships = (obj?.partnerships && new PostPartnershipsData(obj.partnerships)) || null;
this.locations = (obj?.locations && obj.locations.map((p: any) => new PostLocationData(p))) || [];
this.site_selection = (obj?.site_selection && new PostSiteSelectionData(obj)) || null;
this.blocks = (obj?.blocks && obj.blocks.map((p: any) => p as PostSurveyBlock)) || [];
}
Expand Down Expand Up @@ -125,12 +125,14 @@ export class PostProprietorData {
}

export class PostLocationData {
survey_area_name: string;
geometry: Feature[];
name: string;
description: string;
geojson: Feature[];

constructor(obj?: any) {
this.survey_area_name = obj?.survey_area_name || null;
this.geometry = (obj?.geometry?.length && obj.geometry) || [];
this.name = obj?.name || null;
this.description = obj?.description || null;
this.geojson = (obj?.geojson?.length && obj.geojson) || [];
}
}

Expand Down
36 changes: 20 additions & 16 deletions api/src/models/survey-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('PutSurveyObject', () => {
});

it('sets location', () => {
expect(data.location).to.equal(null);
expect(data.locations).to.eql([]);
});
});

Expand All @@ -53,7 +53,6 @@ describe('PutSurveyObject', () => {
permit: {},
proprietor: {},
purpose_and_methodology: {},
location: {},
agreements: {}
};

Expand All @@ -80,10 +79,6 @@ describe('PutSurveyObject', () => {
it('sets purpose_and_methodology', () => {
expect(data.purpose_and_methodology).to.instanceOf(PutSurveyPurposeAndMethodologyData);
});

it('sets location', () => {
expect(data.location).to.instanceOf(PutSurveyLocationData);
});
});
});

Expand Down Expand Up @@ -439,12 +434,16 @@ describe('PutLocationData', () => {
data = new PutSurveyLocationData(null);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal(null);
it('sets name', () => {
expect(data.name).to.equal(null);
});

it('sets description', () => {
expect(data.description).to.equal(null);
});

it('sets geometry', () => {
expect(data.geometry).to.eql([]);
it('sets geojson', () => {
expect(data.geojson).to.eql([]);
});

it('sets revision_count', () => {
Expand All @@ -456,21 +455,26 @@ describe('PutLocationData', () => {
let data: PutSurveyLocationData;

const obj = {
survey_area_name: 'area_name',
geometry: [{}],
name: 'area name',
description: 'area description',
geojson: [{}],
revision_count: 0
};

before(() => {
data = new PutSurveyLocationData(obj);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal(obj.survey_area_name);
it('sets name', () => {
expect(data.name).to.equal(obj.name);
});

it('sets description', () => {
expect(data.description).to.equal(obj.description);
});

it('sets geometry', () => {
expect(data.geometry).to.eql(obj.geometry);
it('sets geojson', () => {
expect(data.geojson).to.eql(obj.geojson);
});

it('sets revision_count', () => {
Expand Down
16 changes: 10 additions & 6 deletions api/src/models/survey-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PutSurveyObject {
funding_sources: PutFundingSourceData[];
proprietor: PutSurveyProprietorData;
purpose_and_methodology: PutSurveyPurposeAndMethodologyData;
location: PutSurveyLocationData;
locations: PutSurveyLocationData[];
participants: PutSurveyParticipantsData[];
partnerships: PutPartnershipsData;
site_selection: PutSiteSelectionData;
Expand All @@ -24,9 +24,9 @@ export class PutSurveyObject {
this.proprietor = (obj?.proprietor && new PutSurveyProprietorData(obj.proprietor)) || null;
this.purpose_and_methodology =
(obj?.purpose_and_methodology && new PutSurveyPurposeAndMethodologyData(obj.purpose_and_methodology)) || null;
this.location = (obj?.location && new PutSurveyLocationData(obj.location)) || null;
this.participants =
(obj?.participants?.length && obj.participants.map((p: any) => new PutSurveyParticipantsData(p))) || [];
this.locations = (obj?.locations && obj.locations.map((p: any) => new PutSurveyLocationData(p))) || [];
this.partnerships = (obj?.partnerships && new PutPartnershipsData(obj.partnerships)) || null;
this.site_selection = (obj?.site_selection && new PutSiteSelectionData(obj)) || null;
this.blocks = (obj?.blocks && obj.blocks.map((p: any) => p as PostSurveyBlock)) || [];
Expand Down Expand Up @@ -155,13 +155,17 @@ export class PutSurveyPurposeAndMethodologyData {
}

export class PutSurveyLocationData {
survey_area_name: string;
geometry: Feature[];
survey_location_id: number;
name: string;
description: string;
geojson: Feature[];
revision_count: number;

constructor(obj?: any) {
this.survey_area_name = obj?.survey_area_name || null;
this.geometry = (obj?.geometry?.length && obj.geometry) || [];
this.survey_location_id = obj?.survey_location_id || null;
this.name = obj?.name || null;
this.description = obj?.description || null;
this.geojson = (obj?.geojson?.length && obj.geojson) || [];
this.revision_count = obj?.revision_count ?? null;
}
}
29 changes: 19 additions & 10 deletions api/src/models/survey-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,33 +306,42 @@ describe('GetSurveyLocationData', () => {
data = new GetSurveyLocationData(null);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal('');
it('sets name', () => {
expect(data.name).to.equal(null);
});

it('sets geometry', () => {
expect(data.geometry).to.eql([]);
it('sets description', () => {
expect(data.description).to.equal(null);
});

it('sets geojson', () => {
expect(data.geojson).to.eql([]);
});
});

describe('All values provided with first nations id', () => {
let data: GetSurveyLocationData;

const obj = {
location_name: 'area_name',
geojson: [{}]
name: 'area name',
description: 'area description',
geojson: []
};

before(() => {
data = new GetSurveyLocationData(obj);
});

it('sets survey_area_name', () => {
expect(data.survey_area_name).to.equal(obj.location_name);
it('sets name', () => {
expect(data.name).to.equal(obj.name);
});

it('sets geometry', () => {
expect(data.geometry).to.eql(obj.geojson);
it('sets description', () => {
expect(data.description).to.equal(obj.description);
});

it('sets geojson', () => {
expect(data.geojson).to.eql(obj.geojson);
});
});
});
Expand Down
23 changes: 15 additions & 8 deletions api/src/models/survey-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SurveyMetadataPublish } from '../repositories/history-publish-repositor
import { IPermitModel } from '../repositories/permit-repository';
import { SiteSelectionData } from '../repositories/site-selection-strategy-repository';
import { SurveyBlockRecord } from '../repositories/survey-block-repository';
import { SurveyLocationRecord } from '../repositories/survey-location-repository';
import { SurveyUser } from '../repositories/survey-participation-repository';

export type SurveyObject = {
Expand All @@ -12,7 +13,7 @@ export type SurveyObject = {
funding_sources: GetSurveyFundingSourceData[];
purpose_and_methodology: GetSurveyPurposeAndMethodologyData;
proprietor: GetSurveyProprietorData | null;
location: GetSurveyLocationData;
locations: SurveyLocationRecord[];
participants: SurveyUser[];
partnerships: ISurveyPartnerships;
site_selection: SiteSelectionData;
Expand All @@ -33,22 +34,22 @@ export class GetSurveyData {
end_date: string;
biologist_first_name: string;
biologist_last_name: string;
survey_area_name: string;
geometry: Feature[];
survey_types: number[];
revision_count: number;
geometry: Feature[];

constructor(obj?: any) {
this.id = obj?.survey_id || null;
this.project_id = obj?.project_id || null;
this.uuid = obj?.uuid || null;
this.survey_name = obj?.name || '';
this.start_date = obj?.start_date || null;
this.end_date = obj?.end_date || null;
this.start_date = String(obj?.start_date) || '';
this.end_date = String(obj?.end_date) || '';
this.geometry = (obj?.geojson?.length && obj.geojson) || [];
this.biologist_first_name = obj?.lead_first_name || '';
this.biologist_last_name = obj?.lead_last_name || '';
this.survey_area_name = obj?.location_name || '';
this.survey_types = (obj?.survey_types?.length && obj.survey_types) || [];
this.revision_count = obj?.revision_count || 0;
}
Expand Down Expand Up @@ -169,12 +170,18 @@ export type SurveySupplementaryData = {
};

export class GetSurveyLocationData {
survey_area_name: string;
geometry: Feature[];
survey_spatial_component_id: number;
name: string;
description: string;
geojson: Feature[];
revision_count: number;

constructor(obj?: any) {
this.survey_area_name = obj?.location_name || '';
this.geometry = (obj?.geojson?.length && obj.geojson) || [];
this.survey_spatial_component_id = obj?.survey_spatial_component_id || null;
this.name = obj?.name || null;
this.description = obj?.description || null;
this.geojson = (obj?.geojson?.length && obj.geojson) || [];
this.revision_count = obj?.revision_count || 0;
}
}

Expand Down
Loading

0 comments on commit c62c52b

Please sign in to comment.