var express = require('express');
var router = express.Router();

var log = require('../util/log.js');

var APIv1 = require('../include/endpoints').APIv1;

var msgStats = require("../repository/stats.msg.repo.js");

/**
 * 获取应用角标数。
 *
 * chats/badge_no?user_id=sand
 *
 * 参数：
 * uid：用户id
 */
router.get(APIv1.Application.BadgeNo, function (req, res) {
    var userId = req.query.user_id;

    msgStats.getBadgeNumber(userId, function (err, result) {
        if (err) {
            console.error("Get badge number failed: ", err);

            res.status(500).send({message: "Get badge number failed."});
            return;
        }

        var data = {userId: userId, badge: result};
        res.send(data);
    });
});

module.exports = router;