1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 03:29:37 +02:00

Preparation for custom sorting

This commit is contained in:
unknown 2021-06-17 10:56:27 +02:00
parent ce173f2c42
commit 8974fb3b49
7 changed files with 42 additions and 7 deletions

View file

@ -36,13 +36,24 @@ exports.createApp = asyncWrapper(async (req, res, next) => {
// @route GET /api/apps
// @access Public
exports.getApps = asyncWrapper(async (req, res, next) => {
// const apps = await App.findAll({
// order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
// });
const apps = await App.findAll({
order: [[ 'orderId', 'ASC' ]]
// Get config from database
const useOrdering = await Config.findOne({
where: { key: 'useOrdering' }
});
const orderType = useOrdering ? useOrdering.value : 'createdAt';
let apps;
if (orderType == 'name') {
apps = await App.findAll({
order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]]
});
} else {
apps = await App.findAll({
order: [[ orderType, 'ASC' ]]
});
}
res.status(200).json({
success: true,
data: apps