Built motion from commit 37e1ed56.|2.6.29
[motion2.git] / server / api / intSugarcrmConfiguration / intSugarcrmConfiguration.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xed12=['where','VIRTUAL','merge','includeAll','include','findAll','rows','catch','show','length','options','find','create','body','params','getFields','findOne','SugarcrmField','order','pick','filter','getSubjects','getDescriptions','eml-format','zip-dir','fast-json-patch','bluebird','util','sox','ejs','fs-extra','lodash','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','Content-Range','apply','reject','save','update','destroy','then','end','stack','name','index','map','SugarcrmConfiguration','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','nolimit','sort','filters'];(function(_0x5b0f02,_0x418043){var _0x300632=function(_0x447174){while(--_0x447174){_0x5b0f02['push'](_0x5b0f02['shift']());}};_0x300632(++_0x418043);}(_0xed12,0xb1));var _0x2ed1=function(_0x65aeaf,_0x4bbaf9){_0x65aeaf=_0x65aeaf-0x0;var _0x505356=_0xed12[_0x65aeaf];return _0x505356;};'use strict';var emlformat=require(_0x2ed1('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x2ed1('0x1'));var jsonpatch=require(_0x2ed1('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x2ed1('0x3'));var Mustache=require('mustache');var util=require(_0x2ed1('0x4'));var path=require('path');var sox=require(_0x2ed1('0x5'));var csv=require('to-csv');var ejs=require(_0x2ed1('0x6'));var fs=require('fs');var fs_extra=require(_0x2ed1('0x7'));var _=require(_0x2ed1('0x8'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x2ed1('0x9'));var toCsv=require(_0x2ed1('0xa'));var querystring=require(_0x2ed1('0xb'));var Papa=require('papaparse');var Redis=require(_0x2ed1('0xc'));var authService=require(_0x2ed1('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0x2ed1('0xe'));var hardwareService=require(_0x2ed1('0xf'));var logger=require('../../config/logger')('api');var utils=require(_0x2ed1('0x10'));var config=require(_0x2ed1('0x11'));var licenseUtil=require(_0x2ed1('0x12'));var db=require(_0x2ed1('0x13'))['db'];function respondWithStatusCode(_0x1581b2,_0x598540){_0x598540=_0x598540||0xcc;return function(_0x103d5e){if(_0x103d5e){return _0x1581b2[_0x2ed1('0x14')](_0x598540);}return _0x1581b2[_0x2ed1('0x15')](_0x598540)['end']();};}function respondWithResult(_0x16545c,_0x19f35a){_0x19f35a=_0x19f35a||0xc8;return function(_0x2dcfd3){if(_0x2dcfd3){return _0x16545c[_0x2ed1('0x15')](_0x19f35a)[_0x2ed1('0x16')](_0x2dcfd3);}};}function respondWithFilteredResult(_0x41806c,_0x2191f1){return function(_0x56ca87){if(_0x56ca87){var _0x18c1b2=typeof _0x2191f1[_0x2ed1('0x17')]==='undefined'&&typeof _0x2191f1[_0x2ed1('0x18')]===_0x2ed1('0x19');var _0x574129=_0x56ca87[_0x2ed1('0x1a')];var _0x8c2398=_0x18c1b2?0x0:_0x2191f1[_0x2ed1('0x17')];var _0x1108e6=_0x18c1b2?_0x56ca87[_0x2ed1('0x1a')]:_0x2191f1[_0x2ed1('0x17')]+_0x2191f1[_0x2ed1('0x18')];var _0x18e130;if(_0x1108e6>=_0x574129){_0x1108e6=_0x574129;_0x18e130=0xc8;}else{_0x18e130=0xce;}_0x41806c[_0x2ed1('0x15')](_0x18e130);return _0x41806c['set'](_0x2ed1('0x1b'),_0x8c2398+'-'+_0x1108e6+'/'+_0x574129)[_0x2ed1('0x16')](_0x56ca87);}return null;};}function patchUpdates(_0x787429){return function(_0x74c0c2){try{jsonpatch[_0x2ed1('0x1c')](_0x74c0c2,_0x787429,!![]);}catch(_0x1b095a){return BPromise[_0x2ed1('0x1d')](_0x1b095a);}return _0x74c0c2[_0x2ed1('0x1e')]();};}function saveUpdates(_0x162c33,_0x31f7f9){return function(_0x317811){if(_0x317811){return _0x317811[_0x2ed1('0x1f')](_0x162c33)['then'](function(_0x441183){return _0x441183;});}return null;};}function removeEntity(_0x21d1e5,_0x1fa7ce){return function(_0x190dff){if(_0x190dff){return _0x190dff[_0x2ed1('0x20')]()[_0x2ed1('0x21')](function(){_0x21d1e5[_0x2ed1('0x15')](0xcc)[_0x2ed1('0x22')]();});}};}function handleEntityNotFound(_0x4fd436,_0x20f993){return function(_0x2ca104){if(!_0x2ca104){_0x4fd436[_0x2ed1('0x14')](0x194);}return _0x2ca104;};}function handleError(_0x12a965,_0x57c8ed){_0x57c8ed=_0x57c8ed||0x1f4;return function(_0x17f4c8){logger['error'](_0x17f4c8[_0x2ed1('0x23')]);if(_0x17f4c8[_0x2ed1('0x24')]){delete _0x17f4c8[_0x2ed1('0x24')];}_0x12a965[_0x2ed1('0x15')](_0x57c8ed)['send'](_0x17f4c8);};}exports[_0x2ed1('0x25')]=function(_0xb27dbc,_0x55b88d){var _0x273453={},_0x1e95e1={},_0x1f2ad3={'count':0x0,'rows':[]};var _0x1c99ff=_[_0x2ed1('0x26')](db[_0x2ed1('0x27')][_0x2ed1('0x28')],function(_0x4f589b){return{'name':_0x4f589b[_0x2ed1('0x29')],'type':_0x4f589b[_0x2ed1('0x2a')][_0x2ed1('0x2b')]};});_0x1e95e1[_0x2ed1('0x2c')]=_[_0x2ed1('0x26')](_0x1c99ff,_0x2ed1('0x24'));_0x1e95e1[_0x2ed1('0x2d')]=_[_0x2ed1('0x2e')](_0xb27dbc[_0x2ed1('0x2d')]);_0x1e95e1['filters']=_[_0x2ed1('0x2f')](_0x1e95e1[_0x2ed1('0x2c')],_0x1e95e1['query']);_0x273453[_0x2ed1('0x30')]=_[_0x2ed1('0x2f')](_0x1e95e1[_0x2ed1('0x2c')],qs[_0x2ed1('0x31')](_0xb27dbc[_0x2ed1('0x2d')][_0x2ed1('0x31')]));_0x273453['attributes']=_0x273453[_0x2ed1('0x30')]['length']?_0x273453[_0x2ed1('0x30')]:_0x1e95e1[_0x2ed1('0x2c')];if(!_0xb27dbc[_0x2ed1('0x2d')][_0x2ed1('0x32')](_0x2ed1('0x33'))){_0x273453['limit']=qs[_0x2ed1('0x18')](_0xb27dbc[_0x2ed1('0x2d')][_0x2ed1('0x18')]);_0x273453[_0x2ed1('0x17')]=qs[_0x2ed1('0x17')](_0xb27dbc['query'][_0x2ed1('0x17')]);}_0x273453['order']=qs[_0x2ed1('0x34')](_0xb27dbc[_0x2ed1('0x2d')][_0x2ed1('0x34')]);_0x273453['where']=qs[_0x2ed1('0x35')](_['pick'](_0xb27dbc['query'],_0x1e95e1[_0x2ed1('0x35')]),_0x1c99ff);if(_0xb27dbc[_0x2ed1('0x2d')]['filter']){_0x273453[_0x2ed1('0x36')]=_['merge'](_0x273453[_0x2ed1('0x36')],{'$or':_[_0x2ed1('0x26')](_0x1c99ff,function(_0x1300dd){if(_0x1300dd[_0x2ed1('0x2a')]!==_0x2ed1('0x37')){var _0x15ef76={};_0x15ef76[_0x1300dd['name']]={'$like':'%'+_0xb27dbc[_0x2ed1('0x2d')]['filter']+'%'};return _0x15ef76;}})});}_0x273453=_[_0x2ed1('0x38')]({},_0x273453,_0xb27dbc['options']);var _0x5b3a32={'where':_0x273453[_0x2ed1('0x36')]};return db['SugarcrmConfiguration']['count'](_0x5b3a32)[_0x2ed1('0x21')](function(_0x1646d9){_0x1f2ad3[_0x2ed1('0x1a')]=_0x1646d9;if(_0xb27dbc[_0x2ed1('0x2d')][_0x2ed1('0x39')]){_0x273453[_0x2ed1('0x3a')]=[{'all':!![]}];}return db[_0x2ed1('0x27')][_0x2ed1('0x3b')](_0x273453);})[_0x2ed1('0x21')](function(_0x10c97d){_0x1f2ad3[_0x2ed1('0x3c')]=_0x10c97d;return _0x1f2ad3;})[_0x2ed1('0x21')](respondWithFilteredResult(_0x55b88d,_0x273453))[_0x2ed1('0x3d')](handleError(_0x55b88d,null));};exports[_0x2ed1('0x3e')]=function(_0x566318,_0x5700c3){var _0x417fb1={'raw':![],'where':{'id':_0x566318['params']['id']}},_0x17687c={};_0x17687c[_0x2ed1('0x2c')]=_[_0x2ed1('0x2e')](db[_0x2ed1('0x27')][_0x2ed1('0x28')]);_0x17687c['query']=_[_0x2ed1('0x2e')](_0x566318[_0x2ed1('0x2d')]);_0x17687c[_0x2ed1('0x35')]=_[_0x2ed1('0x2f')](_0x17687c[_0x2ed1('0x2c')],_0x17687c[_0x2ed1('0x2d')]);_0x417fb1[_0x2ed1('0x30')]=_['intersection'](_0x17687c[_0x2ed1('0x2c')],qs[_0x2ed1('0x31')](_0x566318[_0x2ed1('0x2d')]['fields']));_0x417fb1[_0x2ed1('0x30')]=_0x417fb1[_0x2ed1('0x30')][_0x2ed1('0x3f')]?_0x417fb1['attributes']:_0x17687c[_0x2ed1('0x2c')];if(_0x566318[_0x2ed1('0x2d')]['includeAll']){_0x417fb1[_0x2ed1('0x3a')]=[{'all':!![]}];}_0x417fb1=_[_0x2ed1('0x38')]({},_0x417fb1,_0x566318[_0x2ed1('0x40')]);return db[_0x2ed1('0x27')][_0x2ed1('0x41')](_0x417fb1)[_0x2ed1('0x21')](handleEntityNotFound(_0x5700c3,null))[_0x2ed1('0x21')](respondWithResult(_0x5700c3,null))[_0x2ed1('0x3d')](handleError(_0x5700c3,null));};exports['create']=function(_0x11b2a9,_0x15f548){return db['SugarcrmConfiguration'][_0x2ed1('0x42')](_0x11b2a9['body'],{})[_0x2ed1('0x21')](respondWithResult(_0x15f548,0xc9))[_0x2ed1('0x3d')](handleError(_0x15f548,null));};exports['update']=function(_0x110d9e,_0x29964e){if(_0x110d9e[_0x2ed1('0x43')]['id']){delete _0x110d9e[_0x2ed1('0x43')]['id'];}return db[_0x2ed1('0x27')]['find']({'where':{'id':_0x110d9e[_0x2ed1('0x44')]['id']}})[_0x2ed1('0x21')](handleEntityNotFound(_0x29964e,null))[_0x2ed1('0x21')](saveUpdates(_0x110d9e['body'],null))[_0x2ed1('0x21')](respondWithResult(_0x29964e,null))[_0x2ed1('0x3d')](handleError(_0x29964e,null));};exports[_0x2ed1('0x20')]=function(_0xc79204,_0x483c66){return db[_0x2ed1('0x27')][_0x2ed1('0x41')]({'where':{'id':_0xc79204['params']['id']}})[_0x2ed1('0x21')](handleEntityNotFound(_0x483c66,null))[_0x2ed1('0x21')](removeEntity(_0x483c66,null))[_0x2ed1('0x3d')](handleError(_0x483c66,null));};exports[_0x2ed1('0x45')]=function(_0x37459c,_0x3ab787,_0xd2cab){var _0x2ccccb={};var _0x3fd3de={};var _0x3cd13f;var _0x1436c4;return db[_0x2ed1('0x27')][_0x2ed1('0x46')]({'where':{'id':_0x37459c[_0x2ed1('0x44')]['id']}})[_0x2ed1('0x21')](handleEntityNotFound(_0x3ab787,null))[_0x2ed1('0x21')](function(_0x8beb21){if(_0x8beb21){_0x3cd13f=_0x8beb21;_0x3fd3de[_0x2ed1('0x2c')]=_[_0x2ed1('0x2e')](db[_0x2ed1('0x47')][_0x2ed1('0x28')]);_0x3fd3de[_0x2ed1('0x2d')]=_['keys'](_0x37459c['query']);_0x3fd3de[_0x2ed1('0x35')]=_[_0x2ed1('0x2f')](_0x3fd3de[_0x2ed1('0x2c')],_0x3fd3de['query']);_0x2ccccb[_0x2ed1('0x30')]=_['intersection'](_0x3fd3de[_0x2ed1('0x2c')],qs['fields'](_0x37459c[_0x2ed1('0x2d')]['fields']));_0x2ccccb['attributes']=_0x2ccccb[_0x2ed1('0x30')][_0x2ed1('0x3f')]?_0x2ccccb['attributes']:_0x3fd3de[_0x2ed1('0x2c')];_0x2ccccb[_0x2ed1('0x48')]=qs['sort'](_0x37459c[_0x2ed1('0x2d')]['sort']);_0x2ccccb[_0x2ed1('0x36')]=qs[_0x2ed1('0x35')](_[_0x2ed1('0x49')](_0x37459c[_0x2ed1('0x2d')],_0x3fd3de[_0x2ed1('0x35')]));if(_0x37459c[_0x2ed1('0x2d')][_0x2ed1('0x4a')]){_0x2ccccb[_0x2ed1('0x36')]=_[_0x2ed1('0x38')](_0x2ccccb[_0x2ed1('0x36')],{'$or':_[_0x2ed1('0x26')](_0x2ccccb['attributes'],function(_0x170dde){var _0x1ce221={};_0x1ce221[_0x170dde]={'$like':'%'+_0x37459c[_0x2ed1('0x2d')][_0x2ed1('0x4a')]+'%'};return _0x1ce221;})});}_0x2ccccb=_['merge']({},_0x2ccccb,_0x37459c[_0x2ed1('0x40')]);return _0x3cd13f[_0x2ed1('0x45')](_0x2ccccb);}})['then'](function(_0x28cc98){if(_0x28cc98){_0x1436c4=_0x28cc98[_0x2ed1('0x3f')];if(!_0x37459c[_0x2ed1('0x2d')][_0x2ed1('0x32')]('nolimit')){_0x2ccccb[_0x2ed1('0x18')]=qs['limit'](_0x37459c[_0x2ed1('0x2d')]['limit']);_0x2ccccb[_0x2ed1('0x17')]=qs['offset'](_0x37459c['query'][_0x2ed1('0x17')]);}return _0x3cd13f[_0x2ed1('0x45')](_0x2ccccb);}})['then'](function(_0x296e8a){if(_0x296e8a){return _0x296e8a?{'count':_0x1436c4,'rows':_0x296e8a}:null;}})[_0x2ed1('0x21')](respondWithResult(_0x3ab787,null))[_0x2ed1('0x3d')](handleError(_0x3ab787,null));};exports[_0x2ed1('0x4b')]=function(_0x14bc26,_0x5bd9c0,_0xf9359b){var _0xfc3cc1={};var _0x76fc8f={};var _0x38c103;var _0x5710dc;return db[_0x2ed1('0x27')]['findOne']({'where':{'id':_0x14bc26[_0x2ed1('0x44')]['id']}})[_0x2ed1('0x21')](handleEntityNotFound(_0x5bd9c0,null))['then'](function(_0x4a4418){if(_0x4a4418){_0x38c103=_0x4a4418;_0x76fc8f[_0x2ed1('0x2c')]=_['keys'](db[_0x2ed1('0x47')][_0x2ed1('0x28')]);_0x76fc8f[_0x2ed1('0x2d')]=_[_0x2ed1('0x2e')](_0x14bc26[_0x2ed1('0x2d')]);_0x76fc8f[_0x2ed1('0x35')]=_[_0x2ed1('0x2f')](_0x76fc8f[_0x2ed1('0x2c')],_0x76fc8f[_0x2ed1('0x2d')]);_0xfc3cc1['attributes']=_['intersection'](_0x76fc8f['model'],qs[_0x2ed1('0x31')](_0x14bc26[_0x2ed1('0x2d')][_0x2ed1('0x31')]));_0xfc3cc1['attributes']=_0xfc3cc1[_0x2ed1('0x30')][_0x2ed1('0x3f')]?_0xfc3cc1[_0x2ed1('0x30')]:_0x76fc8f[_0x2ed1('0x2c')];_0xfc3cc1['order']=qs[_0x2ed1('0x34')](_0x14bc26['query'][_0x2ed1('0x34')]);_0xfc3cc1[_0x2ed1('0x36')]=qs[_0x2ed1('0x35')](_[_0x2ed1('0x49')](_0x14bc26['query'],_0x76fc8f['filters']));if(_0x14bc26[_0x2ed1('0x2d')][_0x2ed1('0x4a')]){_0xfc3cc1[_0x2ed1('0x36')]=_[_0x2ed1('0x38')](_0xfc3cc1[_0x2ed1('0x36')],{'$or':_[_0x2ed1('0x26')](_0xfc3cc1[_0x2ed1('0x30')],function(_0x486355){var _0x12783d={};_0x12783d[_0x486355]={'$like':'%'+_0x14bc26[_0x2ed1('0x2d')][_0x2ed1('0x4a')]+'%'};return _0x12783d;})});}_0xfc3cc1=_[_0x2ed1('0x38')]({},_0xfc3cc1,_0x14bc26['options']);return _0x38c103[_0x2ed1('0x4b')](_0xfc3cc1);}})[_0x2ed1('0x21')](function(_0xd48461){if(_0xd48461){_0x5710dc=_0xd48461['length'];if(!_0x14bc26[_0x2ed1('0x2d')]['hasOwnProperty'](_0x2ed1('0x33'))){_0xfc3cc1[_0x2ed1('0x18')]=qs[_0x2ed1('0x18')](_0x14bc26[_0x2ed1('0x2d')][_0x2ed1('0x18')]);_0xfc3cc1[_0x2ed1('0x17')]=qs[_0x2ed1('0x17')](_0x14bc26[_0x2ed1('0x2d')][_0x2ed1('0x17')]);}return _0x38c103[_0x2ed1('0x4b')](_0xfc3cc1);}})[_0x2ed1('0x21')](function(_0x45b8c3){if(_0x45b8c3){return _0x45b8c3?{'count':_0x5710dc,'rows':_0x45b8c3}:null;}})[_0x2ed1('0x21')](respondWithResult(_0x5bd9c0,null))[_0x2ed1('0x3d')](handleError(_0x5bd9c0,null));};exports['getDescriptions']=function(_0x36b867,_0x56d79a,_0x378f77){var _0xf52b09={};var _0x285f26={};var _0x2e6e53;var _0x3798fd;return db[_0x2ed1('0x27')][_0x2ed1('0x46')]({'where':{'id':_0x36b867[_0x2ed1('0x44')]['id']}})['then'](handleEntityNotFound(_0x56d79a,null))[_0x2ed1('0x21')](function(_0x35a8d3){if(_0x35a8d3){_0x2e6e53=_0x35a8d3;_0x285f26[_0x2ed1('0x2c')]=_['keys'](db[_0x2ed1('0x47')][_0x2ed1('0x28')]);_0x285f26[_0x2ed1('0x2d')]=_[_0x2ed1('0x2e')](_0x36b867[_0x2ed1('0x2d')]);_0x285f26[_0x2ed1('0x35')]=_[_0x2ed1('0x2f')](_0x285f26[_0x2ed1('0x2c')],_0x285f26[_0x2ed1('0x2d')]);_0xf52b09['attributes']=_['intersection'](_0x285f26[_0x2ed1('0x2c')],qs[_0x2ed1('0x31')](_0x36b867[_0x2ed1('0x2d')][_0x2ed1('0x31')]));_0xf52b09['attributes']=_0xf52b09['attributes']['length']?_0xf52b09[_0x2ed1('0x30')]:_0x285f26[_0x2ed1('0x2c')];_0xf52b09[_0x2ed1('0x48')]=qs[_0x2ed1('0x34')](_0x36b867['query'][_0x2ed1('0x34')]);_0xf52b09[_0x2ed1('0x36')]=qs[_0x2ed1('0x35')](_[_0x2ed1('0x49')](_0x36b867[_0x2ed1('0x2d')],_0x285f26[_0x2ed1('0x35')]));if(_0x36b867[_0x2ed1('0x2d')][_0x2ed1('0x4a')]){_0xf52b09[_0x2ed1('0x36')]=_[_0x2ed1('0x38')](_0xf52b09[_0x2ed1('0x36')],{'$or':_['map'](_0xf52b09[_0x2ed1('0x30')],function(_0x3e7da1){var _0x24005b={};_0x24005b[_0x3e7da1]={'$like':'%'+_0x36b867[_0x2ed1('0x2d')][_0x2ed1('0x4a')]+'%'};return _0x24005b;})});}_0xf52b09=_[_0x2ed1('0x38')]({},_0xf52b09,_0x36b867['options']);return _0x2e6e53[_0x2ed1('0x4c')](_0xf52b09);}})[_0x2ed1('0x21')](function(_0x1347d6){if(_0x1347d6){_0x3798fd=_0x1347d6[_0x2ed1('0x3f')];if(!_0x36b867[_0x2ed1('0x2d')][_0x2ed1('0x32')](_0x2ed1('0x33'))){_0xf52b09['limit']=qs[_0x2ed1('0x18')](_0x36b867[_0x2ed1('0x2d')][_0x2ed1('0x18')]);_0xf52b09[_0x2ed1('0x17')]=qs[_0x2ed1('0x17')](_0x36b867[_0x2ed1('0x2d')]['offset']);}return _0x2e6e53[_0x2ed1('0x4c')](_0xf52b09);}})['then'](function(_0x5d93d7){if(_0x5d93d7){return _0x5d93d7?{'count':_0x3798fd,'rows':_0x5d93d7}:null;}})['then'](respondWithResult(_0x56d79a,null))[_0x2ed1('0x3d')](handleError(_0x56d79a,null));};