Built motion from commit 497d3d92.|2.5.43
[motion2.git] / server / api / intSalesforceConfiguration / intSalesforceConfiguration.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 _0xe6c5=['nolimit','getSubjects','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send','map','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','pick','filter','where','type','VIRTUAL','merge','options','SalesforceConfiguration','include','findAll','rows','show','params','length','includeAll','find','catch','create','body','findOne','SalesforceField','getFields'];(function(_0x7b7f5f,_0x2d472b){var _0x35e97f=function(_0x1b7300){while(--_0x1b7300){_0x7b7f5f['push'](_0x7b7f5f['shift']());}};_0x35e97f(++_0x2d472b);}(_0xe6c5,0x1e8));var _0x5e6c=function(_0x7a5346,_0x2941a4){_0x7a5346=_0x7a5346-0x0;var _0xf85506=_0xe6c5[_0x7a5346];return _0xf85506;};'use strict';var emlformat=require(_0x5e6c('0x0'));var rimraf=require(_0x5e6c('0x1'));var zipdir=require(_0x5e6c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5e6c('0x3'));var moment=require(_0x5e6c('0x4'));var BPromise=require(_0x5e6c('0x5'));var Mustache=require(_0x5e6c('0x6'));var util=require(_0x5e6c('0x7'));var path=require(_0x5e6c('0x8'));var sox=require('sox');var csv=require(_0x5e6c('0x9'));var ejs=require(_0x5e6c('0xa'));var fs=require('fs');var fs_extra=require(_0x5e6c('0xb'));var _=require('lodash');var squel=require(_0x5e6c('0xc'));var crypto=require(_0x5e6c('0xd'));var jsforce=require(_0x5e6c('0xe'));var deskjs=require(_0x5e6c('0xf'));var toCsv=require(_0x5e6c('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x5e6c('0x10'));var authService=require(_0x5e6c('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5e6c('0x12'));var hardwareService=require(_0x5e6c('0x13'));var logger=require(_0x5e6c('0x14'))(_0x5e6c('0x15'));var utils=require('../../config/utils');var config=require(_0x5e6c('0x16'));var licenseUtil=require(_0x5e6c('0x17'));var db=require(_0x5e6c('0x18'))['db'];function respondWithStatusCode(_0x4c2463,_0x4ffbf9){_0x4ffbf9=_0x4ffbf9||0xcc;return function(_0x3fd8ac){if(_0x3fd8ac){return _0x4c2463[_0x5e6c('0x19')](_0x4ffbf9);}return _0x4c2463[_0x5e6c('0x1a')](_0x4ffbf9)['end']();};}function respondWithResult(_0x4a2b16,_0x537a60){_0x537a60=_0x537a60||0xc8;return function(_0x4487aa){if(_0x4487aa){return _0x4a2b16['status'](_0x537a60)[_0x5e6c('0x1b')](_0x4487aa);}};}function respondWithFilteredResult(_0x3e479f,_0x2e9a87){return function(_0x39b8f7){if(_0x39b8f7){var _0x5c54d9=typeof _0x2e9a87['offset']==='undefined'&&typeof _0x2e9a87[_0x5e6c('0x1c')]==='undefined';var _0x2a8344=_0x39b8f7[_0x5e6c('0x1d')];var _0x478307=_0x5c54d9?0x0:_0x2e9a87['offset'];var _0x22a2f0=_0x5c54d9?_0x39b8f7[_0x5e6c('0x1d')]:_0x2e9a87[_0x5e6c('0x1e')]+_0x2e9a87['limit'];var _0x57c226;if(_0x22a2f0>=_0x2a8344){_0x22a2f0=_0x2a8344;_0x57c226=0xc8;}else{_0x57c226=0xce;}_0x3e479f[_0x5e6c('0x1a')](_0x57c226);return _0x3e479f[_0x5e6c('0x1f')](_0x5e6c('0x20'),_0x478307+'-'+_0x22a2f0+'/'+_0x2a8344)[_0x5e6c('0x1b')](_0x39b8f7);}return null;};}function patchUpdates(_0x4f0af6){return function(_0x3f0ef2){try{jsonpatch[_0x5e6c('0x21')](_0x3f0ef2,_0x4f0af6,!![]);}catch(_0x37a029){return BPromise[_0x5e6c('0x22')](_0x37a029);}return _0x3f0ef2[_0x5e6c('0x23')]();};}function saveUpdates(_0x519897,_0x348f75){return function(_0x508867){if(_0x508867){return _0x508867[_0x5e6c('0x24')](_0x519897)[_0x5e6c('0x25')](function(_0x547202){return _0x547202;});}return null;};}function removeEntity(_0x2b5110,_0x4835a3){return function(_0x1b563e){if(_0x1b563e){return _0x1b563e[_0x5e6c('0x26')]()[_0x5e6c('0x25')](function(){_0x2b5110[_0x5e6c('0x1a')](0xcc)[_0x5e6c('0x27')]();});}};}function handleEntityNotFound(_0x4b9e5b,_0x49e5a6){return function(_0x544527){if(!_0x544527){_0x4b9e5b['sendStatus'](0x194);}return _0x544527;};}function handleError(_0x591d75,_0x33d093){_0x33d093=_0x33d093||0x1f4;return function(_0x11c649){logger[_0x5e6c('0x28')](_0x11c649[_0x5e6c('0x29')]);if(_0x11c649['name']){delete _0x11c649[_0x5e6c('0x2a')];}_0x591d75[_0x5e6c('0x1a')](_0x33d093)[_0x5e6c('0x2b')](_0x11c649);};}exports['index']=function(_0x5a3112,_0x8b5df){var _0x2214e1={},_0x350a93={},_0x1ef6da={'count':0x0,'rows':[]};var _0x8ffe79=_[_0x5e6c('0x2c')](db['SalesforceConfiguration'][_0x5e6c('0x2d')],function(_0x4a8318){return{'name':_0x4a8318[_0x5e6c('0x2e')],'type':_0x4a8318['type']['key']};});_0x350a93[_0x5e6c('0x2f')]=_[_0x5e6c('0x2c')](_0x8ffe79,_0x5e6c('0x2a'));_0x350a93[_0x5e6c('0x30')]=_[_0x5e6c('0x31')](_0x5a3112[_0x5e6c('0x30')]);_0x350a93[_0x5e6c('0x32')]=_[_0x5e6c('0x33')](_0x350a93['model'],_0x350a93['query']);_0x2214e1[_0x5e6c('0x34')]=_[_0x5e6c('0x33')](_0x350a93['model'],qs[_0x5e6c('0x35')](_0x5a3112['query'][_0x5e6c('0x35')]));_0x2214e1[_0x5e6c('0x34')]=_0x2214e1[_0x5e6c('0x34')]['length']?_0x2214e1['attributes']:_0x350a93[_0x5e6c('0x2f')];if(!_0x5a3112['query'][_0x5e6c('0x36')]('nolimit')){_0x2214e1[_0x5e6c('0x1c')]=qs['limit'](_0x5a3112[_0x5e6c('0x30')][_0x5e6c('0x1c')]);_0x2214e1['offset']=qs[_0x5e6c('0x1e')](_0x5a3112[_0x5e6c('0x30')][_0x5e6c('0x1e')]);}_0x2214e1[_0x5e6c('0x37')]=qs[_0x5e6c('0x38')](_0x5a3112[_0x5e6c('0x30')]['sort']);_0x2214e1['where']=qs[_0x5e6c('0x32')](_[_0x5e6c('0x39')](_0x5a3112[_0x5e6c('0x30')],_0x350a93[_0x5e6c('0x32')]),_0x8ffe79);if(_0x5a3112[_0x5e6c('0x30')][_0x5e6c('0x3a')]){_0x2214e1[_0x5e6c('0x3b')]=_['merge'](_0x2214e1[_0x5e6c('0x3b')],{'$or':_[_0x5e6c('0x2c')](_0x8ffe79,function(_0x40fe6e){if(_0x40fe6e[_0x5e6c('0x3c')]!==_0x5e6c('0x3d')){var _0x119e38={};_0x119e38[_0x40fe6e[_0x5e6c('0x2a')]]={'$like':'%'+_0x5a3112['query'][_0x5e6c('0x3a')]+'%'};return _0x119e38;}})});}_0x2214e1=_[_0x5e6c('0x3e')]({},_0x2214e1,_0x5a3112[_0x5e6c('0x3f')]);var _0x3f1cfc={'where':_0x2214e1[_0x5e6c('0x3b')]};return db[_0x5e6c('0x40')][_0x5e6c('0x1d')](_0x3f1cfc)[_0x5e6c('0x25')](function(_0x242fe9){_0x1ef6da[_0x5e6c('0x1d')]=_0x242fe9;if(_0x5a3112['query']['includeAll']){_0x2214e1[_0x5e6c('0x41')]=[{'all':!![]}];}return db[_0x5e6c('0x40')][_0x5e6c('0x42')](_0x2214e1);})[_0x5e6c('0x25')](function(_0x5c7230){_0x1ef6da[_0x5e6c('0x43')]=_0x5c7230;return _0x1ef6da;})[_0x5e6c('0x25')](respondWithFilteredResult(_0x8b5df,_0x2214e1))['catch'](handleError(_0x8b5df,null));};exports[_0x5e6c('0x44')]=function(_0x3d2bd0,_0x2328cb){var _0x6711a7={'raw':![],'where':{'id':_0x3d2bd0[_0x5e6c('0x45')]['id']}},_0x323f5d={};_0x323f5d[_0x5e6c('0x2f')]=_[_0x5e6c('0x31')](db[_0x5e6c('0x40')][_0x5e6c('0x2d')]);_0x323f5d[_0x5e6c('0x30')]=_[_0x5e6c('0x31')](_0x3d2bd0[_0x5e6c('0x30')]);_0x323f5d[_0x5e6c('0x32')]=_[_0x5e6c('0x33')](_0x323f5d[_0x5e6c('0x2f')],_0x323f5d[_0x5e6c('0x30')]);_0x6711a7[_0x5e6c('0x34')]=_['intersection'](_0x323f5d[_0x5e6c('0x2f')],qs[_0x5e6c('0x35')](_0x3d2bd0['query'][_0x5e6c('0x35')]));_0x6711a7['attributes']=_0x6711a7[_0x5e6c('0x34')][_0x5e6c('0x46')]?_0x6711a7[_0x5e6c('0x34')]:_0x323f5d[_0x5e6c('0x2f')];if(_0x3d2bd0['query'][_0x5e6c('0x47')]){_0x6711a7[_0x5e6c('0x41')]=[{'all':!![]}];}_0x6711a7=_[_0x5e6c('0x3e')]({},_0x6711a7,_0x3d2bd0[_0x5e6c('0x3f')]);return db[_0x5e6c('0x40')][_0x5e6c('0x48')](_0x6711a7)[_0x5e6c('0x25')](handleEntityNotFound(_0x2328cb,null))[_0x5e6c('0x25')](respondWithResult(_0x2328cb,null))[_0x5e6c('0x49')](handleError(_0x2328cb,null));};exports[_0x5e6c('0x4a')]=function(_0x287b20,_0x2ac772){return db['SalesforceConfiguration'][_0x5e6c('0x4a')](_0x287b20[_0x5e6c('0x4b')],{})[_0x5e6c('0x25')](respondWithResult(_0x2ac772,0xc9))[_0x5e6c('0x49')](handleError(_0x2ac772,null));};exports[_0x5e6c('0x24')]=function(_0x473b44,_0x569e8b){if(_0x473b44[_0x5e6c('0x4b')]['id']){delete _0x473b44[_0x5e6c('0x4b')]['id'];}return db[_0x5e6c('0x40')]['find']({'where':{'id':_0x473b44[_0x5e6c('0x45')]['id']}})['then'](handleEntityNotFound(_0x569e8b,null))[_0x5e6c('0x25')](saveUpdates(_0x473b44[_0x5e6c('0x4b')],null))['then'](respondWithResult(_0x569e8b,null))[_0x5e6c('0x49')](handleError(_0x569e8b,null));};exports[_0x5e6c('0x26')]=function(_0x1f2670,_0x14c142){return db[_0x5e6c('0x40')]['find']({'where':{'id':_0x1f2670['params']['id']}})['then'](handleEntityNotFound(_0x14c142,null))['then'](removeEntity(_0x14c142,null))[_0x5e6c('0x49')](handleError(_0x14c142,null));};exports['getFields']=function(_0x4be3cf,_0x159624,_0x595b24){var _0x1195f0={};var _0x4fe897={};var _0x1dbc11;var _0x565216;return db[_0x5e6c('0x40')][_0x5e6c('0x4c')]({'where':{'id':_0x4be3cf[_0x5e6c('0x45')]['id']}})[_0x5e6c('0x25')](handleEntityNotFound(_0x159624,null))[_0x5e6c('0x25')](function(_0xdabbf9){if(_0xdabbf9){_0x1dbc11=_0xdabbf9;_0x4fe897['model']=_[_0x5e6c('0x31')](db[_0x5e6c('0x4d')][_0x5e6c('0x2d')]);_0x4fe897[_0x5e6c('0x30')]=_[_0x5e6c('0x31')](_0x4be3cf[_0x5e6c('0x30')]);_0x4fe897[_0x5e6c('0x32')]=_[_0x5e6c('0x33')](_0x4fe897[_0x5e6c('0x2f')],_0x4fe897[_0x5e6c('0x30')]);_0x1195f0[_0x5e6c('0x34')]=_[_0x5e6c('0x33')](_0x4fe897[_0x5e6c('0x2f')],qs[_0x5e6c('0x35')](_0x4be3cf[_0x5e6c('0x30')][_0x5e6c('0x35')]));_0x1195f0['attributes']=_0x1195f0[_0x5e6c('0x34')][_0x5e6c('0x46')]?_0x1195f0[_0x5e6c('0x34')]:_0x4fe897[_0x5e6c('0x2f')];_0x1195f0[_0x5e6c('0x37')]=qs[_0x5e6c('0x38')](_0x4be3cf['query'][_0x5e6c('0x38')]);_0x1195f0[_0x5e6c('0x3b')]=qs[_0x5e6c('0x32')](_[_0x5e6c('0x39')](_0x4be3cf[_0x5e6c('0x30')],_0x4fe897[_0x5e6c('0x32')]));if(_0x4be3cf[_0x5e6c('0x30')][_0x5e6c('0x3a')]){_0x1195f0[_0x5e6c('0x3b')]=_[_0x5e6c('0x3e')](_0x1195f0[_0x5e6c('0x3b')],{'$or':_[_0x5e6c('0x2c')](_0x1195f0[_0x5e6c('0x34')],function(_0x111b08){var _0x6d686f={};_0x6d686f[_0x111b08]={'$like':'%'+_0x4be3cf['query'][_0x5e6c('0x3a')]+'%'};return _0x6d686f;})});}_0x1195f0=_['merge']({},_0x1195f0,_0x4be3cf[_0x5e6c('0x3f')]);return _0x1dbc11[_0x5e6c('0x4e')](_0x1195f0);}})[_0x5e6c('0x25')](function(_0x230cbc){if(_0x230cbc){_0x565216=_0x230cbc['length'];if(!_0x4be3cf[_0x5e6c('0x30')][_0x5e6c('0x36')](_0x5e6c('0x4f'))){_0x1195f0[_0x5e6c('0x1c')]=qs[_0x5e6c('0x1c')](_0x4be3cf[_0x5e6c('0x30')][_0x5e6c('0x1c')]);_0x1195f0['offset']=qs[_0x5e6c('0x1e')](_0x4be3cf['query']['offset']);}return _0x1dbc11[_0x5e6c('0x4e')](_0x1195f0);}})[_0x5e6c('0x25')](function(_0x2802c1){if(_0x2802c1){return _0x2802c1?{'count':_0x565216,'rows':_0x2802c1}:null;}})[_0x5e6c('0x25')](respondWithResult(_0x159624,null))['catch'](handleError(_0x159624,null));};exports[_0x5e6c('0x50')]=function(_0x506021,_0x51414b,_0x95e596){var _0x12ad42={};var _0x3fa18b={};var _0x5b594e;var _0x380b58;return db[_0x5e6c('0x40')][_0x5e6c('0x4c')]({'where':{'id':_0x506021['params']['id']}})['then'](handleEntityNotFound(_0x51414b,null))[_0x5e6c('0x25')](function(_0x1f561e){if(_0x1f561e){_0x5b594e=_0x1f561e;_0x3fa18b[_0x5e6c('0x2f')]=_['keys'](db[_0x5e6c('0x4d')][_0x5e6c('0x2d')]);_0x3fa18b['query']=_['keys'](_0x506021[_0x5e6c('0x30')]);_0x3fa18b[_0x5e6c('0x32')]=_[_0x5e6c('0x33')](_0x3fa18b[_0x5e6c('0x2f')],_0x3fa18b[_0x5e6c('0x30')]);_0x12ad42[_0x5e6c('0x34')]=_[_0x5e6c('0x33')](_0x3fa18b[_0x5e6c('0x2f')],qs[_0x5e6c('0x35')](_0x506021[_0x5e6c('0x30')][_0x5e6c('0x35')]));_0x12ad42[_0x5e6c('0x34')]=_0x12ad42[_0x5e6c('0x34')][_0x5e6c('0x46')]?_0x12ad42[_0x5e6c('0x34')]:_0x3fa18b['model'];_0x12ad42['order']=qs[_0x5e6c('0x38')](_0x506021[_0x5e6c('0x30')]['sort']);_0x12ad42['where']=qs[_0x5e6c('0x32')](_[_0x5e6c('0x39')](_0x506021[_0x5e6c('0x30')],_0x3fa18b[_0x5e6c('0x32')]));if(_0x506021[_0x5e6c('0x30')][_0x5e6c('0x3a')]){_0x12ad42[_0x5e6c('0x3b')]=_[_0x5e6c('0x3e')](_0x12ad42[_0x5e6c('0x3b')],{'$or':_['map'](_0x12ad42[_0x5e6c('0x34')],function(_0x128240){var _0xcad0c5={};_0xcad0c5[_0x128240]={'$like':'%'+_0x506021[_0x5e6c('0x30')][_0x5e6c('0x3a')]+'%'};return _0xcad0c5;})});}_0x12ad42=_[_0x5e6c('0x3e')]({},_0x12ad42,_0x506021[_0x5e6c('0x3f')]);return _0x5b594e[_0x5e6c('0x50')](_0x12ad42);}})[_0x5e6c('0x25')](function(_0x44d949){if(_0x44d949){_0x380b58=_0x44d949[_0x5e6c('0x46')];if(!_0x506021[_0x5e6c('0x30')][_0x5e6c('0x36')](_0x5e6c('0x4f'))){_0x12ad42[_0x5e6c('0x1c')]=qs['limit'](_0x506021[_0x5e6c('0x30')][_0x5e6c('0x1c')]);_0x12ad42[_0x5e6c('0x1e')]=qs['offset'](_0x506021[_0x5e6c('0x30')][_0x5e6c('0x1e')]);}return _0x5b594e[_0x5e6c('0x50')](_0x12ad42);}})[_0x5e6c('0x25')](function(_0x8de0b6){if(_0x8de0b6){return _0x8de0b6?{'count':_0x380b58,'rows':_0x8de0b6}:null;}})[_0x5e6c('0x25')](respondWithResult(_0x51414b,null))[_0x5e6c('0x49')](handleError(_0x51414b,null));};exports['getDescriptions']=function(_0x189f52,_0x91e278,_0x3f16b0){var _0x149eb3={};var _0x43b41a={};var _0x6c3578;var _0xd0c5fe;return db[_0x5e6c('0x40')][_0x5e6c('0x4c')]({'where':{'id':_0x189f52[_0x5e6c('0x45')]['id']}})[_0x5e6c('0x25')](handleEntityNotFound(_0x91e278,null))[_0x5e6c('0x25')](function(_0x384939){if(_0x384939){_0x6c3578=_0x384939;_0x43b41a[_0x5e6c('0x2f')]=_[_0x5e6c('0x31')](db[_0x5e6c('0x4d')]['rawAttributes']);_0x43b41a[_0x5e6c('0x30')]=_[_0x5e6c('0x31')](_0x189f52['query']);_0x43b41a[_0x5e6c('0x32')]=_[_0x5e6c('0x33')](_0x43b41a[_0x5e6c('0x2f')],_0x43b41a[_0x5e6c('0x30')]);_0x149eb3[_0x5e6c('0x34')]=_[_0x5e6c('0x33')](_0x43b41a[_0x5e6c('0x2f')],qs[_0x5e6c('0x35')](_0x189f52[_0x5e6c('0x30')]['fields']));_0x149eb3[_0x5e6c('0x34')]=_0x149eb3['attributes'][_0x5e6c('0x46')]?_0x149eb3[_0x5e6c('0x34')]:_0x43b41a[_0x5e6c('0x2f')];_0x149eb3['order']=qs[_0x5e6c('0x38')](_0x189f52[_0x5e6c('0x30')][_0x5e6c('0x38')]);_0x149eb3[_0x5e6c('0x3b')]=qs[_0x5e6c('0x32')](_[_0x5e6c('0x39')](_0x189f52[_0x5e6c('0x30')],_0x43b41a[_0x5e6c('0x32')]));if(_0x189f52[_0x5e6c('0x30')]['filter']){_0x149eb3[_0x5e6c('0x3b')]=_[_0x5e6c('0x3e')](_0x149eb3[_0x5e6c('0x3b')],{'$or':_[_0x5e6c('0x2c')](_0x149eb3[_0x5e6c('0x34')],function(_0x160802){var _0x17e05c={};_0x17e05c[_0x160802]={'$like':'%'+_0x189f52[_0x5e6c('0x30')]['filter']+'%'};return _0x17e05c;})});}_0x149eb3=_[_0x5e6c('0x3e')]({},_0x149eb3,_0x189f52[_0x5e6c('0x3f')]);return _0x6c3578['getDescriptions'](_0x149eb3);}})[_0x5e6c('0x25')](function(_0x3f7e18){if(_0x3f7e18){_0xd0c5fe=_0x3f7e18[_0x5e6c('0x46')];if(!_0x189f52[_0x5e6c('0x30')]['hasOwnProperty'](_0x5e6c('0x4f'))){_0x149eb3[_0x5e6c('0x1c')]=qs[_0x5e6c('0x1c')](_0x189f52[_0x5e6c('0x30')][_0x5e6c('0x1c')]);_0x149eb3[_0x5e6c('0x1e')]=qs[_0x5e6c('0x1e')](_0x189f52[_0x5e6c('0x30')][_0x5e6c('0x1e')]);}return _0x6c3578['getDescriptions'](_0x149eb3);}})[_0x5e6c('0x25')](function(_0x44679b){if(_0x44679b){return _0x44679b?{'count':_0xd0c5fe,'rows':_0x44679b}:null;}})['then'](respondWithResult(_0x91e278,null))['catch'](handleError(_0x91e278,null));};