Skip to content

Commit ce29d4a

Browse files
committed
chore(deps): force latest version & audit fix
1 parent 96d105b commit ce29d4a

File tree

2 files changed

+136
-24
lines changed

2 files changed

+136
-24
lines changed

es/index.js

+69-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { COLLECTION_NAME_CASE, POPULATION_MAX_DEPTH, PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA, PREDEFINE_NAMESPACE_PARTYGENDER, PREDEFINE_NAMESPACE_PARTYOCCUPATION, PREDEFINE_NAMESPACE_PARTYNATIONALITY, MODEL_NAME_CASE } from '@codetanzania/ewea-internals';
1+
import { COLLECTION_NAME_CASE, POPULATION_MAX_DEPTH, PREDEFINE_NAMESPACE_CASESTAGE, PREDEFINE_NAMESPACE_CASESEVERITY, PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA, PREDEFINE_NAMESPACE_PARTYGENDER, PREDEFINE_NAMESPACE_PARTYOCCUPATION, PREDEFINE_NAMESPACE_PARTYNATIONALITY, MODEL_NAME_CASE, DEFAULT_SEEDS as DEFAULT_SEEDS$1 } from '@codetanzania/ewea-internals';
22
import { compact, mergeObjects, idOf, pkg } from '@lykmapipo/common';
33
import { getString, apiVersion as apiVersion$1 } from '@lykmapipo/env';
44
import { ObjectId, createSubSchema, Mixed, model, createSchema, copyInstance, connect } from '@lykmapipo/mongoose-common';
55
import { mount } from '@lykmapipo/express-common';
66
import { Router, getFor, schemaFor, downloadFor, postFor, getByIdFor, patchFor, putFor, deleteFor, start as start$1 } from '@lykmapipo/express-rest-actions';
77
import { createModels } from '@lykmapipo/file';
8-
import { get, pick } from 'lodash';
8+
import { get, set, pick } from 'lodash';
99
import '@lykmapipo/mongoose-sequenceable';
1010
import actions from 'mongoose-rest-actions';
1111
import exportable from '@lykmapipo/mongoose-exportable';
12+
import { DEFAULT_SEEDS, caseSeverityFor } from '@codetanzania/ewea-common';
1213
import moment from 'moment';
1314
import { Predefine } from '@lykmapipo/predefine';
14-
import { DEFAULT_SEEDS } from '@codetanzania/ewea-common';
1515
import { Event } from '@codetanzania/ewea-event';
1616
import 'mongoose-geojson-schemas';
1717
import { Party } from '@codetanzania/emis-stakeholder';
@@ -236,7 +236,7 @@ const stage = {
236236
format: (v) => get(v, 'strings.name.en'),
237237
default: 'NA',
238238
},
239-
default: DEFAULT_SEEDS.CaseStage,
239+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_CASESTAGE],
240240
};
241241

242242
/**
@@ -280,7 +280,7 @@ const severity = {
280280
format: (v) => get(v, 'strings.name.en'),
281281
default: 'NA',
282282
},
283-
default: DEFAULT_SEEDS.CaseSeverity,
283+
default: DEFAULT_SEEDS[PREDEFINE_NAMESPACE_CASESEVERITY],
284284
};
285285

286286
/**
@@ -749,7 +749,7 @@ const age = {
749749
type: Number,
750750
index: true,
751751
exportable: true,
752-
fake: (f) => f.random.number(),
752+
fake: (f) => f.random.number({ min: 1, max: 100 }),
753753
};
754754

755755
/**
@@ -773,7 +773,32 @@ const weight = {
773773
type: Number,
774774
index: true,
775775
exportable: true,
776-
fake: (f) => f.random.number(),
776+
fake: (f) => f.random.number({ min: 1, max: 250 }),
777+
};
778+
779+
/**
780+
* @name score
781+
* @description Current score of the case followup.
782+
*
783+
* It used to derive case severity.
784+
*
785+
* @property {object} type - schema(data) type
786+
* @property {boolean} trim - force trimming
787+
* @property {boolean} index - ensure database index
788+
* @property {object} fake - fake data generator options
789+
*
790+
* @author lally elias <lallyelias87@gmail.com>
791+
* @since 0.1.0
792+
* @version 0.1.0
793+
* @instance
794+
* @example
795+
* 4
796+
*/
797+
const score = {
798+
type: Number,
799+
index: true,
800+
exportable: true,
801+
fake: (f) => f.random.number({ min: 0, max: 5 }),
777802
};
778803

779804
/**
@@ -1213,6 +1238,7 @@ const followup = createSubSchema({
12131238
follower,
12141239
followedAt,
12151240
symptoms: properties,
1241+
score,
12161242
outcome,
12171243
remarks,
12181244
});
@@ -1294,17 +1320,47 @@ CaseSchema.pre('validate', function onPreValidate(done) {
12941320
* @instance
12951321
*/
12961322
CaseSchema.methods.preValidate = function preValidate(done) {
1297-
// ensure started(or reported) date
1298-
// TODO: drop reported date & use createdAt
1323+
// ensure reported date
12991324
this.reportedAt = this.reportedAt || this.createdAt || new Date();
13001325

1301-
// TODO: ensure victim default gender
1302-
// TODO: ensure victim default occupation
1326+
// ensure case stage
1327+
if (!get(this, 'stage')) {
1328+
const staje = DEFAULT_SEEDS$1[PREDEFINE_NAMESPACE_CASESTAGE];
1329+
set(this, 'stage', staje);
1330+
}
13031331

1304-
// TODO: ensure event group and type
1332+
// TODO: compute score
1333+
// TODO: move score to case base schema
1334+
// always: ensure case severity from followup score
1335+
const score = get(this, 'followup.score');
1336+
this.severity = caseSeverityFor({ score });
13051337

1306-
// TODO: ensure default values
1338+
// ensure victim gender
1339+
if (!get(this, 'victim.gender')) {
1340+
const gender = DEFAULT_SEEDS$1[PREDEFINE_NAMESPACE_PARTYGENDER];
1341+
set(this, 'victim.gender', gender);
1342+
}
13071343

1344+
// ensure victim default occupation
1345+
if (!get(this, 'victim.occupation')) {
1346+
const occupation = DEFAULT_SEEDS$1[PREDEFINE_NAMESPACE_PARTYOCCUPATION];
1347+
set(this, 'victim.occupation', occupation);
1348+
}
1349+
1350+
// ensure victim default nationality
1351+
if (!get(this, 'victim.nationality')) {
1352+
const nationality = DEFAULT_SEEDS$1[PREDEFINE_NAMESPACE_PARTYNATIONALITY];
1353+
set(this, 'victim.nationality', nationality);
1354+
}
1355+
1356+
// ensure victim default area
1357+
if (!get(this, 'victim.area')) {
1358+
const area = DEFAULT_SEEDS$1[PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA];
1359+
set(this, 'victim.area', area);
1360+
}
1361+
1362+
// TODO: ensure event group and type
1363+
// TODO: ensure default values
13081364
// TODO: ensure case status
13091365

13101366
// return

lib/index.js

+67-11
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const lodash = require('lodash');
1111
require('@lykmapipo/mongoose-sequenceable');
1212
const actions = require('mongoose-rest-actions');
1313
const exportable = require('@lykmapipo/mongoose-exportable');
14+
const eweaCommon = require('@codetanzania/ewea-common');
1415
const moment = require('moment');
1516
const predefine = require('@lykmapipo/predefine');
16-
const eweaCommon = require('@codetanzania/ewea-common');
1717
const eweaEvent = require('@codetanzania/ewea-event');
1818
require('mongoose-geojson-schemas');
1919
const emisStakeholder = require('@codetanzania/emis-stakeholder');
@@ -238,7 +238,7 @@ const stage = {
238238
format: (v) => lodash.get(v, 'strings.name.en'),
239239
default: 'NA',
240240
},
241-
default: eweaCommon.DEFAULT_SEEDS.CaseStage,
241+
default: eweaCommon.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_CASESTAGE],
242242
};
243243

244244
/**
@@ -282,7 +282,7 @@ const severity = {
282282
format: (v) => lodash.get(v, 'strings.name.en'),
283283
default: 'NA',
284284
},
285-
default: eweaCommon.DEFAULT_SEEDS.CaseSeverity,
285+
default: eweaCommon.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_CASESEVERITY],
286286
};
287287

288288
/**
@@ -751,7 +751,7 @@ const age = {
751751
type: Number,
752752
index: true,
753753
exportable: true,
754-
fake: (f) => f.random.number(),
754+
fake: (f) => f.random.number({ min: 1, max: 100 }),
755755
};
756756

757757
/**
@@ -775,7 +775,32 @@ const weight = {
775775
type: Number,
776776
index: true,
777777
exportable: true,
778-
fake: (f) => f.random.number(),
778+
fake: (f) => f.random.number({ min: 1, max: 250 }),
779+
};
780+
781+
/**
782+
* @name score
783+
* @description Current score of the case followup.
784+
*
785+
* It used to derive case severity.
786+
*
787+
* @property {object} type - schema(data) type
788+
* @property {boolean} trim - force trimming
789+
* @property {boolean} index - ensure database index
790+
* @property {object} fake - fake data generator options
791+
*
792+
* @author lally elias <lallyelias87@gmail.com>
793+
* @since 0.1.0
794+
* @version 0.1.0
795+
* @instance
796+
* @example
797+
* 4
798+
*/
799+
const score = {
800+
type: Number,
801+
index: true,
802+
exportable: true,
803+
fake: (f) => f.random.number({ min: 0, max: 5 }),
779804
};
780805

781806
/**
@@ -1215,6 +1240,7 @@ const followup = mongooseCommon.createSubSchema({
12151240
follower,
12161241
followedAt,
12171242
symptoms: properties,
1243+
score,
12181244
outcome,
12191245
remarks,
12201246
});
@@ -1296,17 +1322,47 @@ CaseSchema.pre('validate', function onPreValidate(done) {
12961322
* @instance
12971323
*/
12981324
CaseSchema.methods.preValidate = function preValidate(done) {
1299-
// ensure started(or reported) date
1300-
// TODO: drop reported date & use createdAt
1325+
// ensure reported date
13011326
this.reportedAt = this.reportedAt || this.createdAt || new Date();
13021327

1303-
// TODO: ensure victim default gender
1304-
// TODO: ensure victim default occupation
1328+
// ensure case stage
1329+
if (!lodash.get(this, 'stage')) {
1330+
const staje = eweaInternals.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_CASESTAGE];
1331+
lodash.set(this, 'stage', staje);
1332+
}
13051333

1306-
// TODO: ensure event group and type
1334+
// TODO: compute score
1335+
// TODO: move score to case base schema
1336+
// always: ensure case severity from followup score
1337+
const score = lodash.get(this, 'followup.score');
1338+
this.severity = eweaCommon.caseSeverityFor({ score });
13071339

1308-
// TODO: ensure default values
1340+
// ensure victim gender
1341+
if (!lodash.get(this, 'victim.gender')) {
1342+
const gender = eweaInternals.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_PARTYGENDER];
1343+
lodash.set(this, 'victim.gender', gender);
1344+
}
13091345

1346+
// ensure victim default occupation
1347+
if (!lodash.get(this, 'victim.occupation')) {
1348+
const occupation = eweaInternals.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_PARTYOCCUPATION];
1349+
lodash.set(this, 'victim.occupation', occupation);
1350+
}
1351+
1352+
// ensure victim default nationality
1353+
if (!lodash.get(this, 'victim.nationality')) {
1354+
const nationality = eweaInternals.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_PARTYNATIONALITY];
1355+
lodash.set(this, 'victim.nationality', nationality);
1356+
}
1357+
1358+
// ensure victim default area
1359+
if (!lodash.get(this, 'victim.area')) {
1360+
const area = eweaInternals.DEFAULT_SEEDS[eweaInternals.PREDEFINE_NAMESPACE_ADMINISTRATIVEAREA];
1361+
lodash.set(this, 'victim.area', area);
1362+
}
1363+
1364+
// TODO: ensure event group and type
1365+
// TODO: ensure default values
13101366
// TODO: ensure case status
13111367

13121368
// return

0 commit comments

Comments
 (0)