flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.59 kB
JavaScript
'use strict';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.mapSeries(underscore.keys($obj$$.schema.validate),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!1===
$valid$$?($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$jscomp$0$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);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$$))}0<$valid_path$$.length?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$$)};