2021-10-22 15:00:38 +03:00
|
|
|
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
|
|
const Bookmark = require('../../models/Bookmark');
|
|
|
|
const { Sequelize } = require('sequelize');
|
2021-11-22 18:45:59 +03:00
|
|
|
const loadConfig = require('../../utils/loadConfig');
|
2021-10-22 15:00:38 +03:00
|
|
|
|
|
|
|
// @desc Get all bookmarks
|
|
|
|
// @route GET /api/bookmarks
|
|
|
|
// @access Public
|
|
|
|
const getAllBookmarks = asyncWrapper(async (req, res, next) => {
|
2021-11-22 18:45:59 +03:00
|
|
|
const { useOrdering: orderType } = await loadConfig();
|
|
|
|
|
2021-11-11 18:43:00 +03:00
|
|
|
// bookmarks visibility
|
|
|
|
const where = req.isAuthenticated ? {} : { isPublic: true };
|
|
|
|
|
2021-11-22 18:45:59 +03:00
|
|
|
const order =
|
|
|
|
orderType == 'name'
|
|
|
|
? [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
|
|
|
: [[orderType, 'ASC']];
|
|
|
|
|
2021-10-22 15:00:38 +03:00
|
|
|
const bookmarks = await Bookmark.findAll({
|
2021-11-22 18:45:59 +03:00
|
|
|
order,
|
2021-11-11 18:43:00 +03:00
|
|
|
where,
|
2021-10-22 15:00:38 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: bookmarks,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = getAllBookmarks;
|