Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / intSugarcrmConfiguration / intSugarcrmConfiguration.controller.js
index fc8e260..326bcd3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcf95=['limit','set','Content-Range','json','apply','reject','update','then','destroy','stack','name','send','index','SugarcrmConfiguration','rawAttributes','fieldName','type','map','query','keys','intersection','attributes','model','fields','length','hasOwnProperty','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','params','create','body','find','getFields','SugarcrmField','nolimit','getSubjects','getDescriptions','findOne','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','offset','undefined','count'];(function(_0x4726d0,_0x59835d){var _0x1aac2d=function(_0x52510a){while(--_0x52510a){_0x4726d0['push'](_0x4726d0['shift']());}};_0x1aac2d(++_0x59835d);}(_0xcf95,0x82));var _0x5cf9=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xcf95[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x5cf9('0x0'));var rimraf=require(_0x5cf9('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5cf9('0x2'));var rp=require(_0x5cf9('0x3'));var moment=require(_0x5cf9('0x4'));var BPromise=require(_0x5cf9('0x5'));var Mustache=require(_0x5cf9('0x6'));var util=require(_0x5cf9('0x7'));var path=require(_0x5cf9('0x8'));var sox=require('sox');var csv=require(_0x5cf9('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5cf9('0xa'));var _=require(_0x5cf9('0xb'));var squel=require(_0x5cf9('0xc'));var crypto=require(_0x5cf9('0xd'));var jsforce=require(_0x5cf9('0xe'));var deskjs=require(_0x5cf9('0xf'));var toCsv=require(_0x5cf9('0x9'));var querystring=require(_0x5cf9('0x10'));var Papa=require(_0x5cf9('0x11'));var Redis=require(_0x5cf9('0x12'));var authService=require(_0x5cf9('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x5cf9('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5cf9('0x15'))(_0x5cf9('0x16'));var utils=require(_0x5cf9('0x17'));var config=require(_0x5cf9('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x5cf9('0x19'))['db'];function respondWithStatusCode(_0x3f62ba,_0x35e3c2){_0x35e3c2=_0x35e3c2||0xcc;return function(_0x3550c1){if(_0x3550c1){return _0x3f62ba[_0x5cf9('0x1a')](_0x35e3c2);}return _0x3f62ba[_0x5cf9('0x1b')](_0x35e3c2)[_0x5cf9('0x1c')]();};}function respondWithResult(_0x4ec8d9,_0x488a11){_0x488a11=_0x488a11||0xc8;return function(_0x1c52cf){if(_0x1c52cf){return _0x4ec8d9['status'](_0x488a11)['json'](_0x1c52cf);}};}function respondWithFilteredResult(_0x222f51,_0x1dcff3){return function(_0x5b6e7e){if(_0x5b6e7e){var _0x319b96=typeof _0x1dcff3[_0x5cf9('0x1d')]==='undefined'&&typeof _0x1dcff3['limit']===_0x5cf9('0x1e');var _0x121159=_0x5b6e7e[_0x5cf9('0x1f')];var _0xf6ce07=_0x319b96?0x0:_0x1dcff3['offset'];var _0x2501a8=_0x319b96?_0x5b6e7e[_0x5cf9('0x1f')]:_0x1dcff3[_0x5cf9('0x1d')]+_0x1dcff3[_0x5cf9('0x20')];var _0x44e4fd;if(_0x2501a8>=_0x121159){_0x2501a8=_0x121159;_0x44e4fd=0xc8;}else{_0x44e4fd=0xce;}_0x222f51['status'](_0x44e4fd);return _0x222f51[_0x5cf9('0x21')](_0x5cf9('0x22'),_0xf6ce07+'-'+_0x2501a8+'/'+_0x121159)[_0x5cf9('0x23')](_0x5b6e7e);}return null;};}function patchUpdates(_0x4832d7){return function(_0x1e6a62){try{jsonpatch[_0x5cf9('0x24')](_0x1e6a62,_0x4832d7,!![]);}catch(_0x1efe28){return BPromise[_0x5cf9('0x25')](_0x1efe28);}return _0x1e6a62['save']();};}function saveUpdates(_0x496b01,_0x2578c8){return function(_0x43a4a3){if(_0x43a4a3){return _0x43a4a3[_0x5cf9('0x26')](_0x496b01)[_0x5cf9('0x27')](function(_0x4c739a){return _0x4c739a;});}return null;};}function removeEntity(_0x52ca43,_0x1744a4){return function(_0x25bb49){if(_0x25bb49){return _0x25bb49[_0x5cf9('0x28')]()['then'](function(){_0x52ca43[_0x5cf9('0x1b')](0xcc)[_0x5cf9('0x1c')]();});}};}function handleEntityNotFound(_0x1960e6,_0x13f9fb){return function(_0x371701){if(!_0x371701){_0x1960e6[_0x5cf9('0x1a')](0x194);}return _0x371701;};}function handleError(_0x570988,_0x21dd9b){_0x21dd9b=_0x21dd9b||0x1f4;return function(_0x2a8bab){logger['error'](_0x2a8bab[_0x5cf9('0x29')]);if(_0x2a8bab[_0x5cf9('0x2a')]){delete _0x2a8bab['name'];}_0x570988['status'](_0x21dd9b)[_0x5cf9('0x2b')](_0x2a8bab);};}exports[_0x5cf9('0x2c')]=function(_0x5a8074,_0x457aa5){var _0x1a66b9={},_0x4f3e0c={},_0x17c8aa={'count':0x0,'rows':[]};var _0x3ae7dc=_['map'](db[_0x5cf9('0x2d')][_0x5cf9('0x2e')],function(_0x4adc9e){return{'name':_0x4adc9e[_0x5cf9('0x2f')],'type':_0x4adc9e[_0x5cf9('0x30')]['key']};});_0x4f3e0c['model']=_[_0x5cf9('0x31')](_0x3ae7dc,_0x5cf9('0x2a'));_0x4f3e0c[_0x5cf9('0x32')]=_[_0x5cf9('0x33')](_0x5a8074[_0x5cf9('0x32')]);_0x4f3e0c['filters']=_[_0x5cf9('0x34')](_0x4f3e0c['model'],_0x4f3e0c[_0x5cf9('0x32')]);_0x1a66b9[_0x5cf9('0x35')]=_[_0x5cf9('0x34')](_0x4f3e0c[_0x5cf9('0x36')],qs[_0x5cf9('0x37')](_0x5a8074['query'][_0x5cf9('0x37')]));_0x1a66b9[_0x5cf9('0x35')]=_0x1a66b9[_0x5cf9('0x35')][_0x5cf9('0x38')]?_0x1a66b9[_0x5cf9('0x35')]:_0x4f3e0c[_0x5cf9('0x36')];if(!_0x5a8074['query'][_0x5cf9('0x39')]('nolimit')){_0x1a66b9[_0x5cf9('0x20')]=qs[_0x5cf9('0x20')](_0x5a8074[_0x5cf9('0x32')][_0x5cf9('0x20')]);_0x1a66b9['offset']=qs['offset'](_0x5a8074[_0x5cf9('0x32')][_0x5cf9('0x1d')]);}_0x1a66b9[_0x5cf9('0x3a')]=qs[_0x5cf9('0x3b')](_0x5a8074['query']['sort']);_0x1a66b9[_0x5cf9('0x3c')]=qs['filters'](_[_0x5cf9('0x3d')](_0x5a8074[_0x5cf9('0x32')],_0x4f3e0c[_0x5cf9('0x3e')]),_0x3ae7dc);if(_0x5a8074['query'][_0x5cf9('0x3f')]){_0x1a66b9[_0x5cf9('0x3c')]=_[_0x5cf9('0x40')](_0x1a66b9[_0x5cf9('0x3c')],{'$or':_['map'](_0x3ae7dc,function(_0x42687d){if(_0x42687d[_0x5cf9('0x30')]!==_0x5cf9('0x41')){var _0x25e137={};_0x25e137[_0x42687d[_0x5cf9('0x2a')]]={'$like':'%'+_0x5a8074[_0x5cf9('0x32')][_0x5cf9('0x3f')]+'%'};return _0x25e137;}})});}_0x1a66b9=_[_0x5cf9('0x40')]({},_0x1a66b9,_0x5a8074[_0x5cf9('0x42')]);var _0x4f68ce={'where':_0x1a66b9[_0x5cf9('0x3c')]};return db['SugarcrmConfiguration'][_0x5cf9('0x1f')](_0x4f68ce)['then'](function(_0x5b2713){_0x17c8aa[_0x5cf9('0x1f')]=_0x5b2713;if(_0x5a8074['query'][_0x5cf9('0x43')]){_0x1a66b9[_0x5cf9('0x44')]=[{'all':!![]}];}return db[_0x5cf9('0x2d')]['findAll'](_0x1a66b9);})[_0x5cf9('0x27')](function(_0xb27e8b){_0x17c8aa[_0x5cf9('0x45')]=_0xb27e8b;return _0x17c8aa;})[_0x5cf9('0x27')](respondWithFilteredResult(_0x457aa5,_0x1a66b9))[_0x5cf9('0x46')](handleError(_0x457aa5,null));};exports['show']=function(_0x1a45e8,_0x175bb2){var _0x5a929f={'raw':![],'where':{'id':_0x1a45e8[_0x5cf9('0x47')]['id']}},_0x5525bb={};_0x5525bb[_0x5cf9('0x36')]=_['keys'](db[_0x5cf9('0x2d')][_0x5cf9('0x2e')]);_0x5525bb[_0x5cf9('0x32')]=_['keys'](_0x1a45e8['query']);_0x5525bb[_0x5cf9('0x3e')]=_[_0x5cf9('0x34')](_0x5525bb[_0x5cf9('0x36')],_0x5525bb[_0x5cf9('0x32')]);_0x5a929f[_0x5cf9('0x35')]=_['intersection'](_0x5525bb[_0x5cf9('0x36')],qs[_0x5cf9('0x37')](_0x1a45e8['query'][_0x5cf9('0x37')]));_0x5a929f[_0x5cf9('0x35')]=_0x5a929f['attributes'][_0x5cf9('0x38')]?_0x5a929f[_0x5cf9('0x35')]:_0x5525bb[_0x5cf9('0x36')];if(_0x1a45e8[_0x5cf9('0x32')][_0x5cf9('0x43')]){_0x5a929f['include']=[{'all':!![]}];}_0x5a929f=_[_0x5cf9('0x40')]({},_0x5a929f,_0x1a45e8[_0x5cf9('0x42')]);return db[_0x5cf9('0x2d')]['find'](_0x5a929f)[_0x5cf9('0x27')](handleEntityNotFound(_0x175bb2,null))[_0x5cf9('0x27')](respondWithResult(_0x175bb2,null))[_0x5cf9('0x46')](handleError(_0x175bb2,null));};exports[_0x5cf9('0x48')]=function(_0x36f3f6,_0x929acb){return db[_0x5cf9('0x2d')][_0x5cf9('0x48')](_0x36f3f6[_0x5cf9('0x49')],{})[_0x5cf9('0x27')](respondWithResult(_0x929acb,0xc9))[_0x5cf9('0x46')](handleError(_0x929acb,null));};exports[_0x5cf9('0x26')]=function(_0x4424b1,_0x24d226){if(_0x4424b1[_0x5cf9('0x49')]['id']){delete _0x4424b1[_0x5cf9('0x49')]['id'];}return db['SugarcrmConfiguration'][_0x5cf9('0x4a')]({'where':{'id':_0x4424b1[_0x5cf9('0x47')]['id']}})['then'](handleEntityNotFound(_0x24d226,null))[_0x5cf9('0x27')](saveUpdates(_0x4424b1[_0x5cf9('0x49')],null))[_0x5cf9('0x27')](respondWithResult(_0x24d226,null))['catch'](handleError(_0x24d226,null));};exports[_0x5cf9('0x28')]=function(_0x3c85fd,_0x15a0a4){return db[_0x5cf9('0x2d')][_0x5cf9('0x4a')]({'where':{'id':_0x3c85fd['params']['id']}})[_0x5cf9('0x27')](handleEntityNotFound(_0x15a0a4,null))[_0x5cf9('0x27')](removeEntity(_0x15a0a4,null))[_0x5cf9('0x46')](handleError(_0x15a0a4,null));};exports[_0x5cf9('0x4b')]=function(_0x54cbd0,_0x1ce6ff,_0x39b22c){var _0x3613dc={};var _0x52325c={};var _0x55e39d;var _0x357f6f;return db[_0x5cf9('0x2d')]['findOne']({'where':{'id':_0x54cbd0[_0x5cf9('0x47')]['id']}})[_0x5cf9('0x27')](handleEntityNotFound(_0x1ce6ff,null))[_0x5cf9('0x27')](function(_0x545a6d){if(_0x545a6d){_0x55e39d=_0x545a6d;_0x52325c[_0x5cf9('0x36')]=_[_0x5cf9('0x33')](db[_0x5cf9('0x4c')][_0x5cf9('0x2e')]);_0x52325c['query']=_['keys'](_0x54cbd0[_0x5cf9('0x32')]);_0x52325c[_0x5cf9('0x3e')]=_[_0x5cf9('0x34')](_0x52325c[_0x5cf9('0x36')],_0x52325c[_0x5cf9('0x32')]);_0x3613dc['attributes']=_[_0x5cf9('0x34')](_0x52325c[_0x5cf9('0x36')],qs[_0x5cf9('0x37')](_0x54cbd0[_0x5cf9('0x32')]['fields']));_0x3613dc[_0x5cf9('0x35')]=_0x3613dc[_0x5cf9('0x35')][_0x5cf9('0x38')]?_0x3613dc[_0x5cf9('0x35')]:_0x52325c['model'];_0x3613dc[_0x5cf9('0x3a')]=qs['sort'](_0x54cbd0[_0x5cf9('0x32')]['sort']);_0x3613dc[_0x5cf9('0x3c')]=qs[_0x5cf9('0x3e')](_[_0x5cf9('0x3d')](_0x54cbd0['query'],_0x52325c[_0x5cf9('0x3e')]));if(_0x54cbd0[_0x5cf9('0x32')][_0x5cf9('0x3f')]){_0x3613dc[_0x5cf9('0x3c')]=_[_0x5cf9('0x40')](_0x3613dc['where'],{'$or':_['map'](_0x3613dc[_0x5cf9('0x35')],function(_0x32c444){var _0x52199a={};_0x52199a[_0x32c444]={'$like':'%'+_0x54cbd0['query'][_0x5cf9('0x3f')]+'%'};return _0x52199a;})});}_0x3613dc=_[_0x5cf9('0x40')]({},_0x3613dc,_0x54cbd0[_0x5cf9('0x42')]);return _0x55e39d[_0x5cf9('0x4b')](_0x3613dc);}})[_0x5cf9('0x27')](function(_0x206d6e){if(_0x206d6e){_0x357f6f=_0x206d6e[_0x5cf9('0x38')];if(!_0x54cbd0[_0x5cf9('0x32')][_0x5cf9('0x39')](_0x5cf9('0x4d'))){_0x3613dc[_0x5cf9('0x20')]=qs[_0x5cf9('0x20')](_0x54cbd0[_0x5cf9('0x32')][_0x5cf9('0x20')]);_0x3613dc['offset']=qs[_0x5cf9('0x1d')](_0x54cbd0['query']['offset']);}return _0x55e39d[_0x5cf9('0x4b')](_0x3613dc);}})[_0x5cf9('0x27')](function(_0x54f1b1){if(_0x54f1b1){return _0x54f1b1?{'count':_0x357f6f,'rows':_0x54f1b1}:null;}})[_0x5cf9('0x27')](respondWithResult(_0x1ce6ff,null))['catch'](handleError(_0x1ce6ff,null));};exports[_0x5cf9('0x4e')]=function(_0x5344da,_0x5e315f,_0x45964f){var _0x29f3d1={};var _0x7bf8b7={};var _0x228757;var _0x334444;return db[_0x5cf9('0x2d')]['findOne']({'where':{'id':_0x5344da[_0x5cf9('0x47')]['id']}})['then'](handleEntityNotFound(_0x5e315f,null))[_0x5cf9('0x27')](function(_0x3e400c){if(_0x3e400c){_0x228757=_0x3e400c;_0x7bf8b7['model']=_['keys'](db[_0x5cf9('0x4c')][_0x5cf9('0x2e')]);_0x7bf8b7[_0x5cf9('0x32')]=_[_0x5cf9('0x33')](_0x5344da['query']);_0x7bf8b7[_0x5cf9('0x3e')]=_[_0x5cf9('0x34')](_0x7bf8b7['model'],_0x7bf8b7[_0x5cf9('0x32')]);_0x29f3d1[_0x5cf9('0x35')]=_[_0x5cf9('0x34')](_0x7bf8b7['model'],qs[_0x5cf9('0x37')](_0x5344da[_0x5cf9('0x32')][_0x5cf9('0x37')]));_0x29f3d1[_0x5cf9('0x35')]=_0x29f3d1[_0x5cf9('0x35')][_0x5cf9('0x38')]?_0x29f3d1[_0x5cf9('0x35')]:_0x7bf8b7['model'];_0x29f3d1[_0x5cf9('0x3a')]=qs[_0x5cf9('0x3b')](_0x5344da[_0x5cf9('0x32')][_0x5cf9('0x3b')]);_0x29f3d1[_0x5cf9('0x3c')]=qs[_0x5cf9('0x3e')](_[_0x5cf9('0x3d')](_0x5344da[_0x5cf9('0x32')],_0x7bf8b7['filters']));if(_0x5344da['query'][_0x5cf9('0x3f')]){_0x29f3d1[_0x5cf9('0x3c')]=_['merge'](_0x29f3d1[_0x5cf9('0x3c')],{'$or':_[_0x5cf9('0x31')](_0x29f3d1[_0x5cf9('0x35')],function(_0x292096){var _0x1c0ab7={};_0x1c0ab7[_0x292096]={'$like':'%'+_0x5344da[_0x5cf9('0x32')][_0x5cf9('0x3f')]+'%'};return _0x1c0ab7;})});}_0x29f3d1=_[_0x5cf9('0x40')]({},_0x29f3d1,_0x5344da['options']);return _0x228757[_0x5cf9('0x4e')](_0x29f3d1);}})[_0x5cf9('0x27')](function(_0x303476){if(_0x303476){_0x334444=_0x303476[_0x5cf9('0x38')];if(!_0x5344da['query'][_0x5cf9('0x39')]('nolimit')){_0x29f3d1[_0x5cf9('0x20')]=qs['limit'](_0x5344da['query'][_0x5cf9('0x20')]);_0x29f3d1[_0x5cf9('0x1d')]=qs[_0x5cf9('0x1d')](_0x5344da['query'][_0x5cf9('0x1d')]);}return _0x228757[_0x5cf9('0x4e')](_0x29f3d1);}})[_0x5cf9('0x27')](function(_0x139164){if(_0x139164){return _0x139164?{'count':_0x334444,'rows':_0x139164}:null;}})['then'](respondWithResult(_0x5e315f,null))[_0x5cf9('0x46')](handleError(_0x5e315f,null));};exports[_0x5cf9('0x4f')]=function(_0xda5c97,_0x1cb094,_0x17c346){var _0x59d312={};var _0x377686={};var _0x14df6a;var _0x4c38e1;return db[_0x5cf9('0x2d')][_0x5cf9('0x50')]({'where':{'id':_0xda5c97[_0x5cf9('0x47')]['id']}})[_0x5cf9('0x27')](handleEntityNotFound(_0x1cb094,null))['then'](function(_0x410fff){if(_0x410fff){_0x14df6a=_0x410fff;_0x377686[_0x5cf9('0x36')]=_[_0x5cf9('0x33')](db[_0x5cf9('0x4c')][_0x5cf9('0x2e')]);_0x377686['query']=_['keys'](_0xda5c97[_0x5cf9('0x32')]);_0x377686[_0x5cf9('0x3e')]=_[_0x5cf9('0x34')](_0x377686[_0x5cf9('0x36')],_0x377686['query']);_0x59d312[_0x5cf9('0x35')]=_['intersection'](_0x377686[_0x5cf9('0x36')],qs['fields'](_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x37')]));_0x59d312['attributes']=_0x59d312[_0x5cf9('0x35')][_0x5cf9('0x38')]?_0x59d312[_0x5cf9('0x35')]:_0x377686[_0x5cf9('0x36')];_0x59d312[_0x5cf9('0x3a')]=qs[_0x5cf9('0x3b')](_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x3b')]);_0x59d312['where']=qs[_0x5cf9('0x3e')](_[_0x5cf9('0x3d')](_0xda5c97[_0x5cf9('0x32')],_0x377686[_0x5cf9('0x3e')]));if(_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x3f')]){_0x59d312[_0x5cf9('0x3c')]=_['merge'](_0x59d312[_0x5cf9('0x3c')],{'$or':_[_0x5cf9('0x31')](_0x59d312[_0x5cf9('0x35')],function(_0x465746){var _0x8b9640={};_0x8b9640[_0x465746]={'$like':'%'+_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x3f')]+'%'};return _0x8b9640;})});}_0x59d312=_['merge']({},_0x59d312,_0xda5c97[_0x5cf9('0x42')]);return _0x14df6a[_0x5cf9('0x4f')](_0x59d312);}})[_0x5cf9('0x27')](function(_0x2de54d){if(_0x2de54d){_0x4c38e1=_0x2de54d[_0x5cf9('0x38')];if(!_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x39')](_0x5cf9('0x4d'))){_0x59d312['limit']=qs[_0x5cf9('0x20')](_0xda5c97[_0x5cf9('0x32')][_0x5cf9('0x20')]);_0x59d312[_0x5cf9('0x1d')]=qs[_0x5cf9('0x1d')](_0xda5c97['query'][_0x5cf9('0x1d')]);}return _0x14df6a[_0x5cf9('0x4f')](_0x59d312);}})['then'](function(_0x305403){if(_0x305403){return _0x305403?{'count':_0x4c38e1,'rows':_0x305403}:null;}})[_0x5cf9('0x27')](respondWithResult(_0x1cb094,null))[_0x5cf9('0x46')](handleError(_0x1cb094,null));};
\ No newline at end of file
+var _0x6bb1=['getDescriptions','rimraf','zip-dir','fast-json-patch','mustache','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','undefined','offset','count','limit','status','set','Content-Range','apply','save','then','destroy','error','stack','name','send','index','map','SugarcrmConfiguration','rawAttributes','fieldName','type','model','keys','filters','intersection','query','attributes','length','hasOwnProperty','order','sort','where','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','fields','find','create','body','params','getFields','findOne','SugarcrmField','pick','nolimit','getSubjects'];(function(_0x187ee1,_0x3fd1e6){var _0x388160=function(_0x542dd2){while(--_0x542dd2){_0x187ee1['push'](_0x187ee1['shift']());}};_0x388160(++_0x3fd1e6);}(_0x6bb1,0x1cf));var _0x16bb=function(_0x3bf80d,_0x2650df){_0x3bf80d=_0x3bf80d-0x0;var _0x505f21=_0x6bb1[_0x3bf80d];return _0x505f21;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x16bb('0x0'));var zipdir=require(_0x16bb('0x1'));var jsonpatch=require(_0x16bb('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x16bb('0x3'));var util=require('util');var path=require('path');var sox=require(_0x16bb('0x4'));var csv=require(_0x16bb('0x5'));var ejs=require(_0x16bb('0x6'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x16bb('0x7'));var jsforce=require(_0x16bb('0x8'));var deskjs=require(_0x16bb('0x9'));var toCsv=require(_0x16bb('0x5'));var querystring=require(_0x16bb('0xa'));var Papa=require(_0x16bb('0xb'));var Redis=require('ioredis');var authService=require(_0x16bb('0xc'));var qs=require(_0x16bb('0xd'));var as=require(_0x16bb('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x16bb('0xf'))('api');var utils=require(_0x16bb('0x10'));var config=require(_0x16bb('0x11'));var licenseUtil=require(_0x16bb('0x12'));var db=require(_0x16bb('0x13'))['db'];function respondWithStatusCode(_0x461c2e,_0x5c5763){_0x5c5763=_0x5c5763||0xcc;return function(_0x20fef8){if(_0x20fef8){return _0x461c2e[_0x16bb('0x14')](_0x5c5763);}return _0x461c2e['status'](_0x5c5763)[_0x16bb('0x15')]();};}function respondWithResult(_0x34d0a5,_0x1c3e6b){_0x1c3e6b=_0x1c3e6b||0xc8;return function(_0x231d61){if(_0x231d61){return _0x34d0a5['status'](_0x1c3e6b)[_0x16bb('0x16')](_0x231d61);}};}function respondWithFilteredResult(_0x2c2f45,_0x3160d2){return function(_0x16d8d8){if(_0x16d8d8){var _0xeba497=typeof _0x3160d2['offset']===_0x16bb('0x17')&&typeof _0x3160d2['limit']===_0x16bb('0x17');var _0x14bba5=_0x16d8d8['count'];var _0x34d25b=_0xeba497?0x0:_0x3160d2[_0x16bb('0x18')];var _0x4385c2=_0xeba497?_0x16d8d8[_0x16bb('0x19')]:_0x3160d2['offset']+_0x3160d2[_0x16bb('0x1a')];var _0x53bd98;if(_0x4385c2>=_0x14bba5){_0x4385c2=_0x14bba5;_0x53bd98=0xc8;}else{_0x53bd98=0xce;}_0x2c2f45[_0x16bb('0x1b')](_0x53bd98);return _0x2c2f45[_0x16bb('0x1c')](_0x16bb('0x1d'),_0x34d25b+'-'+_0x4385c2+'/'+_0x14bba5)[_0x16bb('0x16')](_0x16d8d8);}return null;};}function patchUpdates(_0x505ab2){return function(_0x3c4a07){try{jsonpatch[_0x16bb('0x1e')](_0x3c4a07,_0x505ab2,!![]);}catch(_0x3affe0){return BPromise['reject'](_0x3affe0);}return _0x3c4a07[_0x16bb('0x1f')]();};}function saveUpdates(_0x1c80a2,_0x39a881){return function(_0x4145a2){if(_0x4145a2){return _0x4145a2['update'](_0x1c80a2)[_0x16bb('0x20')](function(_0x2fb83c){return _0x2fb83c;});}return null;};}function removeEntity(_0x2c5ad6,_0x3717cc){return function(_0x46d7c8){if(_0x46d7c8){return _0x46d7c8[_0x16bb('0x21')]()[_0x16bb('0x20')](function(){_0x2c5ad6[_0x16bb('0x1b')](0xcc)[_0x16bb('0x15')]();});}};}function handleEntityNotFound(_0x14d6cb,_0x517a28){return function(_0x5b2b08){if(!_0x5b2b08){_0x14d6cb[_0x16bb('0x14')](0x194);}return _0x5b2b08;};}function handleError(_0x12f436,_0x534ac7){_0x534ac7=_0x534ac7||0x1f4;return function(_0x15dfc5){logger[_0x16bb('0x22')](_0x15dfc5[_0x16bb('0x23')]);if(_0x15dfc5[_0x16bb('0x24')]){delete _0x15dfc5[_0x16bb('0x24')];}_0x12f436[_0x16bb('0x1b')](_0x534ac7)[_0x16bb('0x25')](_0x15dfc5);};}exports[_0x16bb('0x26')]=function(_0x56a155,_0x21307b){var _0x10d324={},_0x25ca6f={},_0x554f7c={'count':0x0,'rows':[]};var _0x25a731=_[_0x16bb('0x27')](db[_0x16bb('0x28')][_0x16bb('0x29')],function(_0x1fe89f){return{'name':_0x1fe89f[_0x16bb('0x2a')],'type':_0x1fe89f[_0x16bb('0x2b')]['key']};});_0x25ca6f[_0x16bb('0x2c')]=_[_0x16bb('0x27')](_0x25a731,_0x16bb('0x24'));_0x25ca6f['query']=_[_0x16bb('0x2d')](_0x56a155['query']);_0x25ca6f[_0x16bb('0x2e')]=_[_0x16bb('0x2f')](_0x25ca6f[_0x16bb('0x2c')],_0x25ca6f[_0x16bb('0x30')]);_0x10d324[_0x16bb('0x31')]=_['intersection'](_0x25ca6f[_0x16bb('0x2c')],qs['fields'](_0x56a155['query']['fields']));_0x10d324[_0x16bb('0x31')]=_0x10d324[_0x16bb('0x31')][_0x16bb('0x32')]?_0x10d324[_0x16bb('0x31')]:_0x25ca6f[_0x16bb('0x2c')];if(!_0x56a155[_0x16bb('0x30')][_0x16bb('0x33')]('nolimit')){_0x10d324[_0x16bb('0x1a')]=qs[_0x16bb('0x1a')](_0x56a155[_0x16bb('0x30')][_0x16bb('0x1a')]);_0x10d324['offset']=qs[_0x16bb('0x18')](_0x56a155['query'][_0x16bb('0x18')]);}_0x10d324[_0x16bb('0x34')]=qs[_0x16bb('0x35')](_0x56a155[_0x16bb('0x30')][_0x16bb('0x35')]);_0x10d324[_0x16bb('0x36')]=qs[_0x16bb('0x2e')](_['pick'](_0x56a155[_0x16bb('0x30')],_0x25ca6f[_0x16bb('0x2e')]),_0x25a731);if(_0x56a155[_0x16bb('0x30')][_0x16bb('0x37')]){_0x10d324[_0x16bb('0x36')]=_['merge'](_0x10d324['where'],{'$or':_[_0x16bb('0x27')](_0x25a731,function(_0x4c5ccb){if(_0x4c5ccb[_0x16bb('0x2b')]!==_0x16bb('0x38')){var _0x2c5d1a={};_0x2c5d1a[_0x4c5ccb[_0x16bb('0x24')]]={'$like':'%'+_0x56a155[_0x16bb('0x30')]['filter']+'%'};return _0x2c5d1a;}})});}_0x10d324=_[_0x16bb('0x39')]({},_0x10d324,_0x56a155[_0x16bb('0x3a')]);var _0x5a164c={'where':_0x10d324['where']};return db[_0x16bb('0x28')]['count'](_0x5a164c)[_0x16bb('0x20')](function(_0x62e3f0){_0x554f7c[_0x16bb('0x19')]=_0x62e3f0;if(_0x56a155['query'][_0x16bb('0x3b')]){_0x10d324[_0x16bb('0x3c')]=[{'all':!![]}];}return db[_0x16bb('0x28')][_0x16bb('0x3d')](_0x10d324);})[_0x16bb('0x20')](function(_0x28ef2f){_0x554f7c[_0x16bb('0x3e')]=_0x28ef2f;return _0x554f7c;})[_0x16bb('0x20')](respondWithFilteredResult(_0x21307b,_0x10d324))[_0x16bb('0x3f')](handleError(_0x21307b,null));};exports[_0x16bb('0x40')]=function(_0x4cd7d6,_0x30332c){var _0x517bed={'raw':![],'where':{'id':_0x4cd7d6['params']['id']}},_0x387a79={};_0x387a79[_0x16bb('0x2c')]=_[_0x16bb('0x2d')](db[_0x16bb('0x28')]['rawAttributes']);_0x387a79[_0x16bb('0x30')]=_[_0x16bb('0x2d')](_0x4cd7d6[_0x16bb('0x30')]);_0x387a79[_0x16bb('0x2e')]=_[_0x16bb('0x2f')](_0x387a79[_0x16bb('0x2c')],_0x387a79[_0x16bb('0x30')]);_0x517bed[_0x16bb('0x31')]=_['intersection'](_0x387a79[_0x16bb('0x2c')],qs[_0x16bb('0x41')](_0x4cd7d6[_0x16bb('0x30')][_0x16bb('0x41')]));_0x517bed[_0x16bb('0x31')]=_0x517bed[_0x16bb('0x31')][_0x16bb('0x32')]?_0x517bed['attributes']:_0x387a79[_0x16bb('0x2c')];if(_0x4cd7d6[_0x16bb('0x30')][_0x16bb('0x3b')]){_0x517bed[_0x16bb('0x3c')]=[{'all':!![]}];}_0x517bed=_[_0x16bb('0x39')]({},_0x517bed,_0x4cd7d6[_0x16bb('0x3a')]);return db['SugarcrmConfiguration'][_0x16bb('0x42')](_0x517bed)['then'](handleEntityNotFound(_0x30332c,null))[_0x16bb('0x20')](respondWithResult(_0x30332c,null))[_0x16bb('0x3f')](handleError(_0x30332c,null));};exports['create']=function(_0x10e66e,_0x7eb48e){return db[_0x16bb('0x28')][_0x16bb('0x43')](_0x10e66e[_0x16bb('0x44')],{})[_0x16bb('0x20')](respondWithResult(_0x7eb48e,0xc9))[_0x16bb('0x3f')](handleError(_0x7eb48e,null));};exports['update']=function(_0xd4985,_0x400933){if(_0xd4985[_0x16bb('0x44')]['id']){delete _0xd4985['body']['id'];}return db[_0x16bb('0x28')][_0x16bb('0x42')]({'where':{'id':_0xd4985[_0x16bb('0x45')]['id']}})[_0x16bb('0x20')](handleEntityNotFound(_0x400933,null))['then'](saveUpdates(_0xd4985[_0x16bb('0x44')],null))[_0x16bb('0x20')](respondWithResult(_0x400933,null))[_0x16bb('0x3f')](handleError(_0x400933,null));};exports[_0x16bb('0x21')]=function(_0x4eb48f,_0x136de1){return db[_0x16bb('0x28')][_0x16bb('0x42')]({'where':{'id':_0x4eb48f['params']['id']}})[_0x16bb('0x20')](handleEntityNotFound(_0x136de1,null))[_0x16bb('0x20')](removeEntity(_0x136de1,null))[_0x16bb('0x3f')](handleError(_0x136de1,null));};exports[_0x16bb('0x46')]=function(_0x269ae3,_0x38b131,_0x37ead1){var _0x17ed8a={};var _0x224ef5={};var _0x4eede6;var _0x5abef4;return db[_0x16bb('0x28')][_0x16bb('0x47')]({'where':{'id':_0x269ae3['params']['id']}})['then'](handleEntityNotFound(_0x38b131,null))['then'](function(_0x1ea100){if(_0x1ea100){_0x4eede6=_0x1ea100;_0x224ef5[_0x16bb('0x2c')]=_[_0x16bb('0x2d')](db[_0x16bb('0x48')][_0x16bb('0x29')]);_0x224ef5[_0x16bb('0x30')]=_[_0x16bb('0x2d')](_0x269ae3[_0x16bb('0x30')]);_0x224ef5[_0x16bb('0x2e')]=_[_0x16bb('0x2f')](_0x224ef5[_0x16bb('0x2c')],_0x224ef5[_0x16bb('0x30')]);_0x17ed8a['attributes']=_[_0x16bb('0x2f')](_0x224ef5[_0x16bb('0x2c')],qs[_0x16bb('0x41')](_0x269ae3[_0x16bb('0x30')][_0x16bb('0x41')]));_0x17ed8a[_0x16bb('0x31')]=_0x17ed8a['attributes'][_0x16bb('0x32')]?_0x17ed8a[_0x16bb('0x31')]:_0x224ef5[_0x16bb('0x2c')];_0x17ed8a[_0x16bb('0x34')]=qs['sort'](_0x269ae3['query'][_0x16bb('0x35')]);_0x17ed8a[_0x16bb('0x36')]=qs[_0x16bb('0x2e')](_[_0x16bb('0x49')](_0x269ae3[_0x16bb('0x30')],_0x224ef5[_0x16bb('0x2e')]));if(_0x269ae3[_0x16bb('0x30')][_0x16bb('0x37')]){_0x17ed8a[_0x16bb('0x36')]=_[_0x16bb('0x39')](_0x17ed8a[_0x16bb('0x36')],{'$or':_['map'](_0x17ed8a[_0x16bb('0x31')],function(_0x428868){var _0x591663={};_0x591663[_0x428868]={'$like':'%'+_0x269ae3[_0x16bb('0x30')]['filter']+'%'};return _0x591663;})});}_0x17ed8a=_[_0x16bb('0x39')]({},_0x17ed8a,_0x269ae3[_0x16bb('0x3a')]);return _0x4eede6['getFields'](_0x17ed8a);}})[_0x16bb('0x20')](function(_0x720210){if(_0x720210){_0x5abef4=_0x720210['length'];if(!_0x269ae3[_0x16bb('0x30')]['hasOwnProperty'](_0x16bb('0x4a'))){_0x17ed8a[_0x16bb('0x1a')]=qs[_0x16bb('0x1a')](_0x269ae3[_0x16bb('0x30')][_0x16bb('0x1a')]);_0x17ed8a[_0x16bb('0x18')]=qs[_0x16bb('0x18')](_0x269ae3[_0x16bb('0x30')][_0x16bb('0x18')]);}return _0x4eede6[_0x16bb('0x46')](_0x17ed8a);}})[_0x16bb('0x20')](function(_0x1e1fb1){if(_0x1e1fb1){return _0x1e1fb1?{'count':_0x5abef4,'rows':_0x1e1fb1}:null;}})['then'](respondWithResult(_0x38b131,null))[_0x16bb('0x3f')](handleError(_0x38b131,null));};exports['getSubjects']=function(_0xcd21dc,_0x2b4062,_0x47387a){var _0x5a5fdd={};var _0x43cec={};var _0x27a378;var _0x466d37;return db[_0x16bb('0x28')][_0x16bb('0x47')]({'where':{'id':_0xcd21dc[_0x16bb('0x45')]['id']}})[_0x16bb('0x20')](handleEntityNotFound(_0x2b4062,null))[_0x16bb('0x20')](function(_0x573bf){if(_0x573bf){_0x27a378=_0x573bf;_0x43cec[_0x16bb('0x2c')]=_['keys'](db[_0x16bb('0x48')]['rawAttributes']);_0x43cec['query']=_['keys'](_0xcd21dc[_0x16bb('0x30')]);_0x43cec[_0x16bb('0x2e')]=_[_0x16bb('0x2f')](_0x43cec['model'],_0x43cec[_0x16bb('0x30')]);_0x5a5fdd[_0x16bb('0x31')]=_[_0x16bb('0x2f')](_0x43cec[_0x16bb('0x2c')],qs[_0x16bb('0x41')](_0xcd21dc['query'][_0x16bb('0x41')]));_0x5a5fdd[_0x16bb('0x31')]=_0x5a5fdd[_0x16bb('0x31')][_0x16bb('0x32')]?_0x5a5fdd[_0x16bb('0x31')]:_0x43cec[_0x16bb('0x2c')];_0x5a5fdd[_0x16bb('0x34')]=qs['sort'](_0xcd21dc['query'][_0x16bb('0x35')]);_0x5a5fdd['where']=qs[_0x16bb('0x2e')](_['pick'](_0xcd21dc['query'],_0x43cec['filters']));if(_0xcd21dc[_0x16bb('0x30')]['filter']){_0x5a5fdd[_0x16bb('0x36')]=_[_0x16bb('0x39')](_0x5a5fdd[_0x16bb('0x36')],{'$or':_[_0x16bb('0x27')](_0x5a5fdd[_0x16bb('0x31')],function(_0x5d626){var _0x24e521={};_0x24e521[_0x5d626]={'$like':'%'+_0xcd21dc[_0x16bb('0x30')]['filter']+'%'};return _0x24e521;})});}_0x5a5fdd=_[_0x16bb('0x39')]({},_0x5a5fdd,_0xcd21dc['options']);return _0x27a378['getSubjects'](_0x5a5fdd);}})[_0x16bb('0x20')](function(_0x499a43){if(_0x499a43){_0x466d37=_0x499a43[_0x16bb('0x32')];if(!_0xcd21dc[_0x16bb('0x30')][_0x16bb('0x33')](_0x16bb('0x4a'))){_0x5a5fdd[_0x16bb('0x1a')]=qs[_0x16bb('0x1a')](_0xcd21dc['query']['limit']);_0x5a5fdd['offset']=qs['offset'](_0xcd21dc['query'][_0x16bb('0x18')]);}return _0x27a378[_0x16bb('0x4b')](_0x5a5fdd);}})['then'](function(_0x3702d7){if(_0x3702d7){return _0x3702d7?{'count':_0x466d37,'rows':_0x3702d7}:null;}})[_0x16bb('0x20')](respondWithResult(_0x2b4062,null))[_0x16bb('0x3f')](handleError(_0x2b4062,null));};exports[_0x16bb('0x4c')]=function(_0x3ee984,_0x1a7013,_0x5c401e){var _0xf80464={};var _0x1d6d06={};var _0xd77c89;var _0x3d38b9;return db[_0x16bb('0x28')][_0x16bb('0x47')]({'where':{'id':_0x3ee984[_0x16bb('0x45')]['id']}})[_0x16bb('0x20')](handleEntityNotFound(_0x1a7013,null))[_0x16bb('0x20')](function(_0xa8e26b){if(_0xa8e26b){_0xd77c89=_0xa8e26b;_0x1d6d06[_0x16bb('0x2c')]=_['keys'](db[_0x16bb('0x48')][_0x16bb('0x29')]);_0x1d6d06[_0x16bb('0x30')]=_['keys'](_0x3ee984[_0x16bb('0x30')]);_0x1d6d06[_0x16bb('0x2e')]=_['intersection'](_0x1d6d06['model'],_0x1d6d06[_0x16bb('0x30')]);_0xf80464[_0x16bb('0x31')]=_[_0x16bb('0x2f')](_0x1d6d06['model'],qs[_0x16bb('0x41')](_0x3ee984[_0x16bb('0x30')][_0x16bb('0x41')]));_0xf80464[_0x16bb('0x31')]=_0xf80464[_0x16bb('0x31')][_0x16bb('0x32')]?_0xf80464[_0x16bb('0x31')]:_0x1d6d06[_0x16bb('0x2c')];_0xf80464['order']=qs[_0x16bb('0x35')](_0x3ee984[_0x16bb('0x30')]['sort']);_0xf80464[_0x16bb('0x36')]=qs['filters'](_[_0x16bb('0x49')](_0x3ee984['query'],_0x1d6d06['filters']));if(_0x3ee984['query'][_0x16bb('0x37')]){_0xf80464[_0x16bb('0x36')]=_[_0x16bb('0x39')](_0xf80464[_0x16bb('0x36')],{'$or':_[_0x16bb('0x27')](_0xf80464[_0x16bb('0x31')],function(_0x4ad651){var _0x527392={};_0x527392[_0x4ad651]={'$like':'%'+_0x3ee984[_0x16bb('0x30')][_0x16bb('0x37')]+'%'};return _0x527392;})});}_0xf80464=_[_0x16bb('0x39')]({},_0xf80464,_0x3ee984['options']);return _0xd77c89[_0x16bb('0x4c')](_0xf80464);}})['then'](function(_0x4a8674){if(_0x4a8674){_0x3d38b9=_0x4a8674[_0x16bb('0x32')];if(!_0x3ee984[_0x16bb('0x30')][_0x16bb('0x33')](_0x16bb('0x4a'))){_0xf80464[_0x16bb('0x1a')]=qs[_0x16bb('0x1a')](_0x3ee984[_0x16bb('0x30')][_0x16bb('0x1a')]);_0xf80464[_0x16bb('0x18')]=qs[_0x16bb('0x18')](_0x3ee984[_0x16bb('0x30')]['offset']);}return _0xd77c89[_0x16bb('0x4c')](_0xf80464);}})[_0x16bb('0x20')](function(_0x1b7cdf){if(_0x1b7cdf){return _0x1b7cdf?{'count':_0x3d38b9,'rows':_0x1b7cdf}:null;}})['then'](respondWithResult(_0x1a7013,null))[_0x16bb('0x3f')](handleError(_0x1a7013,null));};
\ No newline at end of file