const API = require("../../../lib/API");
const db = require("../../../plugin/DataBase/db");
const AccessControl = require("../../../lib/AccessControl");
const { BaseStdResponse } = require("../../../BaseStdResponse");

class GetStarGroup extends API {
    constructor() {
        super();

        this.setPath('/IC/StarGroup')
        this.setMethod('GET')
    }

    async onRequest(req, res) {
        let {
            uuid,
            session
        } = req.query

        if ([uuid, session].some(value => value === '' || value === null || value === undefined))
            return res.json({
                ...BaseStdResponse.MISSING_PARAMETER
            })

        // 检查 session
        if (!await AccessControl.checkSession(uuid, session))
            return res.status(401).json({
                ...BaseStdResponse.ACCESS_DENIED
            })

        let sql = 'SELECT * FROM ic_star_group WHERE create_user = ?'
        let rows = await db.query(sql, [uuid])

        if (!rows)
            return res.json({
                ...BaseStdResponse.MISSING_FILE,
                msg: '获取志愿组列表失败！'
            })

        res.json({
            ...BaseStdResponse.OK,
            data: rows
        })
    }
}

module.exports.GetStarGroup = GetStarGroup;