trigger pages and posts recording views only when published

master
Andrew 1 year ago
parent 1631c74a8a
commit e5a8171087

1
.gitignore vendored

@ -7,3 +7,4 @@ data/minio
data/minio.old
node_modules
dist
start-local-*

@ -51,7 +51,9 @@ class PageController extends SiteController {
async getView (req, res, next) {
const { resource: resourceService } = this.dtp.services;
try {
await resourceService.recordView(req, 'Page', res.locals.page._id);
if (res.locals.page.status === 'published') {
await resourceService.recordView(req, 'Page', res.locals.page._id);
}
res.locals.pageSlug = res.locals.page.slug;
res.locals.pageTitle = `${res.locals.page.title} on ${this.dtp.config.site.name}`;
res.render('page/view');

@ -277,8 +277,9 @@ class PostController extends SiteController {
throw new SiteError(403, 'The post is not published');
}
}
await resourceService.recordView(req, 'Post', res.locals.post._id);
if (res.locals.post.status === 'published') {
await resourceService.recordView(req, 'Post', res.locals.post._id);
}
res.locals.countPerPage = 20;
res.locals.pagination = this.getPaginationParameters(req, res.locals.countPerPage);

Loading…
Cancel
Save