-
Notifications
You must be signed in to change notification settings - Fork 101
/
getDocFromAlias.js
33 lines (27 loc) · 1.04 KB
/
getDocFromAlias.js
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
27
28
29
30
31
32
33
var _ = require('lodash');
/**
* @dgService getDocFromAlias
* @description Get an array of docs that match this alias, relative to the originating doc.
*/
module.exports = function getDocFromAlias(aliasMap, log) {
return function getDocFromAlias(alias, originatingDoc) {
var docs = aliasMap.getDocs(alias);
// If there is more than one item with this name then try to filter them by the originatingDoc's area
if ( docs.length > 1 && originatingDoc && originatingDoc.area) {
docs = _.filter(docs, function(doc) {
return doc.area === originatingDoc.area;
});
}
// If filtering by area left us with none then let's start again
if ( docs.length === 0 ) {
docs = aliasMap.getDocs(alias);
}
// If there is more than one item with this name then try to filter them by the originatingDoc's module
if ( docs.length > 1 && originatingDoc && originatingDoc.module ) {
docs = _.filter(docs, function(doc) {
return doc.module === originatingDoc.module;
});
}
return docs;
};
};