2021-10-22 15:00:38 +03:00
|
|
|
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
|
|
const Bookmark = require('../../models/Bookmark');
|
|
|
|
const { Sequelize } = require('sequelize');
|
|
|
|
|
|
|
|
// @desc Get all bookmarks
|
|
|
|
// @route GET /api/bookmarks
|
|
|
|
// @access Public
|
|
|
|
const getAllBookmarks = asyncWrapper(async (req, res, next) => {
|
2021-11-11 18:43:00 +03:00
|
|
|
// bookmarks visibility
|
|
|
|
const where = req.isAuthenticated ? {} : { isPublic: true };
|
|
|
|
|
2021-10-22 15:00:38 +03:00
|
|
|
const bookmarks = await Bookmark.findAll({
|
|
|
|
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']],
|
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;
|