UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.55 kB
const async=require("async"),underscore=require("underscore"),valid=function($obj$$,$next$$,$id_app$$,$options$$={}){setImmediate(()=>{$id_app$$||($id_app$$=$obj$$.id_app);$obj$$.schema&&$obj$$.schema.validate?async.mapLimit(underscore.keys($obj$$.schema.validate),50,function($key$$,$callback$$){const $validField$$=$obj$$.schema.validate[$key$$],$value$$=$obj$$[$key$$];if(!$value$$)return $callback$$();let $msg$$=$validField$$[1];(0,$validField$$[0])($id_app$$,$value$$,function($valid$$){return $valid$$=== !1?($msg$$=$msg$$.replace("{PATH}",$key$$),$msg$$=$msg$$.replace("{VALUE}",$value$$),$callback$$($msg$$)):$callback$$()},$options$$)},function($error$$){if($error$$)return $next$$($error$$);$next$$()}):$next$$()})}; module.exports=function($obj$$,$next$$,$options$$={}){const $id_app$$=$obj$$.id_app;valid($obj$$,function($error$$){if($error$$)return $next$$($error$$);setImmediate(()=>{const $valid_path$$=[],$_push_valid_path$$=function($o$$){$valid_path$$.push($o$$)};for(let $key$$ in $obj$$.schema.paths){var $obj_d_path$$=$obj$$.schema.paths[$key$$];$obj_d_path$$.schema&&$obj_d_path$$.schema.validate&&($obj_d_path$$=$obj$$.get($key$$),underscore.isArray($obj_d_path$$)?$obj_d_path$$.forEach($_push_valid_path$$): $valid_path$$.push($obj_d_path$$))}$valid_path$$.length>0?async.each($valid_path$$,function($p$$,$callback$$){valid($p$$,function($error$$){if($error$$)return $callback$$($error$$);$callback$$()},$id_app$$,$options$$)},function($error$$){if($error$$)return $next$$($error$$);$next$$()}):$next$$()})},null,$options$$)};