mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-20 16:51:47 +03:00
32 lines
831 B
JavaScript
32 lines
831 B
JavaScript
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
const Bookmark = require('../../models/Bookmark');
|
|
const { Sequelize } = require('sequelize');
|
|
const loadConfig = require('../../utils/loadConfig');
|
|
|
|
// @desc Get all bookmarks
|
|
// @route GET /api/bookmarks
|
|
// @access Public
|
|
const getAllBookmarks = asyncWrapper(async (req, res, next) => {
|
|
const { useOrdering: orderType } = await loadConfig();
|
|
|
|
// bookmarks visibility
|
|
const where = req.isAuthenticated ? {} : { isPublic: true };
|
|
|
|
const order =
|
|
orderType == 'name'
|
|
? [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
|
: [[orderType, 'ASC']];
|
|
|
|
const bookmarks = await Bookmark.findAll({
|
|
order,
|
|
where,
|
|
});
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
data: bookmarks,
|
|
});
|
|
});
|
|
|
|
module.exports = getAllBookmarks;
|