
import {
    getUsers,
    getGroups
} from "../../lib/mysql.mjs";


export const get = async function (request, response) {
    // if (!request.isLoginCompleted()) {
    //     response.redirect('/login');
    //     return;
    // }

    switch (request.params.page) {
        case 'users':
            response.render(`ui/admin.njk`, {
                page: 'users',
                users: await getUsers()
            });
            break;
        case 'groups':
            response.render(`ui/admin.njk`, {
                page: 'groups',
                groups: await getGroups()
            });
            break;
        default:
            response.redirect('/admin/users');
            break;
    }
}

export const post = async function (request, response) {
    console.log(request.body);
    response.redirect("/login");
}