-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path$board.js
More file actions
26 lines (24 loc) · 1.18 KB
/
$board.js
File metadata and controls
26 lines (24 loc) · 1.18 KB
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');
var debug = require('debug')('parameters:$board');
const { channelRead, frameworkRead } = require('../../helpers/learnerHelper');
module.exports = {
name: '$board',
value: (user) => _.get(user, 'framework.board'),
cache: false,
async masterData({ user, req }) {
try {
const channelId = req.get('x-channel-id') || req.get('X-CHANNEL-ID') || _.get(user, 'rootOrg.hashTagId') || _.get(user, 'channel');
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 boardCategory = _.find(frameworkData.categories, ['code', 'board']);
if (!_.get(boardCategory, 'terms') && !Array.isArray(boardCategory.terms)) { return of([]); }
return _.map(boardCategory.terms, 'name');
} catch (error) {
debug('$board masterData fetch failed', JSON.stringify(error));
return [];
}
}
};