feat: convert categories controller to async/await

v1.18.x
Baris Usakli 6 years ago
parent 90bcd65a00
commit e9fd49e234

@ -1,15 +1,14 @@
'use strict';
var async = require('async');
var nconf = require('nconf');
const nconf = require('nconf');
var categories = require('../categories');
var meta = require('../meta');
var helpers = require('./helpers');
const categories = require('../categories');
const meta = require('../meta');
const helpers = require('./helpers');
var categoriesController = module.exports;
const categoriesController = module.exports;
categoriesController.list = function (req, res, next) {
categoriesController.list = async function (req, res) {
res.locals.metaTags = [{
name: 'title',
content: String(meta.config.title || 'NodeBB'),
@ -18,20 +17,11 @@ categoriesController.list = function (req, res, next) {
content: 'website',
}];
var categoryData;
let tree;
async.waterfall([
function (next) {
categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find', next);
},
function (_categoryData, next) {
categoryData = _categoryData;
tree = categories.getTree(categoryData, 0);
categories.getRecentTopicReplies(categoryData, req.uid, next);
},
function () {
var data = {
const categoryData = await categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find');
const tree = categories.getTree(categoryData, 0);
await categories.getRecentTopicReplies(categoryData, req.uid);
const data = {
title: meta.config.homePageTitle || '[[pages:home]]',
categories: tree,
};
@ -57,6 +47,4 @@ categoriesController.list = function (req, res, next) {
});
res.render('categories', data);
},
], next);
};

Loading…
Cancel
Save