forked from project-sunbird/sunbird-report-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicCategoryManager.js
More file actions
26 lines (22 loc) · 930 Bytes
/
dynamicCategoryManager.js
File metadata and controls
26 lines (22 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const _ = require('lodash');
const { channelRead, frameworkRead } = require('../../helpers/learnerHelper');
const debug = require('debug')('dynamicCategoryManager');
class DynamicCategoryManager {
async getCategoriesForChannel(channelId) {
try {
const channelReadResponse = await channelRead({ channelId });
const frameworkName = _.get(channelReadResponse, 'data.result.channel.defaultFramework');
if (!frameworkName) {
throw new Error('Default framework missing');
}
const frameworkReadResponse = await frameworkRead({ frameworkId: frameworkName });
const frameworkData = _.get(frameworkReadResponse, 'data.result.framework');
const categories = _.map(frameworkData.categories, 'code');
return categories;
} catch (error) {
debug('Failed to fetch framework categories', error);
return [];
}
}
}
module.exports = new DynamicCategoryManager();