UNPKG

flexbiz-server

Version:

Flexible Server

4 lines (3 loc) 873 B
'use strict';module.exports=function($schema$$){$schema$$.post("find",attachId);$schema$$.post("findOne",attachId);$schema$$.post("findOneAndUpdate",attachId)}; function attachId($res$$){function $replaceId$$($res$$){if(Array.isArray($res$$))$res$$.forEach($v$$=>{isObjectId($v$$)||($v$$&&$v$$._id&&($v$$._id=$v$$._id.toString()),$v$$&&Object.keys($v$$).map($k$$=>{Array.isArray($v$$[$k$$])&&$replaceId$$($v$$[$k$$])}))});else{if(isObjectId($res$$))return $res$$;$res$$._id&&($res$$._id=$res$$._id.toString());Object.keys($res$$).map($k$$=>{Array.isArray($res$$[$k$$])&&$replaceId$$($res$$[$k$$])})}}$res$$&&this._mongooseOptions.lean&&$replaceId$$($res$$)} function isObjectId($v$$){if(null==$v$$)return!1;const $proto$$=Object.getPrototypeOf($v$$);return null==$proto$$||null==$proto$$.constructor||"ObjectID"!==$proto$$.constructor.name?!1:"ObjectID"===$v$$._bsontype};