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

NERT-320 api and data model work to support project objectives, other changes #90

Merged
merged 3 commits into from
Jun 5, 2024
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
36 changes: 35 additions & 1 deletion api/src/models/project-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PostFundingSource,
PostIUCNData,
PostLocationData,
PostObjectivesData,
PostPartnershipsData,
PostProjectData,
PostProjectObject
Expand Down Expand Up @@ -42,6 +43,10 @@ describe('PostProjectObject', () => {
it('sets partnerships', function () {
expect(projectPostObject.partnership).to.eql([]);
});

it('sets objectives', function () {
expect(projectPostObject.objective).to.eql([]);
});
});

describe.skip('All values provided', () => {
Expand Down Expand Up @@ -123,7 +128,8 @@ describe('PostProjectObject', () => {
}
]
},
partnerships: ['partner1, partner2']
partnerships: ['partner1, partner2'],
objectives: ['objective1, obective2']
};

before(() => {
Expand Down Expand Up @@ -289,6 +295,34 @@ describe('PostPartnershipsData', () => {
});
});

describe('PostObjectivesData', () => {
describe('No values provided', () => {
let projectObjectiveData: PostObjectivesData;

before(() => {
projectObjectiveData = new PostObjectivesData(null);
});

it('sets projectObjectivesData', function () {
expect(projectObjectiveData.objectives).to.eql([]);
});
});

describe.skip('All values provided', () => {
let projectObjectiveData: PostObjectivesData;

const obj = ['1', '2'];

before(() => {
projectObjectiveData = new PostObjectivesData(obj);
});

it('sets projectObjectivesData', function () {
expect(projectObjectiveData.objectives).to.eql(obj);
});
});
});

describe('PostFundingSource', () => {
describe('No values provided', () => {
let projectFundingData: PostFundingSource;
Expand Down
29 changes: 29 additions & 0 deletions api/src/models/project-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
iucn: PostIUCNData;
funding: PostFundingData;
partnership: PostPartnershipsData;
objective: PostObjectivesData;
focus: PostFocusData;
restoration_plan: PostRestPlanData;

Expand All @@ -32,6 +33,7 @@
this.funding = (obj?.funding && new PostFundingData(obj.funding)) || null;
this.iucn = (obj?.iucn && new PostIUCNData(obj.iucn)) || null;
this.partnership = (obj?.partnership && new PostPartnershipsData(obj.partnership)) || [];
this.objective = (obj?.objective && new PostObjectivesData(obj.objective)) || [];
this.focus = (obj?.focus && new PostFocusData(obj.focus)) || [];
this.restoration_plan = (obj?.restoration_plan && new PostRestPlanData(obj.restoration_plan)) || null;
}
Expand Down Expand Up @@ -158,6 +160,33 @@
}
}

export interface IPostObjective {
objective: string;
}

/**
* Processes POST /project objectives data
*
* @export
* @class PostObjectivesData
*/
export class PostObjectivesData {
objectives: IPostObjective[];

constructor(obj?: any) {
defaultLog.debug({ label: 'PostObjectivesData', message: 'params', obj });

this.objectives =
(obj?.objectives?.length &&
obj.objectives.map((item: any) => {
return {

Check warning on line 182 in api/src/models/project-create.ts

View check run for this annotation

Codecov / codecov/patch

api/src/models/project-create.ts#L182

Added line #L182 was not covered by tests
objective: item.objective
};
})) ||
[];
}
}

/**
* Processes POST /project project data.
*
Expand Down
39 changes: 38 additions & 1 deletion api/src/models/project-update.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import { PutFundingData, PutIUCNData, PutLocationData, PutPartnershipsData, PutProjectData } from './project-update';
import {
PutFundingData,
PutIUCNData,
PutLocationData,
PutObjectivesData,
PutPartnershipsData,
PutProjectData
} from './project-update';

describe('PutLocationData', () => {
describe('No values provided', () => {
Expand Down Expand Up @@ -153,6 +160,36 @@ describe('PutPartnershipsData', () => {
});
});

describe('PutObjectivesData', () => {
describe('No values provided', () => {
let data: PutObjectivesData;

before(() => {
data = new PutObjectivesData(null);
});

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

describe('all values provided', () => {
const obj = {
objectives: ['objective 3', 'objective 4']
};

let data: PutObjectivesData;

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

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

describe('PutProjectData', () => {
describe('No values provided', () => {
let data: PutProjectData;
Expand Down
8 changes: 8 additions & 0 deletions api/src/models/project-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export class PutPartnershipsData {
}
}

export class PutObjectivesData {
objectives: string[];

constructor(obj?: any) {
this.objectives = (obj?.objectives?.length && obj.objectives) || [];
}
}

export class PutFundingData {
fundingSources: PostFundingSource[];

Expand Down
55 changes: 55 additions & 0 deletions api/src/models/project-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GetFundingData,
GetIUCNClassificationData,
GetLocationData,
GetObjectivesData,
GetPartnershipsData,
GetPermitData,
GetProjectData,
Expand Down Expand Up @@ -65,6 +66,60 @@ describe('GetPartnershipsData', () => {
});
});

describe('GetObjectivesData', () => {
describe('No values provided', () => {
let data: GetObjectivesData;

before(() => {
data = new GetObjectivesData(null as unknown as any[]);
});

it('sets objectives', function () {
expect(data.objectives).to.eql([]);
});
});

describe('Empty arrays as values provided', () => {
let data: GetObjectivesData;

before(() => {
data = new GetObjectivesData([]);
});

it('sets objectives', function () {
expect(data.objectives).to.eql([]);
});
});

describe('objectives values provided', () => {
let data: GetObjectivesData;

const objectives = [{ objective: 'objective 1' }, { objective: 'objective 2' }];

before(() => {
data = new GetObjectivesData(objectives);
});

it('sets objectives', function () {
expect(data.objectives).to.eql(['objective 1', 'objective 2']);
});
});

describe('All values provided', () => {
let data: GetObjectivesData;

const objectives = [{ objective: 'objective 3' }, { objective: 'objective 4' }];

before(() => {
data = new GetObjectivesData(objectives);
});

it('sets objectives', function () {
expect(data.objectives).to.eql(['objective 3', 'objective 4']);
});
});
});

describe('GetIUCNClassificationData', () => {
describe('No values provided', () => {
it('sets classification details', function () {
Expand Down
12 changes: 12 additions & 0 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ProjectObject = {
contact: GetContactData;
permit: GetPermitData;
partnerships: GetPartnershipsData;
objectives: GetObjectivesData;
funding: GetFundingData;
location: GetLocationData;
};
Expand Down Expand Up @@ -129,6 +130,17 @@ export class GetPartnershipsData {
}
}

export interface IGetObjective {
objective: string;
}
export class GetObjectivesData {
objectives: IGetObjective[];

constructor(objectives?: any[]) {
this.objectives = (objectives?.length && objectives.map((item: any) => item.objective)) || [];
}
}

export class GetLocationData {
geometry?: Feature[];
is_within_overlapping?: string;
Expand Down
21 changes: 20 additions & 1 deletion api/src/openapi/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ export const projectCreatePostRequestObject = {
}
}
}
},
objective: {
title: 'Project objectives',
type: 'object',
properties: {
objectives: {
type: 'array',
items: {
title: 'Project objectives',
type: 'object',
properties: {
objective: {
type: 'string'
}
}
}
}
}
}
}
};
Expand Down Expand Up @@ -200,7 +218,8 @@ const projectUpdateProperties = {
}
},
funding: { type: 'object', properties: {} },
partnership: { type: 'object', properties: {} }
partnership: { type: 'object', properties: {} },
objective: { type: 'object', properties: {} }
};

/**
Expand Down
4 changes: 1 addition & 3 deletions api/src/paths/project/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ POST.apiDoc = {
objective: {
title: 'Project objectives',
type: 'object',
required: ['objectives'],
additionalProperties: false,
properties: {
objectives: {
type: 'array',
required: ['objective'],
items: {
title: 'Project objective',
title: 'Project objectives',
type: 'object',
properties: {
objective: {
Expand Down
19 changes: 19 additions & 0 deletions api/src/paths/project/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,25 @@ GET.apiDoc = {
}
}
},
objective: {
title: 'Project objectives',
type: 'object',
required: ['objectives'],
properties: {
objectives: {
type: 'array',
items: {
title: 'Project objectives',
type: 'object',
properties: {
objective: {
type: 'string'
}
}
}
}
}
},
location: {
description: 'The project location object',
type: 'object',
Expand Down
1 change: 1 addition & 0 deletions api/src/paths/project/{projectId}/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('update', () => {
permit: {},
funding: {},
partnerships: {},
objectives: {},
location: {}
};

Expand Down
21 changes: 21 additions & 0 deletions api/src/paths/project/{projectId}/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,26 @@ PUT.apiDoc = {
}
}
},
objective: {
description: 'Project objectives',
type: 'object',
required: ['objectives'],
additionalProperties: false,
properties: {
objectives: {
type: 'array',
items: {
title: 'Project objectives',
type: 'object',
properties: {
objective: {
type: 'string'
}
}
}
}
}
},
location: {
description: 'The project location object',
type: 'object',
Expand Down Expand Up @@ -327,6 +347,7 @@ export interface IUpdateProject {
iucn: object | null;
funding: object | null;
partnership: object | null;
objective: object | null;
}

/**
Expand Down
Loading
Loading