-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(overview-analysis): expose parties overview
- Loading branch information
Showing
6 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { isFunction } from 'lodash'; | ||
import { parallel } from 'async'; | ||
import { safeMergeObjects } from '@lykmapipo/common'; | ||
import { getPartyOverview } from './party.aggregations'; | ||
|
||
export const DEFAULT_OVERVIEW_ANALYSIS = { | ||
parties: { total: 0, agency: 0, focal: 0 }, | ||
}; | ||
|
||
export const getOverviewAnalysis = (criteria, done) => { | ||
// normalize arguments | ||
const filter = isFunction(criteria) ? {} : criteria; | ||
const cb = isFunction(criteria) ? criteria : done; | ||
|
||
// tasks | ||
const parties = (next) => getPartyOverview(filter, next); | ||
const tasks = { parties }; | ||
|
||
// return | ||
return parallel(tasks, (error, overviews) => { | ||
// back-off on error | ||
if (error) { | ||
return cb(error); | ||
} | ||
|
||
// normalize and return | ||
const data = safeMergeObjects(DEFAULT_OVERVIEW_ANALYSIS, overviews); | ||
return cb(null, { data }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
expect, | ||
// enableDebug | ||
} from '@lykmapipo/mongoose-test-helpers'; | ||
|
||
import { getOverviewAnalysis } from '../../src'; | ||
|
||
describe('Overview Aggregations', () => { | ||
it('should provide overview analysis', (done) => { | ||
getOverviewAnalysis((error, report) => { | ||
expect(error).to.not.exist; | ||
expect(report).to.exist.and.be.an('object'); | ||
expect(report.data).to.exist.and.be.an('object'); | ||
expect(report.data.parties).to.be.eql({ | ||
total: 4, | ||
agency: 2, | ||
focal: 2, | ||
level: 4, // FIX | ||
area: 4, // FIX | ||
group: 4, // FIX | ||
role: 4, // FIX | ||
active: 4, | ||
inactive: 0, | ||
}); | ||
done(error, report); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters