af6b2d06b93361e4c31688bee783af50fdac848d
[motion-next.git] / server / api / intVtigerField / intVtigerField.controller.js
1 const a395_0x4e2e=['fieldName','error','lodash','model','nolimit','status','rows','attributes','end','VtigerField','type','destroy','findOne','merge','query','VIRTUAL','body','catch','filter','filters','fields','sort','pick','options','send','stack','create','intersection','include','limit','name','count','index','like','show','includeAll','sequelize','update','length','offset','undefined','params','where','sendStatus','map','key','../../mysqldb','Content-Range','then'];(function(_0x27b919,_0x4f2035){const _0x4e2eef=function(_0x24e71c){while(--_0x24e71c){_0x27b919['push'](_0x27b919['shift']());}};_0x4e2eef(++_0x4f2035);}(a395_0x4e2e,0x1dc));const a395_0x24e7=function(_0x27b919,_0x4f2035){_0x27b919=_0x27b919-0x68;let _0x4e2eef=a395_0x4e2e[_0x27b919];return _0x4e2eef;};const a395_0x1899c8=a395_0x24e7;'use strict';const _=require(a395_0x1899c8(0x78)),qs=require('../../components/parsers/qs'),logger=require('../../config/logger')('api'),{db}=require(a395_0x1899c8(0x73)),{Op}=require(a395_0x1899c8(0x69));function respondWithResult(_0x1581af,_0x56fe57){return _0x56fe57=_0x56fe57||0xc8,function(_0x44b95b){const _0x197a98=a395_0x24e7;if(_0x44b95b)return _0x1581af[_0x197a98(0x7b)](_0x56fe57)['json'](_0x44b95b);};}function respondWithFilteredResult(_0xf9d89e,_0x1bad75){return function(_0x4a29e5){const _0x2ea97f=a395_0x24e7;if(_0x4a29e5){const _0x25891e=_0x4a29e5[_0x2ea97f(0x95)],_0x436f13=_0x1bad75['offset'];let _0x3f2871=_0x1bad75[_0x2ea97f(0x6c)]+_0x1bad75[_0x2ea97f(0x93)],_0x36071c;return _0x3f2871>=_0x25891e?(_0x3f2871=_0x25891e,_0x36071c=0xc8):_0x36071c=0xce,_0xf9d89e['status'](_0x36071c),_0xf9d89e['set'](_0x2ea97f(0x74),_0x436f13+'-'+_0x3f2871+'/'+_0x25891e)['json'](_0x4a29e5);}return null;};}function saveUpdates(_0x4fe334){return function(_0x2c7869){const _0x5dc448=a395_0x24e7;if(_0x2c7869)return _0x2c7869[_0x5dc448(0x6a)](_0x4fe334)[_0x5dc448(0x75)](function(_0x35c862){return _0x35c862;});return null;};}function removeEntity(_0x31e47e){return function(_0x171aa2){const _0x386853=a395_0x24e7;if(_0x171aa2)return _0x171aa2[_0x386853(0x81)]()[_0x386853(0x75)](function(){const _0x23abde=_0x386853;_0x31e47e[_0x23abde(0x7b)](0xcc)[_0x23abde(0x7e)]();});};}function handleEntityNotFound(_0x5987c4){return function(_0x4f8678){const _0x5dc987=a395_0x24e7;return!_0x4f8678&&_0x5987c4[_0x5dc987(0x70)](0x194),_0x4f8678;};}function handleError(_0x468efc,_0x8ac62e){return _0x8ac62e=_0x8ac62e||0x1f4,function(_0xb87da2){const _0x4ccc92=a395_0x24e7;logger[_0x4ccc92(0x77)](_0xb87da2[_0x4ccc92(0x8f)]),_0xb87da2[_0x4ccc92(0x94)]&&delete _0xb87da2[_0x4ccc92(0x94)],_0x468efc[_0x4ccc92(0x7b)](_0x8ac62e)[_0x4ccc92(0x8e)](_0xb87da2);};}exports[a395_0x1899c8(0x96)]=function(_0x4f14a8,_0x3657b4){const _0x59ff3d=a395_0x1899c8;let _0x22aabe={};const _0x1fda45={},_0x443842={'count':0x0,'rows':[]},_0x4e2225=_['map'](db[_0x59ff3d(0x7f)]['rawAttributes'],function(_0x11acda){const _0x5d9f6d=_0x59ff3d;return{'name':_0x11acda[_0x5d9f6d(0x76)],'type':_0x11acda[_0x5d9f6d(0x80)][_0x5d9f6d(0x72)]};});_0x1fda45[_0x59ff3d(0x79)]=_[_0x59ff3d(0x71)](_0x4e2225,_0x59ff3d(0x94)),_0x1fda45[_0x59ff3d(0x84)]=_['keys'](_0x4f14a8['query']),_0x1fda45[_0x59ff3d(0x89)]=_[_0x59ff3d(0x91)](_0x1fda45[_0x59ff3d(0x79)],_0x1fda45[_0x59ff3d(0x84)]),_0x22aabe[_0x59ff3d(0x7d)]=_['intersection'](_0x1fda45[_0x59ff3d(0x79)],qs[_0x59ff3d(0x8a)](_0x4f14a8[_0x59ff3d(0x84)]['fields'])),_0x22aabe[_0x59ff3d(0x7d)]=_0x22aabe[_0x59ff3d(0x7d)]['length']?_0x22aabe[_0x59ff3d(0x7d)]:_0x1fda45[_0x59ff3d(0x79)];typeof _0x4f14a8['query'][_0x59ff3d(0x7a)]===_0x59ff3d(0x6d)&&(_0x22aabe['limit']=qs['limit'](_0x4f14a8[_0x59ff3d(0x84)][_0x59ff3d(0x93)]),_0x22aabe[_0x59ff3d(0x6c)]=qs[_0x59ff3d(0x6c)](_0x4f14a8[_0x59ff3d(0x84)][_0x59ff3d(0x6c)]));_0x22aabe['order']=qs[_0x59ff3d(0x8b)](_0x4f14a8[_0x59ff3d(0x84)][_0x59ff3d(0x8b)]),_0x22aabe[_0x59ff3d(0x6f)]=qs[_0x59ff3d(0x89)](_[_0x59ff3d(0x8c)](_0x4f14a8[_0x59ff3d(0x84)],_0x1fda45['filters']),_0x4e2225);_0x4f14a8[_0x59ff3d(0x84)]['filter']&&(_0x22aabe[_0x59ff3d(0x6f)]=_[_0x59ff3d(0x83)](_0x22aabe[_0x59ff3d(0x6f)],{[Op['or']]:_['map'](_0x4e2225,function(_0x383c21){const _0x55b59d=_0x59ff3d;if(_0x383c21['type']!==_0x55b59d(0x85)){const _0x35af90={};return _0x35af90[_0x383c21[_0x55b59d(0x94)]]={[Op[_0x55b59d(0x97)]]:'%'+_0x4f14a8[_0x55b59d(0x84)][_0x55b59d(0x88)]+'%'},_0x35af90;}})}));_0x22aabe=_[_0x59ff3d(0x83)]({},_0x22aabe,_0x4f14a8[_0x59ff3d(0x8d)]);const _0x3babcb={'where':_0x22aabe[_0x59ff3d(0x6f)]};return db['VtigerField'][_0x59ff3d(0x95)](_0x3babcb)[_0x59ff3d(0x75)](function(_0x1ff29d){const _0x2d89e0=_0x59ff3d;return _0x443842[_0x2d89e0(0x95)]=_0x1ff29d,_0x4f14a8[_0x2d89e0(0x84)][_0x2d89e0(0x68)]&&(_0x22aabe[_0x2d89e0(0x92)]=[{'all':!![]}]),db[_0x2d89e0(0x7f)]['findAll'](_0x22aabe);})[_0x59ff3d(0x75)](function(_0x4921b6){const _0x51c245=_0x59ff3d;return _0x443842[_0x51c245(0x7c)]=_0x4921b6,_0x443842;})[_0x59ff3d(0x75)](respondWithFilteredResult(_0x3657b4,_0x22aabe))[_0x59ff3d(0x87)](handleError(_0x3657b4,null));},exports[a395_0x1899c8(0x98)]=function(_0x46a631,_0x1f08ba){const _0x1c4672=a395_0x1899c8;let _0x593979={'raw':!![],'where':{'id':_0x46a631[_0x1c4672(0x6e)]['id']}};const _0x157cc8={};return _0x157cc8[_0x1c4672(0x79)]=_['keys'](db[_0x1c4672(0x7f)]['rawAttributes']),_0x157cc8[_0x1c4672(0x84)]=_['keys'](_0x46a631[_0x1c4672(0x84)]),_0x157cc8[_0x1c4672(0x89)]=_[_0x1c4672(0x91)](_0x157cc8[_0x1c4672(0x79)],_0x157cc8[_0x1c4672(0x84)]),_0x593979['attributes']=_[_0x1c4672(0x91)](_0x157cc8[_0x1c4672(0x79)],qs[_0x1c4672(0x8a)](_0x46a631['query']['fields'])),_0x593979[_0x1c4672(0x7d)]=_0x593979[_0x1c4672(0x7d)][_0x1c4672(0x6b)]?_0x593979[_0x1c4672(0x7d)]:_0x157cc8[_0x1c4672(0x79)],_0x46a631[_0x1c4672(0x84)][_0x1c4672(0x68)]&&(_0x593979[_0x1c4672(0x92)]=[{'all':!![]}]),_0x593979=_[_0x1c4672(0x83)]({},_0x593979,_0x46a631[_0x1c4672(0x8d)]),db[_0x1c4672(0x7f)]['findOne'](_0x593979)['then'](handleEntityNotFound(_0x1f08ba,null))['then'](respondWithResult(_0x1f08ba,null))['catch'](handleError(_0x1f08ba,null));},exports['create']=function(_0x522a35,_0x4357a6){const _0x4e2029=a395_0x1899c8;return db[_0x4e2029(0x7f)][_0x4e2029(0x90)](_0x522a35['body'],{})[_0x4e2029(0x75)](respondWithResult(_0x4357a6,0xc9))[_0x4e2029(0x87)](handleError(_0x4357a6,null));},exports[a395_0x1899c8(0x6a)]=function(_0x411ad7,_0x5df637){const _0xaf1438=a395_0x1899c8;return _0x411ad7[_0xaf1438(0x86)]['id']&&delete _0x411ad7[_0xaf1438(0x86)]['id'],db[_0xaf1438(0x7f)]['findOne']({'where':{'id':_0x411ad7['params']['id']}})[_0xaf1438(0x75)](handleEntityNotFound(_0x5df637,null))[_0xaf1438(0x75)](saveUpdates(_0x411ad7[_0xaf1438(0x86)],null))[_0xaf1438(0x75)](respondWithResult(_0x5df637,null))['catch'](handleError(_0x5df637,null));},exports[a395_0x1899c8(0x81)]=function(_0x10f872,_0x51fc11){const _0x23073c=a395_0x1899c8;return db[_0x23073c(0x7f)][_0x23073c(0x82)]({'where':{'id':_0x10f872[_0x23073c(0x6e)]['id']}})['then'](handleEntityNotFound(_0x51fc11,null))[_0x23073c(0x75)](removeEntity(_0x51fc11,null))['catch'](handleError(_0x51fc11,null));};