2016-09-23 13:31:33 +03:00
|
|
|
import Authors from './collection.js';
|
|
|
|
import Posts from '../posts/collection.js';
|
|
|
|
import Comments from '../comments/collection.js';
|
|
|
|
import Groups from '../groups/collection.js';
|
|
|
|
|
|
|
|
Authors.addLinks({
|
|
|
|
comments: {
|
|
|
|
collection: Comments,
|
|
|
|
inversedBy: 'author'
|
|
|
|
},
|
|
|
|
posts: {
|
|
|
|
collection: Posts,
|
|
|
|
inversedBy: 'author'
|
|
|
|
},
|
|
|
|
groups: {
|
|
|
|
type: 'many',
|
2017-11-23 21:09:14 +02:00
|
|
|
metadata: true,
|
2016-09-23 13:31:33 +03:00
|
|
|
collection: Groups,
|
|
|
|
field: 'groupIds'
|
|
|
|
}
|
2016-11-21 13:28:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
Authors.addReducers({
|
|
|
|
fullName: {
|
|
|
|
body: {
|
|
|
|
name: 1
|
|
|
|
},
|
|
|
|
reduce(object) {
|
|
|
|
return 'full - ' + object.name;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
groupNames: {
|
|
|
|
body: {
|
|
|
|
groups: {
|
|
|
|
name: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reduce(object) {
|
|
|
|
if (object.groups) {
|
|
|
|
return object.groups.map(group => 'G#' + group.name);
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 13:36:12 +02:00
|
|
|
},
|
|
|
|
referenceReducer: {
|
|
|
|
body: {
|
|
|
|
fullName: 1
|
|
|
|
},
|
|
|
|
reduce(object) {
|
|
|
|
return 'nested - ' + object.fullName;
|
|
|
|
}
|
2016-11-21 14:56:17 +02:00
|
|
|
},
|
|
|
|
fullNameNested: {
|
|
|
|
body: {
|
|
|
|
profile: {
|
|
|
|
firstName: 1,
|
|
|
|
lastName: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reduce(object) {
|
|
|
|
if (!object.profile) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object.profile.firstName + ' ' + object.profile.lastName;
|
|
|
|
}
|
2016-11-21 13:28:15 +02:00
|
|
|
}
|
2016-09-23 13:31:33 +03:00
|
|
|
});
|