增删查改

后台系统,最多的页面就是各种表格、表单,最多的接口就是增删查改。
云函数QPS 200次/s,一个接口并发限制200。
个人系统用不了太多,所以我又偷懒了, 直接一个模块的增删查改放一个路由里,调同一个函数。

角色模块

import baseModel from './models/index';
import roleModel from './models/role';
import dao from './dao/index';
import { EBaseAction } from './interfaces/index';
module.exports.main = async (event, context) => {
    if (!event || !event.queryStringParameters) {
        return baseModel.errorParams;
    }
    let action: EBaseAction = event.queryStringParameters.action || null;
    let params = roleModel.orm(event.queryStringParameters.params);
    let options = dao.baseOptions(event.queryStringParameters.options || {});
    console.log('action=>', action);
    console.log('params=>', params);
    console.log('options=>', options);
    if (!params.systemId || !action) {
        return baseModel.errorParams;
    }
    let result: any = baseModel.error();

    switch (action) {
        case EBaseAction.add:
            result = await dao.add('t_role', params);
            break
        case EBaseAction.delete:
            result = await dao.delete('t_role', params);
            break;
        case EBaseAction.update:
            result = await dao.update('t_role', params);
            break;
        case EBaseAction.select:
            let total: any = await dao.count(
                't_role',
                roleModel.selctOrm(event.queryStringParameters.params)
            );
            result = await dao.select(
                't_role',
                roleModel.selctOrm(event.queryStringParameters.params),
                { ...options, total }
            );
            break;
        default:
            result = baseModel.error({ msg: 'action error' });
    }

    return result;
};
  • dao层放的数据库操作
  • todo:
    • 入参统一格式化
    • 装饰器;count获取优化

results matching ""

    No results matching ""