UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.54 kB
'use strict';const async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"search",function($req$$,$callback$jscomp$0$$){if(!$req$$.query.collections)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: collections,value");const $report$$=[],$collections$$=JSON.parse("{"+$req$$.query.collections+"}"),$cols$$=underscore.keys($collections$$);async.mapSeries($cols$$,function($collection$$,$callback$$){var $collection_goc_model$$=$collection$$;"dmkh"==$collection$$&&($collection_goc_model$$= "customer");"dmtk"==$collection$$&&($collection_goc_model$$="account");"dmnt"==$collection$$&&($collection_goc_model$$="currency");$collection_goc_model$$=global.getModel(""+$collection_goc_model$$);const $query$$={id_app:$req$$.query.id_app,$or:[]};$collections$$[$collection$$].split(",").forEach(function($field$$){const $q$$={};$q$$[$field$$]={$regex:$req$$.query.value,$options:"i"};$query$$.$or.push($q$$)});$collection_goc_model$$.find($query$$).lean().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$); let $field_title$$;$rs$$.forEach(function($r$$){if(!$field_title$$)for(let $k$$ in $r$$)if("title"==$k$$||0===$k$$.indexOf("ten_")){$field_title$$=$k$$;break}$r$$.collection_name=$collection$$;$r$$.title=$r$$[$field_title$$];$report$$.push($r$$)});$callback$$(null)})},function($e$$){if($e$$)return $callback$jscomp$0$$($e$$);$callback$jscomp$0$$(null,$report$$)})})};