flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 1.74 kB
JavaScript
const chamcong=global.getModel("chamcong"),controller=require("../../controllers/controllerRPT"),async=require("async"),permission=require("../../libs/permission");
module.exports=function($router$$){new controller($router$$,"bkchamcong",function($req$$,$callback$$){let $id_apps$$=$req$$.query.id_apps;$req$$.query.id_apps&&$req$$.query.id_apps.length!=0||($id_apps$$=[$req$$.query.id_app]);async.map($id_apps$$,($id_app$$,$callback$$)=>{permission.hasRight($id_app$$,$req$$.user.email,"chamcong","view",async function($error$$,$permission$$){if(!$permission$$)return $callback$$(`B\u1ea1n kh\u00f4ng c\u00f3 quy\u1ec1n v\u1edbi c\u00f4ng ty c\u00f3 id '${$id_app$$}'`);
$error$$={};$error$$.id_app=$id_app$$;$error$$.ngay={$gte:$req$$.query.tu_ngay,$lte:$req$$.query.den_ngay};$req$$.query.ma_nv&&($error$$.ma_nv=$req$$.query.ma_nv);$req$$.query.ma_bp&&($error$$.ma_bp=$req$$.query.ma_bp);chamcong.find($error$$).lean().then(async $congs$$=>{await $congs$$.asyncJoinModel2($id_app$$,"dmloaicong",[{where:{ma_loai_cong:"ma_loai_cong"},fields:["ten_loai_cong","color"]}]);await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmnv"),[{where:{ma_nv:"ma_nv"},fields:["ten_nv"]}]);
await $congs$$.asyncJoinModel2($id_app$$,global.getModel("dmbp"),[{where:{ma_bp:"ma_bp"},fields:["ten_bp"]}]);await $congs$$.filter($r$$=>$r$$.ma_kh).asyncJoinModel2($id_app$$,global.getModel("customer"),[{where:{ma_kh:"ma_kh"},fields:["ten_kh"]}]);$callback$$(null,$congs$$)}).catch($e$$=>{$callback$$($e$$)})})},async($e$$,$rs$$)=>{if($e$$)return $callback$$($e$$);$e$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);await $e$$.asyncJoinModel2(null,global.getModel("app"),[{where:{id_app:"_id"},fields:[{ten_cong_ty:"name"}]}]);
$callback$$(null,$e$$)})})};