Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / intSugarcrmConfiguration / intSugarcrmConfiguration.controller.js
index 16e97de..62c6eac 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x67d4=['filters','intersection','attributes','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','fields','find','body','getFields','findOne','SugarcrmField','nolimit','getSubjects','getDescriptions','html-pdf','eml-format','request-promise','mustache','sox','to-csv','lodash','squel','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','jayson/promise','client','http','request','then','info','SugarcrmConfiguration,\x20%s,\x20%s','request\x20sent','debug','SugarcrmConfiguration,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','reject','save','update','destroy','stack','name','send','index','map','SugarcrmConfiguration','rawAttributes','type','key','model','keys','query'];(function(_0x4c61a6,_0x398856){var _0x37c4b4=function(_0x29bd5b){while(--_0x29bd5b){_0x4c61a6['push'](_0x4c61a6['shift']());}};_0x37c4b4(++_0x398856);}(_0x67d4,0x11e));var _0x467d=function(_0x9c973a,_0x3be2e1){_0x9c973a=_0x9c973a-0x0;var _0x11e031=_0x67d4[_0x9c973a];return _0x11e031;};'use strict';var pdf=require(_0x467d('0x0'));var emlformat=require(_0x467d('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x467d('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x467d('0x3'));var util=require('util');var path=require('path');var sox=require(_0x467d('0x4'));var csv=require(_0x467d('0x5'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x467d('0x6'));var squel=require(_0x467d('0x7'));var crypto=require(_0x467d('0x8'));var jsforce=require(_0x467d('0x9'));var deskjs=require('desk.js');var toCsv=require(_0x467d('0x5'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x467d('0xa'));var authService=require(_0x467d('0xb'));var qs=require(_0x467d('0xc'));var as=require(_0x467d('0xd'));var hardwareService=require(_0x467d('0xe'));var logger=require('../../config/logger')('api');var utils=require(_0x467d('0xf'));var config=require(_0x467d('0x10'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var jayson=require(_0x467d('0x11'));var client=jayson[_0x467d('0x12')][_0x467d('0x13')]({'port':0x232a});function respondWithRpcPromise(_0x2db993,_0x308429,_0x4f96ba,_0x295ed2){return new BPromise(function(_0x2ef9fb,_0x12a885){var _0x48ce0e=_0x295ed2||client;return _0x48ce0e[_0x467d('0x14')](_0x2db993,_0x4f96ba)[_0x467d('0x15')](function(_0x557ddb){logger[_0x467d('0x16')](_0x467d('0x17'),_0x308429,_0x467d('0x18'));logger[_0x467d('0x19')](_0x467d('0x1a'),_0x308429,_0x467d('0x18'),JSON[_0x467d('0x1b')](_0x557ddb));if(_0x557ddb[_0x467d('0x1c')]){if(_0x557ddb['error'][_0x467d('0x1d')]===0x1f4){logger[_0x467d('0x1c')](_0x467d('0x17'),_0x308429,_0x557ddb[_0x467d('0x1c')][_0x467d('0x1e')]);return _0x12a885(_0x557ddb[_0x467d('0x1c')]['message']);}logger[_0x467d('0x1c')](_0x467d('0x17'),_0x308429,_0x557ddb['error'][_0x467d('0x1e')]);return _0x2ef9fb(_0x557ddb[_0x467d('0x1c')][_0x467d('0x1e')]);}else{logger['info'](_0x467d('0x17'),_0x308429,'request\x20sent');_0x2ef9fb(_0x557ddb[_0x467d('0x1f')][_0x467d('0x1e')]);}})[_0x467d('0x20')](function(_0x4df5c9){logger[_0x467d('0x1c')]('SugarcrmConfiguration,\x20%s,\x20%s',_0x308429,_0x4df5c9);_0x12a885(_0x4df5c9);});});}function respondWithStatusCode(_0xd7e970,_0x123fe9){_0x123fe9=_0x123fe9||0xcc;return function(_0x3c83ba){if(_0x3c83ba){return _0xd7e970[_0x467d('0x21')](_0x123fe9);}return _0xd7e970[_0x467d('0x22')](_0x123fe9)[_0x467d('0x23')]();};}function respondWithResult(_0x455820,_0x34ad2e){_0x34ad2e=_0x34ad2e||0xc8;return function(_0x421039){if(_0x421039){return _0x455820[_0x467d('0x22')](_0x34ad2e)[_0x467d('0x24')](_0x421039);}};}function respondWithFilteredResult(_0x938257,_0x9ca88){return function(_0xf815b0){if(_0xf815b0){var _0xa34272=_0xf815b0[_0x467d('0x25')],_0x2a8d04=_0x9ca88['offset'],_0x24f86f=_0x9ca88[_0x467d('0x26')]+_0x9ca88[_0x467d('0x27')],_0x534e0f;if(_0x24f86f>=_0xa34272){_0x24f86f=_0xa34272;_0x534e0f=0xc8;}else{_0x534e0f=0xce;}_0x938257[_0x467d('0x22')](_0x534e0f);return _0x938257[_0x467d('0x28')](_0x467d('0x29'),_0x2a8d04+'-'+_0x24f86f+'/'+_0xa34272)[_0x467d('0x24')](_0xf815b0);}return null;};}function patchUpdates(_0x2cb8bb){return function(_0x36bd91){try{jsonpatch['apply'](_0x36bd91,_0x2cb8bb,!![]);}catch(_0x579965){return BPromise[_0x467d('0x2a')](_0x579965);}return _0x36bd91[_0x467d('0x2b')]();};}function saveUpdates(_0x59f483,_0x223066){return function(_0x243dc6){if(_0x243dc6){return _0x243dc6[_0x467d('0x2c')](_0x59f483)[_0x467d('0x15')](function(_0x1344ce){return _0x1344ce;});}return null;};}function removeEntity(_0x2cd251,_0xdef816){return function(_0x193475){if(_0x193475){return _0x193475[_0x467d('0x2d')]()[_0x467d('0x15')](function(){_0x2cd251[_0x467d('0x22')](0xcc)[_0x467d('0x23')]();});}};}function handleEntityNotFound(_0x50430c,_0x1be9f4){return function(_0x542bf3){if(!_0x542bf3){_0x50430c['sendStatus'](0x194);}return _0x542bf3;};}function handleError(_0x544f3c,_0x1c3921){_0x1c3921=_0x1c3921||0x1f4;return function(_0x5c9b93){logger['error'](_0x5c9b93[_0x467d('0x2e')]);if(_0x5c9b93[_0x467d('0x2f')]){delete _0x5c9b93[_0x467d('0x2f')];}_0x544f3c[_0x467d('0x22')](_0x1c3921)[_0x467d('0x30')](_0x5c9b93);};}exports[_0x467d('0x31')]=function(_0x3bc5c2,_0xba2785){var _0x25f2e3={},_0x5b8b84={},_0x5f3a70={'count':0x0,'rows':[]};var _0x36f929=_[_0x467d('0x32')](db[_0x467d('0x33')][_0x467d('0x34')],function(_0xdd6b3a){return{'name':_0xdd6b3a['fieldName'],'type':_0xdd6b3a[_0x467d('0x35')][_0x467d('0x36')]};});_0x5b8b84[_0x467d('0x37')]=_['map'](_0x36f929,'name');_0x5b8b84['query']=_[_0x467d('0x38')](_0x3bc5c2[_0x467d('0x39')]);_0x5b8b84[_0x467d('0x3a')]=_[_0x467d('0x3b')](_0x5b8b84['model'],_0x5b8b84['query']);_0x25f2e3[_0x467d('0x3c')]=_['intersection'](_0x5b8b84[_0x467d('0x37')],qs['fields'](_0x3bc5c2['query']['fields']));_0x25f2e3['attributes']=_0x25f2e3['attributes'][_0x467d('0x3d')]?_0x25f2e3['attributes']:_0x5b8b84[_0x467d('0x37')];if(!_0x3bc5c2[_0x467d('0x39')][_0x467d('0x3e')]('nolimit')){_0x25f2e3['limit']=qs[_0x467d('0x27')](_0x3bc5c2[_0x467d('0x39')]['limit']);_0x25f2e3[_0x467d('0x26')]=qs[_0x467d('0x26')](_0x3bc5c2[_0x467d('0x39')][_0x467d('0x26')]);}_0x25f2e3[_0x467d('0x3f')]=qs[_0x467d('0x40')](_0x3bc5c2[_0x467d('0x39')][_0x467d('0x40')]);_0x25f2e3[_0x467d('0x41')]=qs[_0x467d('0x3a')](_[_0x467d('0x42')](_0x3bc5c2[_0x467d('0x39')],_0x5b8b84[_0x467d('0x3a')]),_0x36f929);if(_0x3bc5c2['query'][_0x467d('0x43')]){_0x25f2e3[_0x467d('0x41')]=_[_0x467d('0x44')](_0x25f2e3['where'],{'$or':_[_0x467d('0x32')](_0x36f929,function(_0x21c390){if(_0x21c390[_0x467d('0x35')]!==_0x467d('0x45')){var _0x356c7e={};_0x356c7e[_0x21c390['name']]={'$like':'%'+_0x3bc5c2[_0x467d('0x39')]['filter']+'%'};return _0x356c7e;}})});}_0x25f2e3=_['merge']({},_0x25f2e3,_0x3bc5c2[_0x467d('0x46')]);var _0xb5a080={'where':_0x25f2e3['where']};return db[_0x467d('0x33')]['count'](_0xb5a080)[_0x467d('0x15')](function(_0x464b33){_0x5f3a70[_0x467d('0x25')]=_0x464b33;if(_0x3bc5c2[_0x467d('0x39')][_0x467d('0x47')]){_0x25f2e3[_0x467d('0x48')]=[{'all':!![]}];}return db[_0x467d('0x33')][_0x467d('0x49')](_0x25f2e3);})[_0x467d('0x15')](function(_0x2334f7){_0x5f3a70[_0x467d('0x4a')]=_0x2334f7;return _0x5f3a70;})[_0x467d('0x15')](respondWithFilteredResult(_0xba2785,_0x25f2e3))['catch'](handleError(_0xba2785,null));};exports[_0x467d('0x4b')]=function(_0x36d807,_0x597a5d){var _0x528a9d={'raw':![],'where':{'id':_0x36d807[_0x467d('0x4c')]['id']}},_0x5ed732={};_0x5ed732['model']=_[_0x467d('0x38')](db[_0x467d('0x33')][_0x467d('0x34')]);_0x5ed732['query']=_[_0x467d('0x38')](_0x36d807[_0x467d('0x39')]);_0x5ed732['filters']=_[_0x467d('0x3b')](_0x5ed732['model'],_0x5ed732[_0x467d('0x39')]);_0x528a9d['attributes']=_[_0x467d('0x3b')](_0x5ed732[_0x467d('0x37')],qs[_0x467d('0x4d')](_0x36d807[_0x467d('0x39')][_0x467d('0x4d')]));_0x528a9d[_0x467d('0x3c')]=_0x528a9d['attributes'][_0x467d('0x3d')]?_0x528a9d[_0x467d('0x3c')]:_0x5ed732[_0x467d('0x37')];if(_0x36d807[_0x467d('0x39')][_0x467d('0x47')]){_0x528a9d[_0x467d('0x48')]=[{'all':!![]}];}_0x528a9d=_['merge']({},_0x528a9d,_0x36d807[_0x467d('0x46')]);return db['SugarcrmConfiguration'][_0x467d('0x4e')](_0x528a9d)['then'](handleEntityNotFound(_0x597a5d,null))[_0x467d('0x15')](respondWithResult(_0x597a5d,null))['catch'](handleError(_0x597a5d,null));};exports['create']=function(_0x2d1216,_0x1a8c99){return db[_0x467d('0x33')]['create'](_0x2d1216[_0x467d('0x4f')],{})[_0x467d('0x15')](respondWithResult(_0x1a8c99,0xc9))[_0x467d('0x20')](handleError(_0x1a8c99,null));};exports['update']=function(_0x5c0983,_0x108ffe){if(_0x5c0983[_0x467d('0x4f')]['id']){delete _0x5c0983['body']['id'];}return db['SugarcrmConfiguration'][_0x467d('0x4e')]({'where':{'id':_0x5c0983[_0x467d('0x4c')]['id']}})[_0x467d('0x15')](handleEntityNotFound(_0x108ffe,null))[_0x467d('0x15')](saveUpdates(_0x5c0983['body'],null))[_0x467d('0x15')](respondWithResult(_0x108ffe,null))[_0x467d('0x20')](handleError(_0x108ffe,null));};exports[_0x467d('0x2d')]=function(_0x381572,_0x1c7cfa){return db['SugarcrmConfiguration'][_0x467d('0x4e')]({'where':{'id':_0x381572[_0x467d('0x4c')]['id']}})[_0x467d('0x15')](handleEntityNotFound(_0x1c7cfa,null))[_0x467d('0x15')](removeEntity(_0x1c7cfa,null))['catch'](handleError(_0x1c7cfa,null));};exports[_0x467d('0x50')]=function(_0x272a63,_0x293725,_0x2ccb3c){var _0x459e69={};var _0x5a2282={};var _0x30a3bd;var _0x52e541;return db['SugarcrmConfiguration'][_0x467d('0x51')]({'where':{'id':_0x272a63[_0x467d('0x4c')]['id']}})[_0x467d('0x15')](handleEntityNotFound(_0x293725,null))['then'](function(_0x208f20){if(_0x208f20){_0x30a3bd=_0x208f20;_0x5a2282[_0x467d('0x37')]=_[_0x467d('0x38')](db[_0x467d('0x52')][_0x467d('0x34')]);_0x5a2282[_0x467d('0x39')]=_['keys'](_0x272a63[_0x467d('0x39')]);_0x5a2282[_0x467d('0x3a')]=_['intersection'](_0x5a2282[_0x467d('0x37')],_0x5a2282[_0x467d('0x39')]);_0x459e69['attributes']=_[_0x467d('0x3b')](_0x5a2282[_0x467d('0x37')],qs[_0x467d('0x4d')](_0x272a63[_0x467d('0x39')][_0x467d('0x4d')]));_0x459e69['attributes']=_0x459e69[_0x467d('0x3c')][_0x467d('0x3d')]?_0x459e69['attributes']:_0x5a2282[_0x467d('0x37')];_0x459e69['order']=qs[_0x467d('0x40')](_0x272a63[_0x467d('0x39')][_0x467d('0x40')]);_0x459e69['where']=qs[_0x467d('0x3a')](_[_0x467d('0x42')](_0x272a63[_0x467d('0x39')],_0x5a2282[_0x467d('0x3a')]));if(_0x272a63[_0x467d('0x39')][_0x467d('0x43')]){_0x459e69[_0x467d('0x41')]=_['merge'](_0x459e69[_0x467d('0x41')],{'$or':_[_0x467d('0x32')](_0x459e69[_0x467d('0x3c')],function(_0x5d56a4){var _0xe1df76={};_0xe1df76[_0x5d56a4]={'$like':'%'+_0x272a63[_0x467d('0x39')][_0x467d('0x43')]+'%'};return _0xe1df76;})});}_0x459e69=_[_0x467d('0x44')]({},_0x459e69,_0x272a63[_0x467d('0x46')]);return _0x30a3bd[_0x467d('0x50')](_0x459e69);}})[_0x467d('0x15')](function(_0x103360){if(_0x103360){_0x52e541=_0x103360[_0x467d('0x3d')];if(!_0x272a63[_0x467d('0x39')][_0x467d('0x3e')](_0x467d('0x53'))){_0x459e69[_0x467d('0x27')]=qs[_0x467d('0x27')](_0x272a63[_0x467d('0x39')][_0x467d('0x27')]);_0x459e69[_0x467d('0x26')]=qs[_0x467d('0x26')](_0x272a63[_0x467d('0x39')][_0x467d('0x26')]);}return _0x30a3bd[_0x467d('0x50')](_0x459e69);}})[_0x467d('0x15')](function(_0x4b6cf8){if(_0x4b6cf8){return _0x4b6cf8?{'count':_0x52e541,'rows':_0x4b6cf8}:null;}})[_0x467d('0x15')](respondWithResult(_0x293725,null))['catch'](handleError(_0x293725,null));};exports[_0x467d('0x54')]=function(_0x56db2b,_0x1a3fcd,_0x57487b){var _0x36f608={};var _0x5151a4={};var _0x3719f4;var _0x28f93a;return db['SugarcrmConfiguration']['findOne']({'where':{'id':_0x56db2b['params']['id']}})[_0x467d('0x15')](handleEntityNotFound(_0x1a3fcd,null))[_0x467d('0x15')](function(_0x5ca2f8){if(_0x5ca2f8){_0x3719f4=_0x5ca2f8;_0x5151a4['model']=_[_0x467d('0x38')](db['SugarcrmField'][_0x467d('0x34')]);_0x5151a4[_0x467d('0x39')]=_[_0x467d('0x38')](_0x56db2b[_0x467d('0x39')]);_0x5151a4['filters']=_[_0x467d('0x3b')](_0x5151a4[_0x467d('0x37')],_0x5151a4[_0x467d('0x39')]);_0x36f608[_0x467d('0x3c')]=_[_0x467d('0x3b')](_0x5151a4[_0x467d('0x37')],qs['fields'](_0x56db2b[_0x467d('0x39')][_0x467d('0x4d')]));_0x36f608[_0x467d('0x3c')]=_0x36f608[_0x467d('0x3c')][_0x467d('0x3d')]?_0x36f608['attributes']:_0x5151a4[_0x467d('0x37')];_0x36f608[_0x467d('0x3f')]=qs[_0x467d('0x40')](_0x56db2b['query'][_0x467d('0x40')]);_0x36f608[_0x467d('0x41')]=qs['filters'](_[_0x467d('0x42')](_0x56db2b[_0x467d('0x39')],_0x5151a4[_0x467d('0x3a')]));if(_0x56db2b[_0x467d('0x39')][_0x467d('0x43')]){_0x36f608[_0x467d('0x41')]=_[_0x467d('0x44')](_0x36f608[_0x467d('0x41')],{'$or':_[_0x467d('0x32')](_0x36f608[_0x467d('0x3c')],function(_0x462172){var _0x1f3778={};_0x1f3778[_0x462172]={'$like':'%'+_0x56db2b['query']['filter']+'%'};return _0x1f3778;})});}_0x36f608=_['merge']({},_0x36f608,_0x56db2b['options']);return _0x3719f4[_0x467d('0x54')](_0x36f608);}})[_0x467d('0x15')](function(_0x84e95a){if(_0x84e95a){_0x28f93a=_0x84e95a[_0x467d('0x3d')];if(!_0x56db2b['query']['hasOwnProperty'](_0x467d('0x53'))){_0x36f608[_0x467d('0x27')]=qs[_0x467d('0x27')](_0x56db2b[_0x467d('0x39')][_0x467d('0x27')]);_0x36f608[_0x467d('0x26')]=qs['offset'](_0x56db2b[_0x467d('0x39')][_0x467d('0x26')]);}return _0x3719f4[_0x467d('0x54')](_0x36f608);}})[_0x467d('0x15')](function(_0x130222){if(_0x130222){return _0x130222?{'count':_0x28f93a,'rows':_0x130222}:null;}})[_0x467d('0x15')](respondWithResult(_0x1a3fcd,null))[_0x467d('0x20')](handleError(_0x1a3fcd,null));};exports['getDescriptions']=function(_0x58e5d7,_0x26e524,_0xa59e7b){var _0x28cf0c={};var _0x18d9ca={};var _0x4d1ea5;var _0x5bc683;return db[_0x467d('0x33')]['findOne']({'where':{'id':_0x58e5d7['params']['id']}})[_0x467d('0x15')](handleEntityNotFound(_0x26e524,null))['then'](function(_0xd59c0f){if(_0xd59c0f){_0x4d1ea5=_0xd59c0f;_0x18d9ca['model']=_[_0x467d('0x38')](db[_0x467d('0x52')]['rawAttributes']);_0x18d9ca[_0x467d('0x39')]=_[_0x467d('0x38')](_0x58e5d7[_0x467d('0x39')]);_0x18d9ca['filters']=_[_0x467d('0x3b')](_0x18d9ca[_0x467d('0x37')],_0x18d9ca[_0x467d('0x39')]);_0x28cf0c[_0x467d('0x3c')]=_[_0x467d('0x3b')](_0x18d9ca[_0x467d('0x37')],qs[_0x467d('0x4d')](_0x58e5d7[_0x467d('0x39')][_0x467d('0x4d')]));_0x28cf0c[_0x467d('0x3c')]=_0x28cf0c['attributes'][_0x467d('0x3d')]?_0x28cf0c[_0x467d('0x3c')]:_0x18d9ca[_0x467d('0x37')];_0x28cf0c[_0x467d('0x3f')]=qs[_0x467d('0x40')](_0x58e5d7[_0x467d('0x39')]['sort']);_0x28cf0c['where']=qs[_0x467d('0x3a')](_[_0x467d('0x42')](_0x58e5d7[_0x467d('0x39')],_0x18d9ca[_0x467d('0x3a')]));if(_0x58e5d7[_0x467d('0x39')]['filter']){_0x28cf0c[_0x467d('0x41')]=_[_0x467d('0x44')](_0x28cf0c[_0x467d('0x41')],{'$or':_[_0x467d('0x32')](_0x28cf0c['attributes'],function(_0x5bfa1b){var _0x56184b={};_0x56184b[_0x5bfa1b]={'$like':'%'+_0x58e5d7[_0x467d('0x39')]['filter']+'%'};return _0x56184b;})});}_0x28cf0c=_[_0x467d('0x44')]({},_0x28cf0c,_0x58e5d7[_0x467d('0x46')]);return _0x4d1ea5[_0x467d('0x55')](_0x28cf0c);}})['then'](function(_0x5aea34){if(_0x5aea34){_0x5bc683=_0x5aea34[_0x467d('0x3d')];if(!_0x58e5d7[_0x467d('0x39')][_0x467d('0x3e')](_0x467d('0x53'))){_0x28cf0c[_0x467d('0x27')]=qs[_0x467d('0x27')](_0x58e5d7[_0x467d('0x39')]['limit']);_0x28cf0c[_0x467d('0x26')]=qs[_0x467d('0x26')](_0x58e5d7[_0x467d('0x39')]['offset']);}return _0x4d1ea5['getDescriptions'](_0x28cf0c);}})[_0x467d('0x15')](function(_0x2c84c1){if(_0x2c84c1){return _0x2c84c1?{'count':_0x5bc683,'rows':_0x2c84c1}:null;}})['then'](respondWithResult(_0x26e524,null))['catch'](handleError(_0x26e524,null));};
\ No newline at end of file
+var _0xdf65=['squel','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','json','offset','undefined','limit','count','Content-Range','apply','save','update','destroy','status','error','stack','name','send','index','SugarcrmConfiguration','fieldName','type','key','model','map','keys','filters','intersection','query','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','then','include','findAll','rows','show','params','rawAttributes','fields','includeAll','options','find','create','body','catch','getFields','findOne','SugarcrmField','getSubjects','getDescriptions','eml-format','zip-dir','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra'];(function(_0xf3bf0b,_0x5c17ed){var _0x3e5c44=function(_0x111dd6){while(--_0x111dd6){_0xf3bf0b['push'](_0xf3bf0b['shift']());}};_0x3e5c44(++_0x5c17ed);}(_0xdf65,0x13d));var _0x5df6=function(_0x115149,_0x1fca9e){_0x115149=_0x115149-0x0;var _0x2a91dc=_0xdf65[_0x115149];return _0x2a91dc;};'use strict';var emlformat=require(_0x5df6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x5df6('0x1'));var jsonpatch=require(_0x5df6('0x2'));var rp=require(_0x5df6('0x3'));var moment=require(_0x5df6('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x5df6('0x5'));var path=require(_0x5df6('0x6'));var sox=require(_0x5df6('0x7'));var csv=require(_0x5df6('0x8'));var ejs=require(_0x5df6('0x9'));var fs=require('fs');var fs_extra=require(_0x5df6('0xa'));var _=require('lodash');var squel=require(_0x5df6('0xb'));var crypto=require(_0x5df6('0xc'));var jsforce=require(_0x5df6('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x5df6('0x8'));var querystring=require(_0x5df6('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x5df6('0xf'));var qs=require(_0x5df6('0x10'));var as=require(_0x5df6('0x11'));var hardwareService=require(_0x5df6('0x12'));var logger=require(_0x5df6('0x13'))(_0x5df6('0x14'));var utils=require(_0x5df6('0x15'));var config=require(_0x5df6('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x5df6('0x17'))['db'];function respondWithStatusCode(_0x10cf4f,_0xd8be85){_0xd8be85=_0xd8be85||0xcc;return function(_0x577f2a){if(_0x577f2a){return _0x10cf4f[_0x5df6('0x18')](_0xd8be85);}return _0x10cf4f['status'](_0xd8be85)[_0x5df6('0x19')]();};}function respondWithResult(_0x220aaa,_0x3b4c45){_0x3b4c45=_0x3b4c45||0xc8;return function(_0x50862c){if(_0x50862c){return _0x220aaa['status'](_0x3b4c45)[_0x5df6('0x1a')](_0x50862c);}};}function respondWithFilteredResult(_0x3aa495,_0x3ff0ad){return function(_0x4d2aa7){if(_0x4d2aa7){var _0x5281fb=typeof _0x3ff0ad[_0x5df6('0x1b')]===_0x5df6('0x1c')&&typeof _0x3ff0ad[_0x5df6('0x1d')]===_0x5df6('0x1c');var _0x339f70=_0x4d2aa7[_0x5df6('0x1e')];var _0x3827f7=_0x5281fb?0x0:_0x3ff0ad['offset'];var _0x38adc1=_0x5281fb?_0x4d2aa7['count']:_0x3ff0ad[_0x5df6('0x1b')]+_0x3ff0ad[_0x5df6('0x1d')];var _0x2e5de3;if(_0x38adc1>=_0x339f70){_0x38adc1=_0x339f70;_0x2e5de3=0xc8;}else{_0x2e5de3=0xce;}_0x3aa495['status'](_0x2e5de3);return _0x3aa495['set'](_0x5df6('0x1f'),_0x3827f7+'-'+_0x38adc1+'/'+_0x339f70)[_0x5df6('0x1a')](_0x4d2aa7);}return null;};}function patchUpdates(_0x5b3358){return function(_0x345ccc){try{jsonpatch[_0x5df6('0x20')](_0x345ccc,_0x5b3358,!![]);}catch(_0x55a71b){return BPromise['reject'](_0x55a71b);}return _0x345ccc[_0x5df6('0x21')]();};}function saveUpdates(_0x200dee,_0x19927b){return function(_0x439570){if(_0x439570){return _0x439570[_0x5df6('0x22')](_0x200dee)['then'](function(_0x338f5b){return _0x338f5b;});}return null;};}function removeEntity(_0x5851e2,_0x398539){return function(_0x2388e9){if(_0x2388e9){return _0x2388e9[_0x5df6('0x23')]()['then'](function(){_0x5851e2[_0x5df6('0x24')](0xcc)[_0x5df6('0x19')]();});}};}function handleEntityNotFound(_0x332a76,_0x242847){return function(_0x4ffbd7){if(!_0x4ffbd7){_0x332a76[_0x5df6('0x18')](0x194);}return _0x4ffbd7;};}function handleError(_0x3e61fd,_0x176495){_0x176495=_0x176495||0x1f4;return function(_0x13fbb8){logger[_0x5df6('0x25')](_0x13fbb8[_0x5df6('0x26')]);if(_0x13fbb8[_0x5df6('0x27')]){delete _0x13fbb8[_0x5df6('0x27')];}_0x3e61fd[_0x5df6('0x24')](_0x176495)[_0x5df6('0x28')](_0x13fbb8);};}exports[_0x5df6('0x29')]=function(_0x37f490,_0x60d6c8){var _0x1a4642={},_0x35a545={},_0x327f69={'count':0x0,'rows':[]};var _0x3d1dd7=_['map'](db[_0x5df6('0x2a')]['rawAttributes'],function(_0x516aea){return{'name':_0x516aea[_0x5df6('0x2b')],'type':_0x516aea[_0x5df6('0x2c')][_0x5df6('0x2d')]};});_0x35a545[_0x5df6('0x2e')]=_[_0x5df6('0x2f')](_0x3d1dd7,_0x5df6('0x27'));_0x35a545['query']=_[_0x5df6('0x30')](_0x37f490['query']);_0x35a545[_0x5df6('0x31')]=_[_0x5df6('0x32')](_0x35a545[_0x5df6('0x2e')],_0x35a545[_0x5df6('0x33')]);_0x1a4642[_0x5df6('0x34')]=_['intersection'](_0x35a545[_0x5df6('0x2e')],qs['fields'](_0x37f490['query']['fields']));_0x1a4642[_0x5df6('0x34')]=_0x1a4642[_0x5df6('0x34')][_0x5df6('0x35')]?_0x1a4642[_0x5df6('0x34')]:_0x35a545[_0x5df6('0x2e')];if(!_0x37f490[_0x5df6('0x33')][_0x5df6('0x36')](_0x5df6('0x37'))){_0x1a4642['limit']=qs[_0x5df6('0x1d')](_0x37f490['query'][_0x5df6('0x1d')]);_0x1a4642[_0x5df6('0x1b')]=qs[_0x5df6('0x1b')](_0x37f490[_0x5df6('0x33')][_0x5df6('0x1b')]);}_0x1a4642[_0x5df6('0x38')]=qs[_0x5df6('0x39')](_0x37f490['query'][_0x5df6('0x39')]);_0x1a4642[_0x5df6('0x3a')]=qs[_0x5df6('0x31')](_[_0x5df6('0x3b')](_0x37f490['query'],_0x35a545[_0x5df6('0x31')]),_0x3d1dd7);if(_0x37f490[_0x5df6('0x33')][_0x5df6('0x3c')]){_0x1a4642['where']=_['merge'](_0x1a4642[_0x5df6('0x3a')],{'$or':_[_0x5df6('0x2f')](_0x3d1dd7,function(_0x5ed024){if(_0x5ed024['type']!==_0x5df6('0x3d')){var _0x2c5343={};_0x2c5343[_0x5ed024[_0x5df6('0x27')]]={'$like':'%'+_0x37f490['query']['filter']+'%'};return _0x2c5343;}})});}_0x1a4642=_[_0x5df6('0x3e')]({},_0x1a4642,_0x37f490['options']);var _0x1608fb={'where':_0x1a4642[_0x5df6('0x3a')]};return db[_0x5df6('0x2a')]['count'](_0x1608fb)[_0x5df6('0x3f')](function(_0x34c152){_0x327f69[_0x5df6('0x1e')]=_0x34c152;if(_0x37f490[_0x5df6('0x33')]['includeAll']){_0x1a4642[_0x5df6('0x40')]=[{'all':!![]}];}return db[_0x5df6('0x2a')][_0x5df6('0x41')](_0x1a4642);})[_0x5df6('0x3f')](function(_0x549cc8){_0x327f69[_0x5df6('0x42')]=_0x549cc8;return _0x327f69;})[_0x5df6('0x3f')](respondWithFilteredResult(_0x60d6c8,_0x1a4642))['catch'](handleError(_0x60d6c8,null));};exports[_0x5df6('0x43')]=function(_0x49cf39,_0x52769c){var _0x5d6a66={'raw':![],'where':{'id':_0x49cf39[_0x5df6('0x44')]['id']}},_0x7f9d2={};_0x7f9d2[_0x5df6('0x2e')]=_[_0x5df6('0x30')](db['SugarcrmConfiguration'][_0x5df6('0x45')]);_0x7f9d2[_0x5df6('0x33')]=_[_0x5df6('0x30')](_0x49cf39['query']);_0x7f9d2[_0x5df6('0x31')]=_[_0x5df6('0x32')](_0x7f9d2['model'],_0x7f9d2[_0x5df6('0x33')]);_0x5d6a66['attributes']=_[_0x5df6('0x32')](_0x7f9d2[_0x5df6('0x2e')],qs[_0x5df6('0x46')](_0x49cf39['query']['fields']));_0x5d6a66[_0x5df6('0x34')]=_0x5d6a66[_0x5df6('0x34')]['length']?_0x5d6a66[_0x5df6('0x34')]:_0x7f9d2['model'];if(_0x49cf39['query'][_0x5df6('0x47')]){_0x5d6a66[_0x5df6('0x40')]=[{'all':!![]}];}_0x5d6a66=_[_0x5df6('0x3e')]({},_0x5d6a66,_0x49cf39[_0x5df6('0x48')]);return db[_0x5df6('0x2a')][_0x5df6('0x49')](_0x5d6a66)[_0x5df6('0x3f')](handleEntityNotFound(_0x52769c,null))[_0x5df6('0x3f')](respondWithResult(_0x52769c,null))['catch'](handleError(_0x52769c,null));};exports[_0x5df6('0x4a')]=function(_0x38e7ef,_0x2c62d7){return db[_0x5df6('0x2a')][_0x5df6('0x4a')](_0x38e7ef[_0x5df6('0x4b')],{})['then'](respondWithResult(_0x2c62d7,0xc9))[_0x5df6('0x4c')](handleError(_0x2c62d7,null));};exports[_0x5df6('0x22')]=function(_0x237f4c,_0x1a783e){if(_0x237f4c['body']['id']){delete _0x237f4c[_0x5df6('0x4b')]['id'];}return db['SugarcrmConfiguration']['find']({'where':{'id':_0x237f4c[_0x5df6('0x44')]['id']}})[_0x5df6('0x3f')](handleEntityNotFound(_0x1a783e,null))[_0x5df6('0x3f')](saveUpdates(_0x237f4c[_0x5df6('0x4b')],null))['then'](respondWithResult(_0x1a783e,null))['catch'](handleError(_0x1a783e,null));};exports[_0x5df6('0x23')]=function(_0x1edfb7,_0x4967bb){return db[_0x5df6('0x2a')][_0x5df6('0x49')]({'where':{'id':_0x1edfb7[_0x5df6('0x44')]['id']}})[_0x5df6('0x3f')](handleEntityNotFound(_0x4967bb,null))[_0x5df6('0x3f')](removeEntity(_0x4967bb,null))[_0x5df6('0x4c')](handleError(_0x4967bb,null));};exports[_0x5df6('0x4d')]=function(_0x6beec1,_0x46de68,_0x1d3feb){var _0x5dc51c={};var _0x40f2e5={};var _0x1b75cc;var _0x3ca3f5;return db[_0x5df6('0x2a')][_0x5df6('0x4e')]({'where':{'id':_0x6beec1[_0x5df6('0x44')]['id']}})[_0x5df6('0x3f')](handleEntityNotFound(_0x46de68,null))['then'](function(_0x565481){if(_0x565481){_0x1b75cc=_0x565481;_0x40f2e5[_0x5df6('0x2e')]=_[_0x5df6('0x30')](db[_0x5df6('0x4f')][_0x5df6('0x45')]);_0x40f2e5[_0x5df6('0x33')]=_[_0x5df6('0x30')](_0x6beec1[_0x5df6('0x33')]);_0x40f2e5['filters']=_[_0x5df6('0x32')](_0x40f2e5[_0x5df6('0x2e')],_0x40f2e5['query']);_0x5dc51c[_0x5df6('0x34')]=_[_0x5df6('0x32')](_0x40f2e5['model'],qs[_0x5df6('0x46')](_0x6beec1[_0x5df6('0x33')][_0x5df6('0x46')]));_0x5dc51c['attributes']=_0x5dc51c[_0x5df6('0x34')][_0x5df6('0x35')]?_0x5dc51c[_0x5df6('0x34')]:_0x40f2e5[_0x5df6('0x2e')];_0x5dc51c[_0x5df6('0x38')]=qs['sort'](_0x6beec1['query']['sort']);_0x5dc51c[_0x5df6('0x3a')]=qs[_0x5df6('0x31')](_[_0x5df6('0x3b')](_0x6beec1['query'],_0x40f2e5[_0x5df6('0x31')]));if(_0x6beec1['query'][_0x5df6('0x3c')]){_0x5dc51c[_0x5df6('0x3a')]=_[_0x5df6('0x3e')](_0x5dc51c[_0x5df6('0x3a')],{'$or':_['map'](_0x5dc51c['attributes'],function(_0x4ac672){var _0x3053c1={};_0x3053c1[_0x4ac672]={'$like':'%'+_0x6beec1[_0x5df6('0x33')][_0x5df6('0x3c')]+'%'};return _0x3053c1;})});}_0x5dc51c=_[_0x5df6('0x3e')]({},_0x5dc51c,_0x6beec1[_0x5df6('0x48')]);return _0x1b75cc[_0x5df6('0x4d')](_0x5dc51c);}})[_0x5df6('0x3f')](function(_0x348fc3){if(_0x348fc3){_0x3ca3f5=_0x348fc3['length'];if(!_0x6beec1['query'][_0x5df6('0x36')](_0x5df6('0x37'))){_0x5dc51c[_0x5df6('0x1d')]=qs[_0x5df6('0x1d')](_0x6beec1[_0x5df6('0x33')][_0x5df6('0x1d')]);_0x5dc51c[_0x5df6('0x1b')]=qs[_0x5df6('0x1b')](_0x6beec1[_0x5df6('0x33')]['offset']);}return _0x1b75cc['getFields'](_0x5dc51c);}})[_0x5df6('0x3f')](function(_0x97fffa){if(_0x97fffa){return _0x97fffa?{'count':_0x3ca3f5,'rows':_0x97fffa}:null;}})[_0x5df6('0x3f')](respondWithResult(_0x46de68,null))[_0x5df6('0x4c')](handleError(_0x46de68,null));};exports['getSubjects']=function(_0x5a189a,_0x3fd0b5,_0x390f9f){var _0x4b6237={};var _0x5e736e={};var _0x751c82;var _0xb273e;return db[_0x5df6('0x2a')][_0x5df6('0x4e')]({'where':{'id':_0x5a189a[_0x5df6('0x44')]['id']}})['then'](handleEntityNotFound(_0x3fd0b5,null))[_0x5df6('0x3f')](function(_0x41b3a7){if(_0x41b3a7){_0x751c82=_0x41b3a7;_0x5e736e[_0x5df6('0x2e')]=_[_0x5df6('0x30')](db['SugarcrmField'][_0x5df6('0x45')]);_0x5e736e[_0x5df6('0x33')]=_[_0x5df6('0x30')](_0x5a189a['query']);_0x5e736e[_0x5df6('0x31')]=_[_0x5df6('0x32')](_0x5e736e[_0x5df6('0x2e')],_0x5e736e[_0x5df6('0x33')]);_0x4b6237['attributes']=_['intersection'](_0x5e736e[_0x5df6('0x2e')],qs[_0x5df6('0x46')](_0x5a189a[_0x5df6('0x33')][_0x5df6('0x46')]));_0x4b6237[_0x5df6('0x34')]=_0x4b6237['attributes']['length']?_0x4b6237['attributes']:_0x5e736e[_0x5df6('0x2e')];_0x4b6237[_0x5df6('0x38')]=qs[_0x5df6('0x39')](_0x5a189a[_0x5df6('0x33')][_0x5df6('0x39')]);_0x4b6237['where']=qs['filters'](_[_0x5df6('0x3b')](_0x5a189a['query'],_0x5e736e[_0x5df6('0x31')]));if(_0x5a189a[_0x5df6('0x33')]['filter']){_0x4b6237['where']=_['merge'](_0x4b6237[_0x5df6('0x3a')],{'$or':_[_0x5df6('0x2f')](_0x4b6237['attributes'],function(_0x4ba447){var _0x5b8760={};_0x5b8760[_0x4ba447]={'$like':'%'+_0x5a189a[_0x5df6('0x33')][_0x5df6('0x3c')]+'%'};return _0x5b8760;})});}_0x4b6237=_[_0x5df6('0x3e')]({},_0x4b6237,_0x5a189a[_0x5df6('0x48')]);return _0x751c82[_0x5df6('0x50')](_0x4b6237);}})[_0x5df6('0x3f')](function(_0x3eebe4){if(_0x3eebe4){_0xb273e=_0x3eebe4['length'];if(!_0x5a189a[_0x5df6('0x33')]['hasOwnProperty'](_0x5df6('0x37'))){_0x4b6237[_0x5df6('0x1d')]=qs[_0x5df6('0x1d')](_0x5a189a[_0x5df6('0x33')][_0x5df6('0x1d')]);_0x4b6237[_0x5df6('0x1b')]=qs[_0x5df6('0x1b')](_0x5a189a[_0x5df6('0x33')][_0x5df6('0x1b')]);}return _0x751c82[_0x5df6('0x50')](_0x4b6237);}})[_0x5df6('0x3f')](function(_0xba102c){if(_0xba102c){return _0xba102c?{'count':_0xb273e,'rows':_0xba102c}:null;}})[_0x5df6('0x3f')](respondWithResult(_0x3fd0b5,null))[_0x5df6('0x4c')](handleError(_0x3fd0b5,null));};exports[_0x5df6('0x51')]=function(_0x27e596,_0x1597a4,_0x1641cc){var _0x3aeb80={};var _0x234c1f={};var _0x52ea14;var _0x3f06e2;return db[_0x5df6('0x2a')][_0x5df6('0x4e')]({'where':{'id':_0x27e596[_0x5df6('0x44')]['id']}})[_0x5df6('0x3f')](handleEntityNotFound(_0x1597a4,null))[_0x5df6('0x3f')](function(_0x30e721){if(_0x30e721){_0x52ea14=_0x30e721;_0x234c1f[_0x5df6('0x2e')]=_[_0x5df6('0x30')](db[_0x5df6('0x4f')]['rawAttributes']);_0x234c1f['query']=_['keys'](_0x27e596['query']);_0x234c1f['filters']=_[_0x5df6('0x32')](_0x234c1f[_0x5df6('0x2e')],_0x234c1f[_0x5df6('0x33')]);_0x3aeb80[_0x5df6('0x34')]=_[_0x5df6('0x32')](_0x234c1f['model'],qs[_0x5df6('0x46')](_0x27e596['query'][_0x5df6('0x46')]));_0x3aeb80[_0x5df6('0x34')]=_0x3aeb80['attributes'][_0x5df6('0x35')]?_0x3aeb80[_0x5df6('0x34')]:_0x234c1f['model'];_0x3aeb80[_0x5df6('0x38')]=qs[_0x5df6('0x39')](_0x27e596[_0x5df6('0x33')][_0x5df6('0x39')]);_0x3aeb80[_0x5df6('0x3a')]=qs['filters'](_['pick'](_0x27e596['query'],_0x234c1f['filters']));if(_0x27e596[_0x5df6('0x33')][_0x5df6('0x3c')]){_0x3aeb80[_0x5df6('0x3a')]=_[_0x5df6('0x3e')](_0x3aeb80[_0x5df6('0x3a')],{'$or':_[_0x5df6('0x2f')](_0x3aeb80['attributes'],function(_0x14c4f1){var _0x28fc43={};_0x28fc43[_0x14c4f1]={'$like':'%'+_0x27e596[_0x5df6('0x33')][_0x5df6('0x3c')]+'%'};return _0x28fc43;})});}_0x3aeb80=_[_0x5df6('0x3e')]({},_0x3aeb80,_0x27e596['options']);return _0x52ea14[_0x5df6('0x51')](_0x3aeb80);}})[_0x5df6('0x3f')](function(_0x49125b){if(_0x49125b){_0x3f06e2=_0x49125b[_0x5df6('0x35')];if(!_0x27e596[_0x5df6('0x33')]['hasOwnProperty'](_0x5df6('0x37'))){_0x3aeb80[_0x5df6('0x1d')]=qs[_0x5df6('0x1d')](_0x27e596[_0x5df6('0x33')]['limit']);_0x3aeb80['offset']=qs['offset'](_0x27e596[_0x5df6('0x33')][_0x5df6('0x1b')]);}return _0x52ea14[_0x5df6('0x51')](_0x3aeb80);}})[_0x5df6('0x3f')](function(_0x5504c9){if(_0x5504c9){return _0x5504c9?{'count':_0x3f06e2,'rows':_0x5504c9}:null;}})['then'](respondWithResult(_0x1597a4,null))['catch'](handleError(_0x1597a4,null));};
\ No newline at end of file