forked from project-sunbird/sunbird-report-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistrict.js
More file actions
19 lines (17 loc) · 695 Bytes
/
district.js
File metadata and controls
19 lines (17 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const _ = require('lodash');
/**
* @description accesspath rule definition for user's district location
*
*/
module.exports = {
ruleName: 'district',
isMatch(user, payload) {
payload = Array.isArray(payload) ? payload : [payload];
const userProfileLocation = _.get(user, 'profileLocation') || _.get(user, 'userLocations');
if (!userProfileLocation) return false;
if (!Array.isArray(userProfileLocation)) return false;
const userDistrict = _.find(userProfileLocation, location => _.get(location, 'type') === 'district');
if (!(userDistrict && ('id' in userDistrict))) return false;
return _.some(payload, locationId => locationId === userDistrict.id);
}
};