Browse Source

getConstellationTimeline

develop
Rob Colbert 2 years ago
parent
commit
e457a76f94
  1. 6
      app/controllers/home.js
  2. 22
      app/services/hive.js

6
app/controllers/home.js

@ -63,9 +63,13 @@ class HomeController extends SiteController {
}
async getHome (req, res, next) {
const { announcement: announcementService } = this.dtp.services;
const { announcement: announcementService, hive: hiveService } = this.dtp.services;
try {
res.locals.announcements = await announcementService.getLatest(req.user);
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.constellationTimeline = await hiveService.getConstellationTimeline(req.user, res.locals.pagination);
res.render('index');
} catch (error) {
this.log.error('failed to render home view', { error });

22
app/services/hive.js

@ -251,6 +251,28 @@ class HiveService extends SiteService {
return event.toObject();
}
async getConstellationTimeline (user, pagination) {
const totalEventCount = await KaleidoscopeEvent.estimatedDocumentCount();
const job = { };
if (user) {
job.search = {
$or: [
{ recipient: { $exists: false } },
{ recipient: user._id },
],
};
} else {
job.search = { recipient: { $exists: false } };
}
const events = await KaleidoscopeEvent
.find(job.search)
.sort({ created: -1 })
.skip(pagination.skip)
.limit(pagination.cpp)
.lean();
return { events, totalEventCount };
}
}
module.exports = {

Loading…
Cancel
Save