Skip to content

Commit bd47174

Browse files
committed
feat(model): add victim & next of kin locales
1 parent 2e49470 commit bd47174

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/schema/common.schema.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '@codetanzania/ewea-internals';
77
import { DEFAULT_SEEDS } from '@codetanzania/ewea-common';
88
import { compact } from '@lykmapipo/common';
9+
import { getString, getStrings } from '@lykmapipo/env';
910
import { Point } from 'mongoose-geojson-schemas';
1011
import { ObjectId, Mixed, createSubSchema } from '@lykmapipo/mongoose-common';
1112
import { Predefine } from '@lykmapipo/predefine';
@@ -19,6 +20,9 @@ import { follower } from './parties.schema';
1920
import { followedAt } from './dates.schema';
2021
import { outcome, remarks } from './base.schema';
2122

23+
const DEFAULT_LOCALE = getString('DEFAULT_LOCALE', 'en');
24+
const LOCALES = getStrings('LOCALES', DEFAULT_LOCALE);
25+
2226
/**
2327
* @name properties
2428
* @description A map of key value pairs to allow to associate
@@ -45,6 +49,40 @@ export const properties = {
4549
fake: (f) => f.helpers.createTransaction(),
4650
};
4751

52+
/**
53+
* @name locale
54+
* @description Defines the party's language, region and any
55+
* special variant preferences.
56+
*
57+
* @see {@link https://en.wikipedia.org/wiki/Locale_(computer_software)}
58+
*
59+
* @type {object}
60+
* @property {object} type - schema(data) type
61+
* @property {boolean} trim - force trimming
62+
* @property {boolean} enum - list of acceptable values
63+
* @property {boolean} index - ensure database index
64+
* @property {boolean} searchable - allow for searching
65+
* @property {boolean} taggable - allow field use for tagging
66+
* @property {boolean} default - default value set when none provided
67+
* @property {object} fake - fake data generator options
68+
*
69+
* @since 0.1.0
70+
* @version 0.1.0
71+
* @instance
72+
* @example
73+
* en
74+
*/
75+
export const locale = {
76+
type: String,
77+
trim: true,
78+
enum: LOCALES,
79+
index: true,
80+
searchable: true,
81+
taggable: true,
82+
default: DEFAULT_LOCALE,
83+
fake: true,
84+
};
85+
4886
/**
4987
* @name name
5088
* @description Full name name of the party(i.e individual).
@@ -539,7 +577,8 @@ export const nationality = {
539577
* @type {object}
540578
* @property {string} name - Full name of the next of kin
541579
* @property {string} mobile - Mobile phone number of the next of kin
542-
* @property {string} email - Email address of the victim
580+
* @property {string} email - Email address of the next of kin
581+
* @property {string} locale - Locale of the next of kin
543582
*
544583
* @author lally elias <lallyelias87@gmail.com>
545584
* @since 0.1.0
@@ -550,12 +589,15 @@ export const nationality = {
550589
* name: "Jane Doe",
551590
* mobile: "+255715463739"
552591
* email: "jane.doe@example.com"
592+
* locale: "en"
553593
* }
554594
*/
555595
export const nextOfKin = createSubSchema({
556596
name,
557597
mobile,
558598
email,
599+
locale,
600+
// csids,
559601
});
560602

561603
/**
@@ -574,6 +616,7 @@ export const nextOfKin = createSubSchema({
574616
* @property {object} occupation - Occupation of the victim
575617
* @property {object} nationality - Nationality of the victim
576618
* @property {string} address - Address of the victim
619+
* @property {string} locale - Locale of the victim
577620
*
578621
* @author lally elias <lallyelias87@gmail.com>
579622
* @since 0.1.0
@@ -593,6 +636,7 @@ export const nextOfKin = createSubSchema({
593636
* nationality: { name: { en: "Tanzanian"} },
594637
* address: "Tandale",
595638
* area: { name: { en: "Dar es Salaam"} },
639+
* locale: "en",
596640
* nextOfKin: { name: "Halima Mdoe", mobile: "+255715463740" }
597641
* }
598642
*/
@@ -610,7 +654,9 @@ export const victim = createSubSchema({
610654
nationality,
611655
address,
612656
area,
657+
locale,
613658
nextOfKin,
659+
// csids.
614660
});
615661

616662
/**

test/unit/case.schema.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ describe('Case Schema', () => {
7373
const gender = Case.path('victim.gender');
7474
const occupation = Case.path('victim.occupation');
7575
const nationality = Case.path('victim.nationality');
76+
const locale = Case.path('victim.locale');
7677
const nextOfKinName = Case.path('victim.nextOfKin.name');
7778
const nextOfKinMobile = Case.path('victim.nextOfKin.mobile');
7879
const nextOfKinEmail = Case.path('victim.nextOfKin.email');
80+
const nextOfKinLocale = Case.path('victim.nextOfKin.locale');
7981

8082
expect(victim).to.exist;
8183
expect(victim).to.be.an.instanceof(SchemaTypes.Embedded);
@@ -189,6 +191,17 @@ describe('Case Schema', () => {
189191
expect(nationality.options.aggregatable).to.exist;
190192
expect(nationality.options.default).to.exist;
191193

194+
expect(locale).to.exist;
195+
expect(locale).to.be.an.instanceof(SchemaTypes.String);
196+
expect(locale.options).to.exist;
197+
expect(locale.options).to.be.an('object');
198+
expect(locale.options.type).to.exist;
199+
expect(locale.options.trim).to.be.true;
200+
expect(locale.options.enum).to.be.exist;
201+
expect(locale.options.index).to.be.true;
202+
expect(locale.options.searchable).to.be.true;
203+
expect(locale.options.fake).to.exist;
204+
192205
expect(nextOfKinName).to.exist;
193206
expect(nextOfKinName).to.be.instanceof(SchemaTypes.String);
194207
expect(nextOfKinName.options).to.exist;
@@ -225,6 +238,17 @@ describe('Case Schema', () => {
225238
expect(nextOfKinEmail.options.taggable).to.be.true;
226239
expect(nextOfKinEmail.options.exportable).to.be.true;
227240
expect(nextOfKinEmail.options.fake).to.exist;
241+
242+
expect(nextOfKinLocale).to.exist;
243+
expect(nextOfKinLocale).to.be.an.instanceof(SchemaTypes.String);
244+
expect(nextOfKinLocale.options).to.exist;
245+
expect(nextOfKinLocale.options).to.be.an('object');
246+
expect(nextOfKinLocale.options.type).to.exist;
247+
expect(nextOfKinLocale.options.trim).to.be.true;
248+
expect(nextOfKinLocale.options.enum).to.be.exist;
249+
expect(nextOfKinLocale.options.index).to.be.true;
250+
expect(nextOfKinLocale.options.searchable).to.be.true;
251+
expect(nextOfKinLocale.options.fake).to.exist;
228252
});
229253

230254
it('should have description field', () => {

0 commit comments

Comments
 (0)