Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter notifications by severity #383

Open
mueller-ma opened this issue Sep 23, 2022 · 1 comment
Open

Filter notifications by severity #383

mueller-ma opened this issue Sep 23, 2022 · 1 comment

Comments

@mueller-ma
Copy link
Member

I'd like to filter the notification list in the Android app by severity, but for this the notifications API needs to be extended:

  1. Add an endpoint that returns all severities used in the last X days. X could be hardcoded to e.g. 60.
  2. Add a query parameter to the current notification endpoint, e.g. &severity="high"
@iPavel89-work
Copy link

iPavel89-work commented Jun 28, 2024

file routes/api.js

exports.notificationsget = function (req, res) {
    var limit = req.query.limit > 0 ? parseInt(req.query.limit) : 10,
        skip = req.query.skip > 0 ? parseInt(req.query.skip) : 0;
    var filter = { user: req.user.id };

    // Добавляем фильтр по параметру severity, если он указан в запросе
    if (req.query.severity) {
        filter.severity = req.query.severity;
    }
    
    Notification.find(filter, '-user')
        .limit(limit)
        .skip(skip)
        .sort({ created: 'desc' })
        .exec(function (error, notifications) {
            if (!error) {
                res.status(200).json(notifications);
            } else {
                return res.status(500).json({
                    errors: [{
                        message: "Error getting notifications"
                    }]
                });
            }
        });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants