Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / integration / integration.controller.js
index 7784930..77b0545 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x28f3=['type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','offset','order','sort','where','merge','VIRTUAL','filter','options','includeAll','include','rows','catch','show','params','keys','find','create','body','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','Content-Range','apply','update','then','destroy','stack','name','send','map','Integration','rawAttributes'];(function(_0x536f62,_0x1ecaf6){var _0x58dc3d=function(_0x59ee7a){while(--_0x59ee7a){_0x536f62['push'](_0x536f62['shift']());}};_0x58dc3d(++_0x1ecaf6);}(_0x28f3,0xec));var _0x328f=function(_0x3adfb0,_0x4ccb50){_0x3adfb0=_0x3adfb0-0x0;var _0x3a60bf=_0x28f3[_0x3adfb0];return _0x3a60bf;};'use strict';var pdf=require(_0x328f('0x0'));var emlformat=require(_0x328f('0x1'));var rimraf=require(_0x328f('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x328f('0x3'));var rp=require(_0x328f('0x4'));var moment=require(_0x328f('0x5'));var BPromise=require(_0x328f('0x6'));var Mustache=require(_0x328f('0x7'));var util=require(_0x328f('0x8'));var path=require(_0x328f('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x328f('0xa'));var fs=require('fs');var _=require(_0x328f('0xb'));var squel=require('squel');var crypto=require(_0x328f('0xc'));var jsforce=require(_0x328f('0xd'));var deskjs=require(_0x328f('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x328f('0xf'));var Redis=require(_0x328f('0x10'));var authService=require(_0x328f('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x328f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x328f('0x13'))(_0x328f('0x14'));var utils=require(_0x328f('0x15'));var config=require(_0x328f('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x328f('0x17'))['db'];function respondWithStatusCode(_0xa5626b,_0x4dc533){_0x4dc533=_0x4dc533||0xcc;return function(_0x2b1058){if(_0x2b1058){return _0xa5626b[_0x328f('0x18')](_0x4dc533);}return _0xa5626b['status'](_0x4dc533)[_0x328f('0x19')]();};}function respondWithResult(_0x571ff0,_0x42fd75){_0x42fd75=_0x42fd75||0xc8;return function(_0x544fe7){if(_0x544fe7){return _0x571ff0[_0x328f('0x1a')](_0x42fd75)[_0x328f('0x1b')](_0x544fe7);}};}function respondWithFilteredResult(_0x594ac5,_0x4da2dd){return function(_0x29698d){if(_0x29698d){var _0x4a5012=_0x29698d[_0x328f('0x1c')],_0xcca42=_0x4da2dd['offset'],_0x228a63=_0x4da2dd['offset']+_0x4da2dd['limit'],_0xa9a941;if(_0x228a63>=_0x4a5012){_0x228a63=_0x4a5012;_0xa9a941=0xc8;}else{_0xa9a941=0xce;}_0x594ac5[_0x328f('0x1a')](_0xa9a941);return _0x594ac5['set'](_0x328f('0x1d'),_0xcca42+'-'+_0x228a63+'/'+_0x4a5012)[_0x328f('0x1b')](_0x29698d);}return null;};}function patchUpdates(_0x2262ba){return function(_0x2fda25){try{jsonpatch[_0x328f('0x1e')](_0x2fda25,_0x2262ba,!![]);}catch(_0x563670){return BPromise['reject'](_0x563670);}return _0x2fda25['save']();};}function saveUpdates(_0x1d732c,_0x17b9c0){return function(_0x443b9c){if(_0x443b9c){return _0x443b9c[_0x328f('0x1f')](_0x1d732c)[_0x328f('0x20')](function(_0x4280f4){return _0x4280f4;});}return null;};}function removeEntity(_0x48c542,_0x241b64){return function(_0x130255){if(_0x130255){return _0x130255[_0x328f('0x21')]()[_0x328f('0x20')](function(){_0x48c542['status'](0xcc)[_0x328f('0x19')]();});}};}function handleEntityNotFound(_0x4d31d6,_0x53b921){return function(_0xedf9bc){if(!_0xedf9bc){_0x4d31d6['sendStatus'](0x194);}return _0xedf9bc;};}function handleError(_0x83adff,_0x3de578){_0x3de578=_0x3de578||0x1f4;return function(_0xc7eee){logger['error'](_0xc7eee[_0x328f('0x22')]);if(_0xc7eee['name']){delete _0xc7eee[_0x328f('0x23')];}_0x83adff['status'](_0x3de578)[_0x328f('0x24')](_0xc7eee);};}exports['index']=function(_0x230fba,_0x3c5fb1){var _0x3988a4={},_0x50a093={},_0x198ea4={'count':0x0,'rows':[]};var _0x24a349=_[_0x328f('0x25')](db[_0x328f('0x26')][_0x328f('0x27')],function(_0x455dde){return{'name':_0x455dde['fieldName'],'type':_0x455dde[_0x328f('0x28')]['key']};});_0x50a093[_0x328f('0x29')]=_[_0x328f('0x25')](_0x24a349,_0x328f('0x23'));_0x50a093[_0x328f('0x2a')]=_['keys'](_0x230fba[_0x328f('0x2a')]);_0x50a093[_0x328f('0x2b')]=_[_0x328f('0x2c')](_0x50a093['model'],_0x50a093[_0x328f('0x2a')]);_0x3988a4[_0x328f('0x2d')]=_[_0x328f('0x2c')](_0x50a093[_0x328f('0x29')],qs[_0x328f('0x2e')](_0x230fba['query'][_0x328f('0x2e')]));_0x3988a4[_0x328f('0x2d')]=_0x3988a4[_0x328f('0x2d')][_0x328f('0x2f')]?_0x3988a4[_0x328f('0x2d')]:_0x50a093[_0x328f('0x29')];if(!_0x230fba[_0x328f('0x2a')][_0x328f('0x30')](_0x328f('0x31'))){_0x3988a4[_0x328f('0x32')]=qs['limit'](_0x230fba[_0x328f('0x2a')][_0x328f('0x32')]);_0x3988a4[_0x328f('0x33')]=qs[_0x328f('0x33')](_0x230fba[_0x328f('0x2a')]['offset']);}_0x3988a4[_0x328f('0x34')]=qs[_0x328f('0x35')](_0x230fba[_0x328f('0x2a')][_0x328f('0x35')]);_0x3988a4[_0x328f('0x36')]=qs[_0x328f('0x2b')](_['pick'](_0x230fba[_0x328f('0x2a')],_0x50a093['filters']),_0x24a349);if(_0x230fba['query']['filter']){_0x3988a4['where']=_[_0x328f('0x37')](_0x3988a4[_0x328f('0x36')],{'$or':_[_0x328f('0x25')](_0x24a349,function(_0x4c74d5){if(_0x4c74d5[_0x328f('0x28')]!==_0x328f('0x38')){var _0x4d5f74={};_0x4d5f74[_0x4c74d5[_0x328f('0x23')]]={'$like':'%'+_0x230fba['query'][_0x328f('0x39')]+'%'};return _0x4d5f74;}})});}_0x3988a4=_[_0x328f('0x37')]({},_0x3988a4,_0x230fba[_0x328f('0x3a')]);var _0x21d112={'where':_0x3988a4[_0x328f('0x36')]};return db['Integration'][_0x328f('0x1c')](_0x21d112)[_0x328f('0x20')](function(_0x26e4b4){_0x198ea4[_0x328f('0x1c')]=_0x26e4b4;if(_0x230fba['query'][_0x328f('0x3b')]){_0x3988a4[_0x328f('0x3c')]=[{'all':!![]}];}return db[_0x328f('0x26')]['findAll'](_0x3988a4);})[_0x328f('0x20')](function(_0x47e7ba){_0x198ea4[_0x328f('0x3d')]=_0x47e7ba;return _0x198ea4;})[_0x328f('0x20')](respondWithFilteredResult(_0x3c5fb1,_0x3988a4))[_0x328f('0x3e')](handleError(_0x3c5fb1,null));};exports[_0x328f('0x3f')]=function(_0x133968,_0x2afe9b){var _0x2dafac={'raw':![],'where':{'id':_0x133968[_0x328f('0x40')]['id']}},_0x17dbe2={};_0x17dbe2['model']=_[_0x328f('0x41')](db[_0x328f('0x26')][_0x328f('0x27')]);_0x17dbe2[_0x328f('0x2a')]=_['keys'](_0x133968[_0x328f('0x2a')]);_0x17dbe2[_0x328f('0x2b')]=_['intersection'](_0x17dbe2[_0x328f('0x29')],_0x17dbe2[_0x328f('0x2a')]);_0x2dafac[_0x328f('0x2d')]=_[_0x328f('0x2c')](_0x17dbe2[_0x328f('0x29')],qs[_0x328f('0x2e')](_0x133968[_0x328f('0x2a')][_0x328f('0x2e')]));_0x2dafac['attributes']=_0x2dafac['attributes'][_0x328f('0x2f')]?_0x2dafac[_0x328f('0x2d')]:_0x17dbe2['model'];if(_0x133968[_0x328f('0x2a')]['includeAll']){_0x2dafac[_0x328f('0x3c')]=[{'all':!![]}];}_0x2dafac=_[_0x328f('0x37')]({},_0x2dafac,_0x133968[_0x328f('0x3a')]);return db['Integration'][_0x328f('0x42')](_0x2dafac)[_0x328f('0x20')](handleEntityNotFound(_0x2afe9b,null))[_0x328f('0x20')](respondWithResult(_0x2afe9b,null))[_0x328f('0x3e')](handleError(_0x2afe9b,null));};exports['create']=function(_0x2b39cf,_0x307f38){return db['Integration'][_0x328f('0x43')](_0x2b39cf[_0x328f('0x44')],{})[_0x328f('0x20')](respondWithResult(_0x307f38,0xc9))[_0x328f('0x3e')](handleError(_0x307f38,null));};exports[_0x328f('0x1f')]=function(_0x4dc767,_0x16c717){if(_0x4dc767[_0x328f('0x44')]['id']){delete _0x4dc767[_0x328f('0x44')]['id'];}return db['Integration'][_0x328f('0x42')]({'where':{'id':_0x4dc767['params']['id']}})[_0x328f('0x20')](handleEntityNotFound(_0x16c717,null))[_0x328f('0x20')](saveUpdates(_0x4dc767[_0x328f('0x44')],null))['then'](respondWithResult(_0x16c717,null))['catch'](handleError(_0x16c717,null));};exports[_0x328f('0x21')]=function(_0x54ca42,_0x29b7e7){return db[_0x328f('0x26')][_0x328f('0x42')]({'where':{'id':_0x54ca42[_0x328f('0x40')]['id']}})[_0x328f('0x20')](handleEntityNotFound(_0x29b7e7,null))[_0x328f('0x20')](removeEntity(_0x29b7e7,null))['catch'](handleError(_0x29b7e7,null));};
\ No newline at end of file
+var _0x687b=['order','sort','where','filter','VIRTUAL','options','include','findAll','rows','show','length','includeAll','merge','find','catch','create','body','params','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','Content-Range','save','update','then','destroy','end','error','stack','name','send','index','map','Integration','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit'];(function(_0x7293e1,_0x3e8cf2){var _0x3ec34f=function(_0x29f472){while(--_0x29f472){_0x7293e1['push'](_0x7293e1['shift']());}};_0x3ec34f(++_0x3e8cf2);}(_0x687b,0x14a));var _0xb687=function(_0x2234bd,_0x259d9d){_0x2234bd=_0x2234bd-0x0;var _0x2aa4bd=_0x687b[_0x2234bd];return _0x2aa4bd;};'use strict';var emlformat=require(_0xb687('0x0'));var rimraf=require(_0xb687('0x1'));var zipdir=require(_0xb687('0x2'));var jsonpatch=require(_0xb687('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xb687('0x4'));var Mustache=require(_0xb687('0x5'));var util=require(_0xb687('0x6'));var path=require(_0xb687('0x7'));var sox=require(_0xb687('0x8'));var csv=require(_0xb687('0x9'));var ejs=require(_0xb687('0xa'));var fs=require('fs');var fs_extra=require(_0xb687('0xb'));var _=require(_0xb687('0xc'));var squel=require(_0xb687('0xd'));var crypto=require('crypto');var jsforce=require(_0xb687('0xe'));var deskjs=require(_0xb687('0xf'));var toCsv=require('to-csv');var querystring=require(_0xb687('0x10'));var Papa=require(_0xb687('0x11'));var Redis=require(_0xb687('0x12'));var authService=require(_0xb687('0x13'));var qs=require(_0xb687('0x14'));var as=require(_0xb687('0x15'));var hardwareService=require(_0xb687('0x16'));var logger=require(_0xb687('0x17'))(_0xb687('0x18'));var utils=require('../../config/utils');var config=require(_0xb687('0x19'));var licenseUtil=require(_0xb687('0x1a'));var db=require(_0xb687('0x1b'))['db'];function respondWithStatusCode(_0x12a0be,_0x4f9c19){_0x4f9c19=_0x4f9c19||0xcc;return function(_0x4c97ed){if(_0x4c97ed){return _0x12a0be[_0xb687('0x1c')](_0x4f9c19);}return _0x12a0be[_0xb687('0x1d')](_0x4f9c19)['end']();};}function respondWithResult(_0x108fd0,_0x2f1ac0){_0x2f1ac0=_0x2f1ac0||0xc8;return function(_0x1f1f35){if(_0x1f1f35){return _0x108fd0[_0xb687('0x1d')](_0x2f1ac0)[_0xb687('0x1e')](_0x1f1f35);}};}function respondWithFilteredResult(_0x3ab914,_0x30622f){return function(_0x141375){if(_0x141375){var _0x263085=typeof _0x30622f[_0xb687('0x1f')]===_0xb687('0x20')&&typeof _0x30622f[_0xb687('0x21')]==='undefined';var _0x214b06=_0x141375[_0xb687('0x22')];var _0x30d370=_0x263085?0x0:_0x30622f['offset'];var _0x48958d=_0x263085?_0x141375[_0xb687('0x22')]:_0x30622f[_0xb687('0x1f')]+_0x30622f[_0xb687('0x21')];var _0x4b593b;if(_0x48958d>=_0x214b06){_0x48958d=_0x214b06;_0x4b593b=0xc8;}else{_0x4b593b=0xce;}_0x3ab914[_0xb687('0x1d')](_0x4b593b);return _0x3ab914['set'](_0xb687('0x23'),_0x30d370+'-'+_0x48958d+'/'+_0x214b06)[_0xb687('0x1e')](_0x141375);}return null;};}function patchUpdates(_0x170dc0){return function(_0x44bd0b){try{jsonpatch['apply'](_0x44bd0b,_0x170dc0,!![]);}catch(_0x3a73d5){return BPromise['reject'](_0x3a73d5);}return _0x44bd0b[_0xb687('0x24')]();};}function saveUpdates(_0x90e892,_0x274241){return function(_0x546fde){if(_0x546fde){return _0x546fde[_0xb687('0x25')](_0x90e892)[_0xb687('0x26')](function(_0xa95e91){return _0xa95e91;});}return null;};}function removeEntity(_0x16cdcb,_0xbf6c58){return function(_0x38866c){if(_0x38866c){return _0x38866c[_0xb687('0x27')]()[_0xb687('0x26')](function(){_0x16cdcb['status'](0xcc)[_0xb687('0x28')]();});}};}function handleEntityNotFound(_0x129347,_0x1c1585){return function(_0x1a0261){if(!_0x1a0261){_0x129347[_0xb687('0x1c')](0x194);}return _0x1a0261;};}function handleError(_0x4136c9,_0x17ff2b){_0x17ff2b=_0x17ff2b||0x1f4;return function(_0x3cb2f2){logger[_0xb687('0x29')](_0x3cb2f2[_0xb687('0x2a')]);if(_0x3cb2f2['name']){delete _0x3cb2f2[_0xb687('0x2b')];}_0x4136c9[_0xb687('0x1d')](_0x17ff2b)[_0xb687('0x2c')](_0x3cb2f2);};}exports[_0xb687('0x2d')]=function(_0x2e5c8d,_0x173c58){var _0x4e9a06={},_0x28b69a={},_0x5143af={'count':0x0,'rows':[]};var _0x360429=_[_0xb687('0x2e')](db[_0xb687('0x2f')][_0xb687('0x30')],function(_0x1ad3ef){return{'name':_0x1ad3ef[_0xb687('0x31')],'type':_0x1ad3ef[_0xb687('0x32')]['key']};});_0x28b69a[_0xb687('0x33')]=_[_0xb687('0x2e')](_0x360429,_0xb687('0x2b'));_0x28b69a[_0xb687('0x34')]=_[_0xb687('0x35')](_0x2e5c8d[_0xb687('0x34')]);_0x28b69a[_0xb687('0x36')]=_[_0xb687('0x37')](_0x28b69a[_0xb687('0x33')],_0x28b69a[_0xb687('0x34')]);_0x4e9a06[_0xb687('0x38')]=_['intersection'](_0x28b69a['model'],qs[_0xb687('0x39')](_0x2e5c8d[_0xb687('0x34')][_0xb687('0x39')]));_0x4e9a06[_0xb687('0x38')]=_0x4e9a06['attributes']['length']?_0x4e9a06[_0xb687('0x38')]:_0x28b69a[_0xb687('0x33')];if(!_0x2e5c8d['query'][_0xb687('0x3a')](_0xb687('0x3b'))){_0x4e9a06['limit']=qs[_0xb687('0x21')](_0x2e5c8d['query'][_0xb687('0x21')]);_0x4e9a06[_0xb687('0x1f')]=qs[_0xb687('0x1f')](_0x2e5c8d[_0xb687('0x34')][_0xb687('0x1f')]);}_0x4e9a06[_0xb687('0x3c')]=qs['sort'](_0x2e5c8d[_0xb687('0x34')][_0xb687('0x3d')]);_0x4e9a06[_0xb687('0x3e')]=qs[_0xb687('0x36')](_['pick'](_0x2e5c8d[_0xb687('0x34')],_0x28b69a[_0xb687('0x36')]),_0x360429);if(_0x2e5c8d[_0xb687('0x34')][_0xb687('0x3f')]){_0x4e9a06[_0xb687('0x3e')]=_['merge'](_0x4e9a06[_0xb687('0x3e')],{'$or':_[_0xb687('0x2e')](_0x360429,function(_0x24c013){if(_0x24c013[_0xb687('0x32')]!==_0xb687('0x40')){var _0x29cf09={};_0x29cf09[_0x24c013['name']]={'$like':'%'+_0x2e5c8d['query'][_0xb687('0x3f')]+'%'};return _0x29cf09;}})});}_0x4e9a06=_['merge']({},_0x4e9a06,_0x2e5c8d[_0xb687('0x41')]);var _0x2f4550={'where':_0x4e9a06['where']};return db[_0xb687('0x2f')][_0xb687('0x22')](_0x2f4550)['then'](function(_0x394b56){_0x5143af[_0xb687('0x22')]=_0x394b56;if(_0x2e5c8d[_0xb687('0x34')]['includeAll']){_0x4e9a06[_0xb687('0x42')]=[{'all':!![]}];}return db[_0xb687('0x2f')][_0xb687('0x43')](_0x4e9a06);})[_0xb687('0x26')](function(_0x140388){_0x5143af[_0xb687('0x44')]=_0x140388;return _0x5143af;})[_0xb687('0x26')](respondWithFilteredResult(_0x173c58,_0x4e9a06))['catch'](handleError(_0x173c58,null));};exports[_0xb687('0x45')]=function(_0x4cf6ad,_0x50fdb7){var _0xa3a9e0={'raw':![],'where':{'id':_0x4cf6ad['params']['id']}},_0x430364={};_0x430364[_0xb687('0x33')]=_['keys'](db[_0xb687('0x2f')][_0xb687('0x30')]);_0x430364['query']=_[_0xb687('0x35')](_0x4cf6ad[_0xb687('0x34')]);_0x430364['filters']=_[_0xb687('0x37')](_0x430364[_0xb687('0x33')],_0x430364[_0xb687('0x34')]);_0xa3a9e0[_0xb687('0x38')]=_[_0xb687('0x37')](_0x430364[_0xb687('0x33')],qs[_0xb687('0x39')](_0x4cf6ad[_0xb687('0x34')][_0xb687('0x39')]));_0xa3a9e0[_0xb687('0x38')]=_0xa3a9e0[_0xb687('0x38')][_0xb687('0x46')]?_0xa3a9e0['attributes']:_0x430364[_0xb687('0x33')];if(_0x4cf6ad['query'][_0xb687('0x47')]){_0xa3a9e0[_0xb687('0x42')]=[{'all':!![]}];}_0xa3a9e0=_[_0xb687('0x48')]({},_0xa3a9e0,_0x4cf6ad[_0xb687('0x41')]);return db[_0xb687('0x2f')][_0xb687('0x49')](_0xa3a9e0)['then'](handleEntityNotFound(_0x50fdb7,null))['then'](respondWithResult(_0x50fdb7,null))[_0xb687('0x4a')](handleError(_0x50fdb7,null));};exports[_0xb687('0x4b')]=function(_0x40558a,_0x4f3069){return db['Integration'][_0xb687('0x4b')](_0x40558a[_0xb687('0x4c')],{})[_0xb687('0x26')](respondWithResult(_0x4f3069,0xc9))[_0xb687('0x4a')](handleError(_0x4f3069,null));};exports['update']=function(_0x33a0b0,_0xfc4c5f){if(_0x33a0b0[_0xb687('0x4c')]['id']){delete _0x33a0b0[_0xb687('0x4c')]['id'];}return db['Integration']['find']({'where':{'id':_0x33a0b0[_0xb687('0x4d')]['id']}})[_0xb687('0x26')](handleEntityNotFound(_0xfc4c5f,null))[_0xb687('0x26')](saveUpdates(_0x33a0b0['body'],null))['then'](respondWithResult(_0xfc4c5f,null))[_0xb687('0x4a')](handleError(_0xfc4c5f,null));};exports[_0xb687('0x27')]=function(_0xd5bdb7,_0x22e618){return db[_0xb687('0x2f')][_0xb687('0x49')]({'where':{'id':_0xd5bdb7[_0xb687('0x4d')]['id']}})[_0xb687('0x26')](handleEntityNotFound(_0x22e618,null))['then'](removeEntity(_0x22e618,null))[_0xb687('0x4a')](handleError(_0x22e618,null));};
\ No newline at end of file