Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / intZohoConfiguration / intZohoConfiguration.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 _0x8f15=['fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','save','update','destroy','then','error','stack','name','send','index','map','ZohoConfiguration','rawAttributes','key','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','filters','filter','type','VIRTUAL','merge','options','include','findAll','rows','catch','show','length','find','create','body','getFields','params','ZohoField','order','pick','getSubjects','findOne','getDescriptions','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs'];(function(_0x11f0bf,_0x5360f5){var _0x347400=function(_0x1d0043){while(--_0x1d0043){_0x11f0bf['push'](_0x11f0bf['shift']());}};_0x347400(++_0x5360f5);}(_0x8f15,0x98));var _0x58f1=function(_0x14a804,_0x185102){_0x14a804=_0x14a804-0x0;var _0x3e5fcc=_0x8f15[_0x14a804];return _0x3e5fcc;};'use strict';var emlformat=require(_0x58f1('0x0'));var rimraf=require(_0x58f1('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x58f1('0x2'));var moment=require(_0x58f1('0x3'));var BPromise=require(_0x58f1('0x4'));var Mustache=require(_0x58f1('0x5'));var util=require(_0x58f1('0x6'));var path=require(_0x58f1('0x7'));var sox=require('sox');var csv=require(_0x58f1('0x8'));var ejs=require(_0x58f1('0x9'));var fs=require('fs');var fs_extra=require(_0x58f1('0xa'));var _=require(_0x58f1('0xb'));var squel=require(_0x58f1('0xc'));var crypto=require(_0x58f1('0xd'));var jsforce=require(_0x58f1('0xe'));var deskjs=require(_0x58f1('0xf'));var toCsv=require(_0x58f1('0x8'));var querystring=require(_0x58f1('0x10'));var Papa=require(_0x58f1('0x11'));var Redis=require(_0x58f1('0x12'));var authService=require(_0x58f1('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x58f1('0x14'));var logger=require(_0x58f1('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x58f1('0x16'));var licenseUtil=require(_0x58f1('0x17'));var db=require(_0x58f1('0x18'))['db'];function respondWithStatusCode(_0x41550d,_0x3c7646){_0x3c7646=_0x3c7646||0xcc;return function(_0x3167a2){if(_0x3167a2){return _0x41550d[_0x58f1('0x19')](_0x3c7646);}return _0x41550d[_0x58f1('0x1a')](_0x3c7646)[_0x58f1('0x1b')]();};}function respondWithResult(_0x7862e4,_0x4063f6){_0x4063f6=_0x4063f6||0xc8;return function(_0x40a1c8){if(_0x40a1c8){return _0x7862e4[_0x58f1('0x1a')](_0x4063f6)[_0x58f1('0x1c')](_0x40a1c8);}};}function respondWithFilteredResult(_0x17fdeb,_0x469832){return function(_0x32087){if(_0x32087){var _0x10cefa=typeof _0x469832[_0x58f1('0x1d')]==='undefined'&&typeof _0x469832[_0x58f1('0x1e')]===_0x58f1('0x1f');var _0x17053a=_0x32087[_0x58f1('0x20')];var _0x3ffc23=_0x10cefa?0x0:_0x469832[_0x58f1('0x1d')];var _0x1b852d=_0x10cefa?_0x32087[_0x58f1('0x20')]:_0x469832['offset']+_0x469832[_0x58f1('0x1e')];var _0x17c5e8;if(_0x1b852d>=_0x17053a){_0x1b852d=_0x17053a;_0x17c5e8=0xc8;}else{_0x17c5e8=0xce;}_0x17fdeb[_0x58f1('0x1a')](_0x17c5e8);return _0x17fdeb[_0x58f1('0x21')](_0x58f1('0x22'),_0x3ffc23+'-'+_0x1b852d+'/'+_0x17053a)['json'](_0x32087);}return null;};}function patchUpdates(_0x38194f){return function(_0x5cd5bf){try{jsonpatch['apply'](_0x5cd5bf,_0x38194f,!![]);}catch(_0x46a522){return BPromise['reject'](_0x46a522);}return _0x5cd5bf[_0x58f1('0x23')]();};}function saveUpdates(_0x130891,_0x58c7fd){return function(_0x54b67c){if(_0x54b67c){return _0x54b67c[_0x58f1('0x24')](_0x130891)['then'](function(_0x1142a0){return _0x1142a0;});}return null;};}function removeEntity(_0x361f28,_0x53a6eb){return function(_0x1184e4){if(_0x1184e4){return _0x1184e4[_0x58f1('0x25')]()[_0x58f1('0x26')](function(){_0x361f28[_0x58f1('0x1a')](0xcc)[_0x58f1('0x1b')]();});}};}function handleEntityNotFound(_0x227a26,_0x5e7b81){return function(_0x5f0ceb){if(!_0x5f0ceb){_0x227a26[_0x58f1('0x19')](0x194);}return _0x5f0ceb;};}function handleError(_0x7674db,_0x4b2ca6){_0x4b2ca6=_0x4b2ca6||0x1f4;return function(_0x33da9e){logger[_0x58f1('0x27')](_0x33da9e[_0x58f1('0x28')]);if(_0x33da9e[_0x58f1('0x29')]){delete _0x33da9e[_0x58f1('0x29')];}_0x7674db[_0x58f1('0x1a')](_0x4b2ca6)[_0x58f1('0x2a')](_0x33da9e);};}exports[_0x58f1('0x2b')]=function(_0x1fbdbc,_0x2b66ff){var _0x565b2e={},_0x437bc9={},_0x4d7915={'count':0x0,'rows':[]};var _0x544e7e=_[_0x58f1('0x2c')](db[_0x58f1('0x2d')][_0x58f1('0x2e')],function(_0x18ef6e){return{'name':_0x18ef6e['fieldName'],'type':_0x18ef6e['type'][_0x58f1('0x2f')]};});_0x437bc9[_0x58f1('0x30')]=_[_0x58f1('0x2c')](_0x544e7e,'name');_0x437bc9['query']=_[_0x58f1('0x31')](_0x1fbdbc[_0x58f1('0x32')]);_0x437bc9['filters']=_[_0x58f1('0x33')](_0x437bc9[_0x58f1('0x30')],_0x437bc9['query']);_0x565b2e[_0x58f1('0x34')]=_[_0x58f1('0x33')](_0x437bc9[_0x58f1('0x30')],qs[_0x58f1('0x35')](_0x1fbdbc[_0x58f1('0x32')]['fields']));_0x565b2e['attributes']=_0x565b2e[_0x58f1('0x34')]['length']?_0x565b2e[_0x58f1('0x34')]:_0x437bc9[_0x58f1('0x30')];if(!_0x1fbdbc[_0x58f1('0x32')][_0x58f1('0x36')](_0x58f1('0x37'))){_0x565b2e[_0x58f1('0x1e')]=qs[_0x58f1('0x1e')](_0x1fbdbc[_0x58f1('0x32')][_0x58f1('0x1e')]);_0x565b2e[_0x58f1('0x1d')]=qs['offset'](_0x1fbdbc[_0x58f1('0x32')][_0x58f1('0x1d')]);}_0x565b2e['order']=qs[_0x58f1('0x38')](_0x1fbdbc[_0x58f1('0x32')][_0x58f1('0x38')]);_0x565b2e[_0x58f1('0x39')]=qs[_0x58f1('0x3a')](_['pick'](_0x1fbdbc[_0x58f1('0x32')],_0x437bc9[_0x58f1('0x3a')]),_0x544e7e);if(_0x1fbdbc['query'][_0x58f1('0x3b')]){_0x565b2e[_0x58f1('0x39')]=_['merge'](_0x565b2e[_0x58f1('0x39')],{'$or':_[_0x58f1('0x2c')](_0x544e7e,function(_0x5c4443){if(_0x5c4443[_0x58f1('0x3c')]!==_0x58f1('0x3d')){var _0x1b83bf={};_0x1b83bf[_0x5c4443[_0x58f1('0x29')]]={'$like':'%'+_0x1fbdbc[_0x58f1('0x32')][_0x58f1('0x3b')]+'%'};return _0x1b83bf;}})});}_0x565b2e=_[_0x58f1('0x3e')]({},_0x565b2e,_0x1fbdbc[_0x58f1('0x3f')]);var _0x2e20e6={'where':_0x565b2e[_0x58f1('0x39')]};return db[_0x58f1('0x2d')][_0x58f1('0x20')](_0x2e20e6)[_0x58f1('0x26')](function(_0x5edcbf){_0x4d7915[_0x58f1('0x20')]=_0x5edcbf;if(_0x1fbdbc['query']['includeAll']){_0x565b2e[_0x58f1('0x40')]=[{'all':!![]}];}return db['ZohoConfiguration'][_0x58f1('0x41')](_0x565b2e);})[_0x58f1('0x26')](function(_0x486776){_0x4d7915[_0x58f1('0x42')]=_0x486776;return _0x4d7915;})['then'](respondWithFilteredResult(_0x2b66ff,_0x565b2e))[_0x58f1('0x43')](handleError(_0x2b66ff,null));};exports[_0x58f1('0x44')]=function(_0x232668,_0x26242f){var _0x54d169={'raw':![],'where':{'id':_0x232668['params']['id']}},_0x5dea43={};_0x5dea43[_0x58f1('0x30')]=_['keys'](db['ZohoConfiguration'][_0x58f1('0x2e')]);_0x5dea43[_0x58f1('0x32')]=_[_0x58f1('0x31')](_0x232668['query']);_0x5dea43[_0x58f1('0x3a')]=_[_0x58f1('0x33')](_0x5dea43[_0x58f1('0x30')],_0x5dea43[_0x58f1('0x32')]);_0x54d169[_0x58f1('0x34')]=_[_0x58f1('0x33')](_0x5dea43[_0x58f1('0x30')],qs[_0x58f1('0x35')](_0x232668[_0x58f1('0x32')][_0x58f1('0x35')]));_0x54d169[_0x58f1('0x34')]=_0x54d169['attributes'][_0x58f1('0x45')]?_0x54d169[_0x58f1('0x34')]:_0x5dea43[_0x58f1('0x30')];if(_0x232668[_0x58f1('0x32')]['includeAll']){_0x54d169[_0x58f1('0x40')]=[{'all':!![]}];}_0x54d169=_[_0x58f1('0x3e')]({},_0x54d169,_0x232668['options']);return db[_0x58f1('0x2d')][_0x58f1('0x46')](_0x54d169)[_0x58f1('0x26')](handleEntityNotFound(_0x26242f,null))['then'](respondWithResult(_0x26242f,null))[_0x58f1('0x43')](handleError(_0x26242f,null));};exports[_0x58f1('0x47')]=function(_0x5ad1d1,_0x438e9a){return db[_0x58f1('0x2d')]['create'](_0x5ad1d1[_0x58f1('0x48')],{})['then'](respondWithResult(_0x438e9a,0xc9))[_0x58f1('0x43')](handleError(_0x438e9a,null));};exports[_0x58f1('0x24')]=function(_0x2123a1,_0x1382e0){if(_0x2123a1['body']['id']){delete _0x2123a1['body']['id'];}return db['ZohoConfiguration'][_0x58f1('0x46')]({'where':{'id':_0x2123a1['params']['id']}})['then'](handleEntityNotFound(_0x1382e0,null))[_0x58f1('0x26')](saveUpdates(_0x2123a1[_0x58f1('0x48')],null))[_0x58f1('0x26')](respondWithResult(_0x1382e0,null))['catch'](handleError(_0x1382e0,null));};exports['destroy']=function(_0x40b008,_0x7a5c67){return db[_0x58f1('0x2d')][_0x58f1('0x46')]({'where':{'id':_0x40b008['params']['id']}})['then'](handleEntityNotFound(_0x7a5c67,null))['then'](removeEntity(_0x7a5c67,null))[_0x58f1('0x43')](handleError(_0x7a5c67,null));};exports[_0x58f1('0x49')]=function(_0x3a99e6,_0x146a5a,_0xee58c1){var _0x3e89a5={};var _0xa9bd3c={};var _0x56042b;var _0xd19116;return db[_0x58f1('0x2d')]['findOne']({'where':{'id':_0x3a99e6[_0x58f1('0x4a')]['id']}})[_0x58f1('0x26')](handleEntityNotFound(_0x146a5a,null))[_0x58f1('0x26')](function(_0x518161){if(_0x518161){_0x56042b=_0x518161;_0xa9bd3c[_0x58f1('0x30')]=_[_0x58f1('0x31')](db[_0x58f1('0x4b')][_0x58f1('0x2e')]);_0xa9bd3c[_0x58f1('0x32')]=_['keys'](_0x3a99e6[_0x58f1('0x32')]);_0xa9bd3c[_0x58f1('0x3a')]=_[_0x58f1('0x33')](_0xa9bd3c[_0x58f1('0x30')],_0xa9bd3c[_0x58f1('0x32')]);_0x3e89a5[_0x58f1('0x34')]=_[_0x58f1('0x33')](_0xa9bd3c[_0x58f1('0x30')],qs[_0x58f1('0x35')](_0x3a99e6[_0x58f1('0x32')][_0x58f1('0x35')]));_0x3e89a5[_0x58f1('0x34')]=_0x3e89a5[_0x58f1('0x34')][_0x58f1('0x45')]?_0x3e89a5[_0x58f1('0x34')]:_0xa9bd3c[_0x58f1('0x30')];_0x3e89a5[_0x58f1('0x4c')]=qs[_0x58f1('0x38')](_0x3a99e6['query']['sort']);_0x3e89a5[_0x58f1('0x39')]=qs[_0x58f1('0x3a')](_[_0x58f1('0x4d')](_0x3a99e6[_0x58f1('0x32')],_0xa9bd3c[_0x58f1('0x3a')]));if(_0x3a99e6[_0x58f1('0x32')][_0x58f1('0x3b')]){_0x3e89a5[_0x58f1('0x39')]=_[_0x58f1('0x3e')](_0x3e89a5['where'],{'$or':_[_0x58f1('0x2c')](_0x3e89a5['attributes'],function(_0x53a5bc){var _0xb36a63={};_0xb36a63[_0x53a5bc]={'$like':'%'+_0x3a99e6[_0x58f1('0x32')]['filter']+'%'};return _0xb36a63;})});}_0x3e89a5=_[_0x58f1('0x3e')]({},_0x3e89a5,_0x3a99e6[_0x58f1('0x3f')]);return _0x56042b[_0x58f1('0x49')](_0x3e89a5);}})[_0x58f1('0x26')](function(_0xaf8695){if(_0xaf8695){_0xd19116=_0xaf8695[_0x58f1('0x45')];if(!_0x3a99e6[_0x58f1('0x32')][_0x58f1('0x36')](_0x58f1('0x37'))){_0x3e89a5[_0x58f1('0x1e')]=qs['limit'](_0x3a99e6[_0x58f1('0x32')]['limit']);_0x3e89a5[_0x58f1('0x1d')]=qs[_0x58f1('0x1d')](_0x3a99e6['query'][_0x58f1('0x1d')]);}return _0x56042b['getFields'](_0x3e89a5);}})[_0x58f1('0x26')](function(_0x18a1ec){if(_0x18a1ec){return _0x18a1ec?{'count':_0xd19116,'rows':_0x18a1ec}:null;}})['then'](respondWithResult(_0x146a5a,null))[_0x58f1('0x43')](handleError(_0x146a5a,null));};exports[_0x58f1('0x4e')]=function(_0x2a9f36,_0x138a1,_0x1c8b68){var _0x27c9f2={};var _0x53939a={};var _0x4959ce;var _0x4ff686;return db['ZohoConfiguration'][_0x58f1('0x4f')]({'where':{'id':_0x2a9f36[_0x58f1('0x4a')]['id']}})[_0x58f1('0x26')](handleEntityNotFound(_0x138a1,null))['then'](function(_0xaee060){if(_0xaee060){_0x4959ce=_0xaee060;_0x53939a[_0x58f1('0x30')]=_[_0x58f1('0x31')](db[_0x58f1('0x4b')]['rawAttributes']);_0x53939a[_0x58f1('0x32')]=_[_0x58f1('0x31')](_0x2a9f36[_0x58f1('0x32')]);_0x53939a[_0x58f1('0x3a')]=_[_0x58f1('0x33')](_0x53939a['model'],_0x53939a['query']);_0x27c9f2['attributes']=_[_0x58f1('0x33')](_0x53939a[_0x58f1('0x30')],qs[_0x58f1('0x35')](_0x2a9f36[_0x58f1('0x32')]['fields']));_0x27c9f2[_0x58f1('0x34')]=_0x27c9f2[_0x58f1('0x34')][_0x58f1('0x45')]?_0x27c9f2[_0x58f1('0x34')]:_0x53939a['model'];_0x27c9f2[_0x58f1('0x4c')]=qs[_0x58f1('0x38')](_0x2a9f36['query'][_0x58f1('0x38')]);_0x27c9f2[_0x58f1('0x39')]=qs[_0x58f1('0x3a')](_[_0x58f1('0x4d')](_0x2a9f36['query'],_0x53939a[_0x58f1('0x3a')]));if(_0x2a9f36['query']['filter']){_0x27c9f2[_0x58f1('0x39')]=_[_0x58f1('0x3e')](_0x27c9f2['where'],{'$or':_[_0x58f1('0x2c')](_0x27c9f2[_0x58f1('0x34')],function(_0x4215f4){var _0x302b3a={};_0x302b3a[_0x4215f4]={'$like':'%'+_0x2a9f36[_0x58f1('0x32')][_0x58f1('0x3b')]+'%'};return _0x302b3a;})});}_0x27c9f2=_[_0x58f1('0x3e')]({},_0x27c9f2,_0x2a9f36[_0x58f1('0x3f')]);return _0x4959ce['getSubjects'](_0x27c9f2);}})[_0x58f1('0x26')](function(_0x2afccf){if(_0x2afccf){_0x4ff686=_0x2afccf[_0x58f1('0x45')];if(!_0x2a9f36[_0x58f1('0x32')][_0x58f1('0x36')](_0x58f1('0x37'))){_0x27c9f2[_0x58f1('0x1e')]=qs[_0x58f1('0x1e')](_0x2a9f36[_0x58f1('0x32')][_0x58f1('0x1e')]);_0x27c9f2[_0x58f1('0x1d')]=qs[_0x58f1('0x1d')](_0x2a9f36[_0x58f1('0x32')][_0x58f1('0x1d')]);}return _0x4959ce['getSubjects'](_0x27c9f2);}})[_0x58f1('0x26')](function(_0x26548c){if(_0x26548c){return _0x26548c?{'count':_0x4ff686,'rows':_0x26548c}:null;}})['then'](respondWithResult(_0x138a1,null))[_0x58f1('0x43')](handleError(_0x138a1,null));};exports[_0x58f1('0x50')]=function(_0x2fc17b,_0x2f1c07,_0x30c162){var _0xfb6298={};var _0x3422cf={};var _0x5a64f8;var _0x3ec6ef;return db[_0x58f1('0x2d')]['findOne']({'where':{'id':_0x2fc17b['params']['id']}})[_0x58f1('0x26')](handleEntityNotFound(_0x2f1c07,null))[_0x58f1('0x26')](function(_0x1bb778){if(_0x1bb778){_0x5a64f8=_0x1bb778;_0x3422cf[_0x58f1('0x30')]=_['keys'](db[_0x58f1('0x4b')][_0x58f1('0x2e')]);_0x3422cf[_0x58f1('0x32')]=_[_0x58f1('0x31')](_0x2fc17b[_0x58f1('0x32')]);_0x3422cf['filters']=_['intersection'](_0x3422cf[_0x58f1('0x30')],_0x3422cf['query']);_0xfb6298['attributes']=_[_0x58f1('0x33')](_0x3422cf['model'],qs[_0x58f1('0x35')](_0x2fc17b[_0x58f1('0x32')][_0x58f1('0x35')]));_0xfb6298[_0x58f1('0x34')]=_0xfb6298[_0x58f1('0x34')][_0x58f1('0x45')]?_0xfb6298[_0x58f1('0x34')]:_0x3422cf[_0x58f1('0x30')];_0xfb6298['order']=qs[_0x58f1('0x38')](_0x2fc17b[_0x58f1('0x32')]['sort']);_0xfb6298[_0x58f1('0x39')]=qs[_0x58f1('0x3a')](_['pick'](_0x2fc17b[_0x58f1('0x32')],_0x3422cf[_0x58f1('0x3a')]));if(_0x2fc17b['query'][_0x58f1('0x3b')]){_0xfb6298[_0x58f1('0x39')]=_[_0x58f1('0x3e')](_0xfb6298[_0x58f1('0x39')],{'$or':_['map'](_0xfb6298['attributes'],function(_0x21cf67){var _0x4c06d7={};_0x4c06d7[_0x21cf67]={'$like':'%'+_0x2fc17b['query'][_0x58f1('0x3b')]+'%'};return _0x4c06d7;})});}_0xfb6298=_[_0x58f1('0x3e')]({},_0xfb6298,_0x2fc17b[_0x58f1('0x3f')]);return _0x5a64f8[_0x58f1('0x50')](_0xfb6298);}})[_0x58f1('0x26')](function(_0x1316a2){if(_0x1316a2){_0x3ec6ef=_0x1316a2[_0x58f1('0x45')];if(!_0x2fc17b[_0x58f1('0x32')][_0x58f1('0x36')](_0x58f1('0x37'))){_0xfb6298['limit']=qs[_0x58f1('0x1e')](_0x2fc17b[_0x58f1('0x32')][_0x58f1('0x1e')]);_0xfb6298['offset']=qs[_0x58f1('0x1d')](_0x2fc17b[_0x58f1('0x32')][_0x58f1('0x1d')]);}return _0x5a64f8[_0x58f1('0x50')](_0xfb6298);}})[_0x58f1('0x26')](function(_0x5e4c06){if(_0x5e4c06){return _0x5e4c06?{'count':_0x3ec6ef,'rows':_0x5e4c06}:null;}})[_0x58f1('0x26')](respondWithResult(_0x2f1c07,null))[_0x58f1('0x43')](handleError(_0x2f1c07,null));};