Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:CodeTanzania/ewea-reports into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
BenMaruchu committed Jun 4, 2020
2 parents 06c8a9e + 701f445 commit c31fca9
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 131 deletions.
135 changes: 10 additions & 125 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -102,15 +102,15 @@
"generate-changelog": "^1.8.0",
"handlebars": "^4.7.6",
"husky": "^4.2.5",
"lint-staged": "^10.2.7",
"lint-staged": "^10.2.8",
"lodash.template": "^4.5.0",
"mocha": "^7.2.0",
"mongoose": ">=5.9.17",
"npm-check-updates": "^6.0.1",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"rollup": "^2.12.1",
"rollup": "^2.13.1",
"shelljs": "^0.8.4"
},
"peerDependencies": {
Expand Down
124 changes: 124 additions & 0 deletions src/aggregations/case.aggregations.js
@@ -0,0 +1,124 @@
import { Case } from '@codetanzania/ewea-case';

// start: constants
// order: base to specific

const CASE_AGGREGATION_EXCLUDE = [];

// start: extra metric fields
// order: base to specific

/**
* @constant
* @name CASE_BASE_METRIC_FIELDS
* @description Adds new metric fields to the next stage in the pipeline.
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @license MIT
* @since 0.8.0
* @version 0.1.0
*/
export const CASE_BASE_METRIC_FIELDS = {};

// start: projections
// order: base to specific
//
/**
* @constant
* @name CASE_DEFAULT_PROJECTION
* @description Normalize Case fields with defaults before pass to
* the next stage in the pipeline.
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @license MIT
* @since 0.5.0
* @version 0.1.0
*/
export const CASE_DEFAULT_PROJECTION = {
_id: 1,
createdAt: 1,
updatedAt: 1,
metrics: 1,
};

/**
* @constant
* @name CASE_BASE_PROJECTION
* @description Case fields passed to the next stage in the pipeline.
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @license MIT
* @since 0.5.0
* @version 0.1.0
*/
export const CASE_BASE_PROJECTION = {
_id: 1,
createdAt: 1,
updatedAt: 1,
metrics: 1,
};

// start: facets
// order: base, overall to specific

/**
* @constant
* @name CASE_FACET_OVERVIEW
* @description General `Event` overview facet.
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @license MIT
* @since 0.5.0
* @version 0.1.0
*/
export const CASE_FACET_OVERVIEW = {};

// start: aggregations
// order: base to specific

/**
* @function getEventCaseAggregation
* @name getEventCaseAggregation
* @description Create base aggregation for `Case` with all fields
* looked up and un-winded for further aggregation operations.
* @param {object} [criteria={}] conditions which will be applied in
* first aggregation stage.
* @returns {object} valid base aggregation for case.
*
* @author lally elias <lallyelias87@gmail.com>
* @license MIT
* @since 0.1.0
* @version 0.1.0
* @static
* @public
* @example
*
* getEventCaseAggregation({ ... });
* //=> Aggregation{ ... }
*
*/
export const getEventCaseAggregation = (criteria = {}) => {
// TODO: ignore agencies & focals unwind

// initialize case base aggregation
const options = { exclude: CASE_AGGREGATION_EXCLUDE };
const base = Case.lookup(criteria, options);

// project default on relations
base.project(CASE_DEFAULT_PROJECTION);

// add base projection
base.project(CASE_BASE_PROJECTION);

// TODO: project per relations before add metrics

// add extra metric fields
base.addFields(CASE_BASE_METRIC_FIELDS);

// return case base aggregation
return base;
};
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -29,6 +29,7 @@ export * from './aggregations/changelog.aggregations';
export * from './aggregations/event.aggregations';
export * from './aggregations/party.aggregations';
export * from './aggregations/dispatch.aggregations';
export * from './aggregations/case.aggregations';
export * from './aggregations/predefine.aggregations';
export * from './aggregations/overview.aggregations';

Expand Down

0 comments on commit c31fca9

Please sign in to comment.