UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.5 kB
const async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"search",function($req$$,$callback$$){if(!$req$$.query.collections)return $callback$$("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.mapLimit($cols$$,20,function($collection$$,$callback$$){var $collection_goc_model$$=$collection$$;$collection$$=="dmkh"&&($collection_goc_model$$= "customer");$collection$$=="dmtk"&&($collection_goc_model$$="account");$collection$$=="dmnt"&&($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($k$$=="title"||$k$$.indexOf("ten_")===0){$field_title$$=$k$$;break}$r$$.collection_name=$collection$$;$r$$.title=$r$$[$field_title$$];$report$$.push($r$$)});$callback$$(null)})},function($e$$){if($e$$)return $callback$$($e$$);$callback$$(null,$report$$)})})};