/**
 * 青岛博物馆用户注册登录接口
 */
import asyncHandler from 'express-async-handler';
import * as usersBiz from '../biz/users';
import { eccReqParamater } from '../util/verificationParam';

export function setRouter(httpServer) {
    /** 用户注册 */
    httpServer.post('/api/qdm/user/register', asyncHandler(registerUser));

    /** 用户登录 */
    httpServer.post('/api/qdm/user/login', asyncHandler(login));

    /**
     * 注册信息
     */
    async function registerUser(req, res) {
        let reqConf = {username:'String', password:'String', name:'String'};
        const NotMustHaveKeys = [];
        let { username, password, name } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
        const result = await usersBiz.registerUser(username, password, name);
        res.success(result);
    }
    
    /**
     * 登录信息
     */
    async function login(req, res) {
        let reqConf = {username:'String', password:'String'};
        const NotMustHaveKeys = [];
        let { username, password } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
        const result = await usersBiz.adminLogin(username, password);
        res.success(result);
    }
}