Skip to content

Commit 4b3e81d

Browse files
committed
feat(model): add stage & severity field
1 parent db7371d commit 4b3e81d

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

src/case.model.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ import {
1515
CASE_OPTION_AUTOPOPULATE,
1616
} from './internals';
1717

18-
import { number, description, remarks } from './schema/base.schema';
18+
import {
19+
number,
20+
stage,
21+
severity,
22+
description,
23+
remarks,
24+
} from './schema/base.schema';
1925
import { victim, followup } from './schema/common.schema';
2026
import { reporter, resolver } from './schema/parties.schema';
2127
import { reportedAt, resolvedAt } from './schema/dates.schema';
2228

2329
const SCHEMA = mergeObjects(
2430
{ number },
31+
{ stage, severity },
2532
{ victim },
2633
{ description },
2734
{ reportedAt, reporter },

src/schema/base.schema.js

+89
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { get } from 'lodash';
22
import moment from 'moment';
33
import { ObjectId } from '@lykmapipo/mongoose-common';
44
import { Predefine } from '@lykmapipo/predefine';
5+
import { DEFAULT_SEEDS } from '@codetanzania/ewea-common';
56
import { Event } from '@codetanzania/ewea-event';
67

78
import { AUTOPOPULATE_OPTION_PREDEFINE, COUNTRY_CODE } from '../internals';
@@ -138,6 +139,94 @@ export const event = {
138139
default: undefined,
139140
};
140141

142+
/**
143+
* @name stage
144+
* @description Currently assigned stage of a case.
145+
*
146+
* @memberof Case
147+
*
148+
* @type {object}
149+
* @property {object} type - schema(data) type
150+
* @property {boolean} required - mark required
151+
* @property {boolean} index - ensure database index
152+
* @property {boolean} exists - ensure ref exists before save
153+
* @property {object} autopopulate - auto populate(eager loading) options
154+
* @property {boolean} taggable - allow field use for tagging
155+
* @property {boolean} exportable - allow field use for exporting
156+
* @property {boolean} aggregatable - allow field use for aggregation
157+
* @property {boolean} default - default value set when none provided
158+
* @property {object} fake - fake data generator options
159+
*
160+
* @author lally elias <lallyelias87@gmail.com>
161+
* @since 0.4.0
162+
* @version 0.1.0
163+
* @instance
164+
* @example
165+
* {
166+
* _id: '5dde6ca23631a92c2d616250',
167+
* strings: { name: { en: 'Confirmed' } },
168+
* }
169+
*/
170+
export const stage = {
171+
type: ObjectId,
172+
ref: Predefine.MODEL_NAME,
173+
// required: true,
174+
index: true,
175+
exists: true,
176+
aggregatable: { unwind: true },
177+
autopopulate: AUTOPOPULATE_OPTION_PREDEFINE,
178+
taggable: true,
179+
exportable: {
180+
format: (v) => get(v, 'strings.name.en'),
181+
default: 'NA',
182+
},
183+
default: DEFAULT_SEEDS.CaseStage,
184+
};
185+
186+
/**
187+
* @name severity
188+
* @description Currently assigned severity of a case.
189+
*
190+
* @memberof Case
191+
*
192+
* @type {object}
193+
* @property {object} type - schema(data) type
194+
* @property {boolean} required - mark required
195+
* @property {boolean} index - ensure database index
196+
* @property {boolean} exists - ensure ref exists before save
197+
* @property {object} autopopulate - auto populate(eager loading) options
198+
* @property {boolean} taggable - allow field use for tagging
199+
* @property {boolean} exportable - allow field use for exporting
200+
* @property {boolean} aggregatable - allow field use for aggregation
201+
* @property {boolean} default - default value set when none provided
202+
* @property {object} fake - fake data generator options
203+
*
204+
* @author lally elias <lallyelias87@gmail.com>
205+
* @since 0.4.0
206+
* @version 0.1.0
207+
* @instance
208+
* @example
209+
* {
210+
* _id: '5dde6ca23631a92c2d616250',
211+
* strings: { name: { en: 'Extreme' } },
212+
* }
213+
*/
214+
export const severity = {
215+
type: ObjectId,
216+
ref: Predefine.MODEL_NAME,
217+
// required: true,
218+
index: true,
219+
exists: true,
220+
aggregatable: { unwind: true },
221+
autopopulate: AUTOPOPULATE_OPTION_PREDEFINE,
222+
taggable: true,
223+
exportable: {
224+
format: (v) => get(v, 'strings.name.en'),
225+
default: 'NA',
226+
},
227+
default: DEFAULT_SEEDS.CaseSeverity,
228+
};
229+
141230
/**
142231
* @name number
143232
* @description Human readable, unique identifier of a case.

test/unit/case.schema.spec.js

+40
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,46 @@ describe('Case Schema', () => {
2323
expect(number.options.fake).to.exist;
2424
});
2525

26+
it('should have stage field', () => {
27+
const stage = Case.path('stage');
28+
29+
expect(stage).to.exist;
30+
expect(stage).to.be.instanceof(SchemaTypes.ObjectId);
31+
expect(stage.options).to.exist;
32+
expect(stage.options).to.be.an('object');
33+
expect(stage.options.type).to.exist;
34+
expect(stage.options.ref).to.exist;
35+
expect(stage.options.ref).to.be.equal(Predefine.MODEL_NAME);
36+
expect(stage.options.index).to.be.true;
37+
// expect(stage.options.required).to.be.true;
38+
expect(stage.options.exists).to.be.true;
39+
expect(stage.options.autopopulate).to.exist;
40+
expect(stage.options.taggable).to.exist;
41+
expect(stage.options.exportable).to.exist;
42+
expect(stage.options.aggregatable).to.exist;
43+
expect(stage.options.default).to.exist;
44+
});
45+
46+
it('should have severity field', () => {
47+
const severity = Case.path('severity');
48+
49+
expect(severity).to.exist;
50+
expect(severity).to.be.instanceof(SchemaTypes.ObjectId);
51+
expect(severity.options).to.exist;
52+
expect(severity.options).to.be.an('object');
53+
expect(severity.options.type).to.exist;
54+
expect(severity.options.ref).to.exist;
55+
expect(severity.options.ref).to.be.equal(Predefine.MODEL_NAME);
56+
expect(severity.options.index).to.be.true;
57+
// expect(severity.options.required).to.be.true;
58+
expect(severity.options.exists).to.be.true;
59+
expect(severity.options.autopopulate).to.exist;
60+
expect(severity.options.taggable).to.exist;
61+
expect(severity.options.exportable).to.exist;
62+
expect(severity.options.aggregatable).to.exist;
63+
expect(severity.options.default).to.exist;
64+
});
65+
2666
it('should have victim field', () => {
2767
const victim = Case.path('victim');
2868
const referral = Case.path('victim.referral');

0 commit comments

Comments
 (0)