UNPKG

flexbiz-server

Version:

Flexible Server

6 lines (5 loc) 2 kB
const dmchietkhau=global.getModel("dmchietkhau"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),dmvt=global.getModel("dmvt"); module.exports=function($router$$){new controller($router$$,"getcschietkhau",function($query_req$$,$callback$$){const $condition$$=$query_req$$.query;if(!$condition$$.ma_vt)return $callback$$("Ch\u1ee9c n\u0103ng n\u00e0y y\u00eau c\u1ea7u tham s\u1ed1: ma_vt");$condition$$.id_app=$query_req$$.user.current_id_app;$query_req$$={ma_vt:$condition$$.ma_vt,id_app:$condition$$.id_app,status:!0};$condition$$.nh_kh&&($query_req$$.nh_kh={$or:[{$eq:null},{$eq:$condition$$.nh_kh}]});$condition$$.ma_kh&&($query_req$$.ma_kh= {$or:[{$eq:null},{$eq:$condition$$.ma_kh}]});$condition$$.ma_kho&&($query_req$$.ma_kho={$or:[{$eq:null},{$eq:$condition$$.ma_kho}]});if($condition$$.ngay_ct)try{$condition$$.ngay_ct=new Date($condition$$.ngay_ct)}catch($e$$){return $callback$$($e$$.message)}else $condition$$.ngay_ct=new Date;let $hieu_luc_tu$$;var $hieu_luc_den_tu_ngay$$=moment($condition$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu$$={$lte:moment($condition$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_tu_ngay$$={$gte:$hieu_luc_den_tu_ngay$$}; $query_req$$.hieu_luc_tu=$hieu_luc_tu$$;$query_req$$.hieu_luc_den=$hieu_luc_den_tu_ngay$$;let $query_ck$$=Object.assign({},$query_req$$);dmvt.findOne({ma_vt:$condition$$.ma_vt,id_app:$condition$$.id_app}).lean().exec(($e$$,$vt$$)=>{if($e$$||!$vt$$)return $callback$$($e$$||$condition$$.ma_vt+" is not exists");dmchietkhau.find($query_ck$$).populate("dmvt").exec(($_q_e$$,$rs$$)=>{if($_q_e$$)return $callback$$($_q_e$$);if($rs$$.length>0)return $callback$$(null,$rs$$.map($r$$=>$r$$.toJSON()));$_q_e$$= Object.assign({},$query_ck$$);$_q_e$$.ma_vt={$in:["",null,void 0]};$_q_e$$.ma_nvt={$in:["",null,void 0,$vt$$.ma_nvt]};dmchietkhau.find($_q_e$$).populate("dmvt").exec(($e$$,$chietkhau$$)=>{if($e$$)return $callback$$($e$$);$callback$$(null,$chietkhau$$.map($c$$=>$c$$.toJSON()))})})})},{cache:!1})};