mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-20 12:09:36 +02:00
Split remaining controllers into separate files. Added iOS homescreen icon. Removed additional logging from weather module.
This commit is contained in:
parent
88694c7e27
commit
4ed29fe276
32 changed files with 418 additions and 312 deletions
43
controllers/categories/getAllCategories.js
Normal file
43
controllers/categories/getAllCategories.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const Category = require('../../models/Category');
|
||||
const Bookmark = require('../../models/Bookmark');
|
||||
const { Sequelize } = require('sequelize');
|
||||
const loadConfig = require('../../utils/loadConfig');
|
||||
|
||||
// @desc Get all categories
|
||||
// @route GET /api/categories
|
||||
// @access Public
|
||||
const getAllCategories = asyncWrapper(async (req, res, next) => {
|
||||
const { useOrdering: orderType } = await loadConfig();
|
||||
|
||||
let categories;
|
||||
|
||||
if (orderType == 'name') {
|
||||
categories = await Category.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
},
|
||||
],
|
||||
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
|
||||
});
|
||||
} else {
|
||||
categories = await Category.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
},
|
||||
],
|
||||
order: [[orderType, 'ASC']],
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: categories,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = getAllCategories;
|
Loading…
Add table
Add a link
Reference in a new issue