diff --git a/.env b/.env
index 26702f26babec1b6eb05b8c6cbdb623c4ffd2104..2f26ed02da8b5ec45b282490c9443c541e04f4c7 100644
--- a/.env
+++ b/.env
@@ -2,5 +2,5 @@ PORT=8000
INSTANCE=PROD
HOST=localhost
USER=root
-PASSWORD=mysql
-DB=repp_users
\ No newline at end of file
+PASSWORD=rootroot
+DB=parameter_database
\ No newline at end of file
diff --git a/src/Controllers/ParameterController.ts b/src/Controllers/ParameterController.ts
index 852879e8cbbbc4802fcf36f374029055677c8d95..2586a27c883c064a4c46f27b04ad25594704c430 100644
--- a/src/Controllers/ParameterController.ts
+++ b/src/Controllers/ParameterController.ts
@@ -45,9 +45,9 @@ const getDefaultExtraData: Handler = async (req: Request, res: Response) => {
};
const updateParameterValue: Handler = async (req: Request, res: Response) => {
- const { parameters, parameterType } = req.body;
+ const { parameters } = req.body;
try {
- switch (parameterType) {
+ switch (parameters[0].parameterType) {
case ParameterType.DefaultWeight:
await ParameterService.updateDefaultWeight(parameters[0]);
break;
diff --git a/src/Schemas/getRepBody.ts b/src/Schemas/getRepBody.ts
index 3eeb9e715be29a113683b565b7a70d89b23d6dbe..deadbe2ba3bb2a80f9aa1925f2855debf7578afd 100644
--- a/src/Schemas/getRepBody.ts
+++ b/src/Schemas/getRepBody.ts
@@ -13,12 +13,15 @@ const getRepBody = {
},
sex: {
type: 'string' as const,
+ pattern: '(^Masculino$)|(^Femenino$)',
},
medianWeight: {
type: 'number' as const,
+ minimum: 0,
},
population: {
type: 'number' as const,
+ minumum: 0,
},
},
},
@@ -32,12 +35,18 @@ const getRepBody = {
properties: {
lowPALPrevalence: {
type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
},
moderatePALPrevalence: {
type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
},
intensePALPrevalence: {
type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
},
},
},
@@ -45,22 +54,61 @@ const getRepBody = {
type: 'object' as const,
required: ['urbanPercentage', 'activeUrbanPAL', 'lowUrbanPAL', 'ruralPercentage', 'activeRuralPAL', 'lowRuralPAL'],
properties: {
- urbanPercentage: { type: 'number' as const },
- activeUrbanPAL: { type: 'number' as const },
- lowUrbanPAL: { type: 'number' as const },
- ruralPercentage: { type: 'number' as const },
- activeRuralPAL: { type: 'number' as const },
- lowRuralPAL: { type: 'number' as const },
+ urbanPercentage: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
+ activeUrbanPAL: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
+ lowUrbanPAL: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
+ ruralPercentage: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
+ activeRuralPAL: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
+ lowRuralPAL: {
+ type: 'number' as const,
+ minimum: 0,
+ maximum: 100,
+ },
},
},
maternity18To29: {
type: 'object' as const,
properties: {
- pregnantWomen: { type: 'number' as const },
- lactatingWomen: { type: 'number' as const },
- countryBirthRate: { type: 'number' as const },
- countryWomenInAgeGroup: { type: 'number' as const },
- countryPopulation: { type: 'number' as const },
+ pregnantWomen: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ lactatingWomen: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ countryBirthRate: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ countryWomenInAgeGroup: {
+ type: 'number' as const,
+ exclusiveMinimum: 0,
+ },
+ countryPopulation: {
+ type: 'number' as const,
+ exclusiveMinimum: 0,
+ },
},
oneOf: [
{
@@ -74,11 +122,26 @@ const getRepBody = {
maternity30To59: {
type: 'object' as const,
properties: {
- pregnantWomen: { type: 'number' as const },
- lactatingWomen: { type: 'number' as const },
- countryBirthRate: { type: 'number' as const },
- countryWomenInAgeGroup: { type: 'number' as const },
- countryPopulation: { type: 'number' as const },
+ pregnantWomen: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ lactatingWomen: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ countryBirthRate: {
+ type: 'number' as const,
+ minimum: 0,
+ },
+ countryWomenInAgeGroup: {
+ type: 'number' as const,
+ exclusiveMinimum: 0,
+ },
+ countryPopulation: {
+ type: 'number' as const,
+ exclusiveMinimum: 0,
+ },
},
oneOf: [
{
diff --git a/src/Schemas/updateParameterValueBody.ts b/src/Schemas/updateParameterValueBody.ts
index b7e27a9238b95232c7938e75bcf13e13ff179684..048b17e3d636a4174702c20a04e8486db911a217 100644
--- a/src/Schemas/updateParameterValueBody.ts
+++ b/src/Schemas/updateParameterValueBody.ts
@@ -1,10 +1,7 @@
const updateParameterValueBody = {
type: 'object' as const,
- required: ['parameters', 'parameterType'],
+ required: ['parameters'],
properties: {
- parameterType: {
- type: 'string' as const,
- },
parameters: {
type: 'array' as const,
items: {
@@ -15,6 +12,7 @@ const updateParameterValueBody = {
},
sex: {
type: 'string' as const,
+ pattern: '(^Masculino$)|(^Femenino$)',
},
id: {
type: 'string' as const,
@@ -22,25 +20,35 @@ const updateParameterValueBody = {
value: {
type: 'number' as const,
},
- parameterType: {
- type: 'string' as const,
- },
order: {
type: 'number' as const,
+ minimum: 0,
},
description: {
type: 'string' as const,
},
},
- oneOf: [
+ anyOf: [
{
- required: ['parameterType', 'ageRange', 'sex', 'value'],
+ parameterType: {
+ type: 'string' as const,
+ pattern: '(^TMB$)|(^GET$)|(^Energia para crecimiento$)',
+ },
+ required: ['parameterType', 'ageRange', 'sex', 'order', 'value'],
},
{
- required: ['parameterType', 'id', 'value'],
+ parameterType: {
+ type: 'string' as const,
+ pattern: '^Peso por defecto$',
+ },
+ required: ['parameterType', 'ageRange', 'sex', 'value'],
},
{
- required: ['parameterType', 'ageRange', 'sex', 'order', 'value'],
+ parameterType: {
+ type: 'string' as const,
+ pattern: '(^NAF Menores$)|(^NAF Adultos$)|(^Embarazo y lactancia$)',
+ },
+ required: ['parameterType', 'id', 'value'],
},
],
},
diff --git a/src/Services/ERCalculator.ts b/src/Services/ERCalculator.ts
index 77bd5491ac05e9e70ac39e81e4669c6227432c0e..cab07b8a073607111bc67904567aeed0e6873e4d 100644
--- a/src/Services/ERCalculator.ts
+++ b/src/Services/ERCalculator.ts
@@ -24,8 +24,7 @@ const calculateTEE = (group: AgeGroup, params: number[], preval: MinorPAL): numb
const prevalCheck: number = preval.intensePALPrevalence
+ preval.lowPALPrevalence
+ preval.moderatePALPrevalence;
- if (prevalCheck !== 100 || preval.intensePALPrevalence < 0
- || preval.moderatePALPrevalence < 0 || preval.lowPALPrevalence < 0) {
+ if (prevalCheck !== 100) {
throw new Error('Minor PAL data does not respect format');
}
@@ -52,10 +51,7 @@ const calculatePAL = (params: number[], popData: AdultPAL): number => {
const popCheck: number = popData.ruralPercentage + popData.urbanPercentage;
const urbanPALCheck: number = popData.activeUrbanPAL + popData.lowUrbanPAL;
const ruralPALCheck: number = popData.activeRuralPAL + popData.lowRuralPAL;
- if (popCheck !== 100 || urbanPALCheck !== 100 || ruralPALCheck !== 100
- || popData.ruralPercentage < 0 || popData.urbanPercentage < 0
- || popData.activeUrbanPAL < 0 || popData.lowUrbanPAL < 0
- || popData.activeRuralPAL < 0 || popData.lowRuralPAL < 0) {
+ if (popCheck !== 100 || urbanPALCheck !== 100 || ruralPALCheck !== 100) {
throw new Error('Adult PAL data does not respect format');
}
@@ -72,7 +68,7 @@ const calculatePAL = (params: number[], popData: AdultPAL): number => {
// eslint-disable-next-line max-len
const calculateERWomenIndividual = (group: AgeGroup, params: number[], popData: IndividualMaternity, req: number): number => {
const popCheck: number = popData.lactatingWomen + popData.pregnantWomen;
- if (popCheck > group.population || popData.lactatingWomen < 0 || popData.pregnantWomen < 0) {
+ if (popCheck > group.population) {
throw new Error('Individual Maternity does not respect format');
}
@@ -88,10 +84,7 @@ const calculateERWomenIndividual = (group: AgeGroup, params: number[], popData:
// eslint-disable-next-line max-len
const calculateERWomenPopulation = (params: number[], popData: PopulationMaternity, req: number): number => {
- if (popData.countryWomenInAgeGroup > popData.countryPopulation
- || typeof (popData.countryBirthRate) !== 'number' || popData.countryBirthRate < 0
- || typeof (popData.countryWomenInAgeGroup) !== 'number' || popData.countryWomenInAgeGroup < 0
- || typeof (popData.countryPopulation) !== 'number' || popData.countryPopulation < 0) {
+ if (popData.countryWomenInAgeGroup > popData.countryPopulation) {
throw new Error('Population Maternity does not respect format');
}
diff --git a/src/Services/ParameterService.ts b/src/Services/ParameterService.ts
index a6a3456f12975006098921c3b0ddeb91ec2b9afd..85e69c0f27fab6e8012e737f4658af6e9c5af7dd 100644
--- a/src/Services/ParameterService.ts
+++ b/src/Services/ParameterService.ts
@@ -288,7 +288,7 @@ const updatePair = async (param: DefaultExtraDataDTO, pairID: string): Promise<v
const validateID = (id: string): boolean => {
const keys: string[] = Object.keys(extraDataIDs);
- for (let i = 0; i < keys.length; i + 1) {
+ for (let i = 0; i < keys.length; i += 1) {
if (extraDataIDs[keys[i]] === id) {
return true;
}
diff --git a/src/Services/ParserService.ts b/src/Services/ParserService.ts
index 0b2384024a8058ef9f62d4ddd4929dad167687e9..afa7841f154f530f15db93b9290d304d16ba65eb 100644
--- a/src/Services/ParserService.ts
+++ b/src/Services/ParserService.ts
@@ -3,29 +3,16 @@ import AgeGroupJSON from '../DTOs/AgeGroupJSON';
import AgeBracket from '../Enum/AgeBracket';
import Sex from '../Enum/Sex';
-const checkAgeGroup = (group: AgeGroupJSON): boolean => (
- typeof (group.age) !== 'string'
- || typeof (group.sex) !== 'string'
- || typeof (group.medianWeight) !== 'number'
- || typeof (group.population) !== 'number'
- || group.medianWeight <= 0
- || group.population <= 0
-);
-
const parseGroups = (groups: AgeGroupJSON[]): AgeGroup[] => {
const retGroups: AgeGroup[] = [];
groups.forEach((ageGroup: AgeGroupJSON) => {
- if (checkAgeGroup(ageGroup)) {
- throw new Error('Age group data does not meet specification');
- } else {
- const group: AgeGroup = {
- age: ageGroup.age as AgeBracket,
- sex: ageGroup.sex as Sex,
- medianWeight: ageGroup.medianWeight,
- population: ageGroup.population,
- };
- retGroups.push(group);
- }
+ const group: AgeGroup = {
+ age: ageGroup.age as AgeBracket,
+ sex: ageGroup.sex as Sex,
+ medianWeight: ageGroup.medianWeight,
+ population: ageGroup.population,
+ };
+ retGroups.push(group);
});
return retGroups;
};