Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / intServicenowConfiguration / intServicenowConfiguration.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 _0x0b57=['../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','update','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','ServicenowConfiguration','catch','show','params','include','find','create','body','getFields','findOne','ServicenowField','hasOwnProperty','getSubjects','getDescriptions','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch'];(function(_0x2c32ae,_0xc93333){var _0xbc3d35=function(_0x34ae92){while(--_0x34ae92){_0x2c32ae['push'](_0x2c32ae['shift']());}};_0xbc3d35(++_0xc93333);}(_0x0b57,0x1d0));var _0x70b5=function(_0x3f48e0,_0x453a44){_0x3f48e0=_0x3f48e0-0x0;var _0x2333e1=_0x0b57[_0x3f48e0];return _0x2333e1;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x70b5('0x0'));var zipdir=require(_0x70b5('0x1'));var jsonpatch=require(_0x70b5('0x2'));var rp=require(_0x70b5('0x3'));var moment=require(_0x70b5('0x4'));var BPromise=require(_0x70b5('0x5'));var Mustache=require(_0x70b5('0x6'));var util=require(_0x70b5('0x7'));var path=require(_0x70b5('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x70b5('0x9'));var fs=require('fs');var fs_extra=require(_0x70b5('0xa'));var _=require(_0x70b5('0xb'));var squel=require(_0x70b5('0xc'));var crypto=require(_0x70b5('0xd'));var jsforce=require(_0x70b5('0xe'));var deskjs=require(_0x70b5('0xf'));var toCsv=require(_0x70b5('0x10'));var querystring=require(_0x70b5('0x11'));var Papa=require('papaparse');var Redis=require(_0x70b5('0x12'));var authService=require(_0x70b5('0x13'));var qs=require(_0x70b5('0x14'));var as=require(_0x70b5('0x15'));var hardwareService=require(_0x70b5('0x16'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x70b5('0x17'));var licenseUtil=require(_0x70b5('0x18'));var db=require(_0x70b5('0x19'))['db'];function respondWithStatusCode(_0x223038,_0x44ae28){_0x44ae28=_0x44ae28||0xcc;return function(_0x2bb5e1){if(_0x2bb5e1){return _0x223038[_0x70b5('0x1a')](_0x44ae28);}return _0x223038[_0x70b5('0x1b')](_0x44ae28)[_0x70b5('0x1c')]();};}function respondWithResult(_0x43b96c,_0x2c2618){_0x2c2618=_0x2c2618||0xc8;return function(_0x4b6aa0){if(_0x4b6aa0){return _0x43b96c[_0x70b5('0x1b')](_0x2c2618)[_0x70b5('0x1d')](_0x4b6aa0);}};}function respondWithFilteredResult(_0x2c9e7f,_0x25cad8){return function(_0x2ee12f){if(_0x2ee12f){var _0x2d0fab=typeof _0x25cad8[_0x70b5('0x1e')]===_0x70b5('0x1f')&&typeof _0x25cad8[_0x70b5('0x20')]===_0x70b5('0x1f');var _0x4e1344=_0x2ee12f[_0x70b5('0x21')];var _0x66c9ad=_0x2d0fab?0x0:_0x25cad8['offset'];var _0x20acaa=_0x2d0fab?_0x2ee12f['count']:_0x25cad8[_0x70b5('0x1e')]+_0x25cad8[_0x70b5('0x20')];var _0x389576;if(_0x20acaa>=_0x4e1344){_0x20acaa=_0x4e1344;_0x389576=0xc8;}else{_0x389576=0xce;}_0x2c9e7f[_0x70b5('0x1b')](_0x389576);return _0x2c9e7f[_0x70b5('0x22')](_0x70b5('0x23'),_0x66c9ad+'-'+_0x20acaa+'/'+_0x4e1344)[_0x70b5('0x1d')](_0x2ee12f);}return null;};}function patchUpdates(_0x28aed3){return function(_0x4e50f9){try{jsonpatch['apply'](_0x4e50f9,_0x28aed3,!![]);}catch(_0x24694a){return BPromise[_0x70b5('0x24')](_0x24694a);}return _0x4e50f9['save']();};}function saveUpdates(_0x166aa9,_0x1e7556){return function(_0x47e656){if(_0x47e656){return _0x47e656[_0x70b5('0x25')](_0x166aa9)[_0x70b5('0x26')](function(_0x2152e8){return _0x2152e8;});}return null;};}function removeEntity(_0xb74621,_0x448b0f){return function(_0x59d8e2){if(_0x59d8e2){return _0x59d8e2[_0x70b5('0x27')]()[_0x70b5('0x26')](function(){_0xb74621[_0x70b5('0x1b')](0xcc)[_0x70b5('0x1c')]();});}};}function handleEntityNotFound(_0xa0871b,_0x22b76a){return function(_0x2bdd19){if(!_0x2bdd19){_0xa0871b['sendStatus'](0x194);}return _0x2bdd19;};}function handleError(_0x8d6091,_0x3b4aba){_0x3b4aba=_0x3b4aba||0x1f4;return function(_0x5a2481){logger[_0x70b5('0x28')](_0x5a2481[_0x70b5('0x29')]);if(_0x5a2481[_0x70b5('0x2a')]){delete _0x5a2481[_0x70b5('0x2a')];}_0x8d6091[_0x70b5('0x1b')](_0x3b4aba)[_0x70b5('0x2b')](_0x5a2481);};}exports[_0x70b5('0x2c')]=function(_0x16e73e,_0xf7e0a9){var _0x2540ac={},_0x134c84={},_0x574c26={'count':0x0,'rows':[]};var _0x5217a5=_[_0x70b5('0x2d')](db['ServicenowConfiguration'][_0x70b5('0x2e')],function(_0xc48168){return{'name':_0xc48168[_0x70b5('0x2f')],'type':_0xc48168[_0x70b5('0x30')]['key']};});_0x134c84[_0x70b5('0x31')]=_[_0x70b5('0x2d')](_0x5217a5,'name');_0x134c84[_0x70b5('0x32')]=_[_0x70b5('0x33')](_0x16e73e['query']);_0x134c84[_0x70b5('0x34')]=_[_0x70b5('0x35')](_0x134c84[_0x70b5('0x31')],_0x134c84[_0x70b5('0x32')]);_0x2540ac[_0x70b5('0x36')]=_[_0x70b5('0x35')](_0x134c84[_0x70b5('0x31')],qs[_0x70b5('0x37')](_0x16e73e[_0x70b5('0x32')][_0x70b5('0x37')]));_0x2540ac[_0x70b5('0x36')]=_0x2540ac[_0x70b5('0x36')][_0x70b5('0x38')]?_0x2540ac[_0x70b5('0x36')]:_0x134c84[_0x70b5('0x31')];if(!_0x16e73e[_0x70b5('0x32')]['hasOwnProperty'](_0x70b5('0x39'))){_0x2540ac[_0x70b5('0x20')]=qs['limit'](_0x16e73e[_0x70b5('0x32')][_0x70b5('0x20')]);_0x2540ac['offset']=qs[_0x70b5('0x1e')](_0x16e73e[_0x70b5('0x32')]['offset']);}_0x2540ac[_0x70b5('0x3a')]=qs[_0x70b5('0x3b')](_0x16e73e[_0x70b5('0x32')]['sort']);_0x2540ac[_0x70b5('0x3c')]=qs[_0x70b5('0x34')](_[_0x70b5('0x3d')](_0x16e73e[_0x70b5('0x32')],_0x134c84[_0x70b5('0x34')]),_0x5217a5);if(_0x16e73e[_0x70b5('0x32')][_0x70b5('0x3e')]){_0x2540ac[_0x70b5('0x3c')]=_['merge'](_0x2540ac[_0x70b5('0x3c')],{'$or':_[_0x70b5('0x2d')](_0x5217a5,function(_0x3d6a1){if(_0x3d6a1[_0x70b5('0x30')]!==_0x70b5('0x3f')){var _0x40fde1={};_0x40fde1[_0x3d6a1[_0x70b5('0x2a')]]={'$like':'%'+_0x16e73e[_0x70b5('0x32')][_0x70b5('0x3e')]+'%'};return _0x40fde1;}})});}_0x2540ac=_[_0x70b5('0x40')]({},_0x2540ac,_0x16e73e[_0x70b5('0x41')]);var _0x3c13c3={'where':_0x2540ac[_0x70b5('0x3c')]};return db['ServicenowConfiguration']['count'](_0x3c13c3)[_0x70b5('0x26')](function(_0x52bb56){_0x574c26[_0x70b5('0x21')]=_0x52bb56;if(_0x16e73e[_0x70b5('0x32')][_0x70b5('0x42')]){_0x2540ac['include']=[{'all':!![]}];}return db[_0x70b5('0x43')]['findAll'](_0x2540ac);})['then'](function(_0x1050b8){_0x574c26['rows']=_0x1050b8;return _0x574c26;})[_0x70b5('0x26')](respondWithFilteredResult(_0xf7e0a9,_0x2540ac))[_0x70b5('0x44')](handleError(_0xf7e0a9,null));};exports[_0x70b5('0x45')]=function(_0x173ea3,_0x5118fc){var _0x333f36={'raw':![],'where':{'id':_0x173ea3[_0x70b5('0x46')]['id']}},_0x2adc41={};_0x2adc41['model']=_[_0x70b5('0x33')](db['ServicenowConfiguration'][_0x70b5('0x2e')]);_0x2adc41[_0x70b5('0x32')]=_[_0x70b5('0x33')](_0x173ea3[_0x70b5('0x32')]);_0x2adc41['filters']=_[_0x70b5('0x35')](_0x2adc41[_0x70b5('0x31')],_0x2adc41[_0x70b5('0x32')]);_0x333f36['attributes']=_[_0x70b5('0x35')](_0x2adc41[_0x70b5('0x31')],qs[_0x70b5('0x37')](_0x173ea3[_0x70b5('0x32')][_0x70b5('0x37')]));_0x333f36[_0x70b5('0x36')]=_0x333f36[_0x70b5('0x36')][_0x70b5('0x38')]?_0x333f36['attributes']:_0x2adc41[_0x70b5('0x31')];if(_0x173ea3[_0x70b5('0x32')]['includeAll']){_0x333f36[_0x70b5('0x47')]=[{'all':!![]}];}_0x333f36=_[_0x70b5('0x40')]({},_0x333f36,_0x173ea3['options']);return db[_0x70b5('0x43')][_0x70b5('0x48')](_0x333f36)['then'](handleEntityNotFound(_0x5118fc,null))[_0x70b5('0x26')](respondWithResult(_0x5118fc,null))[_0x70b5('0x44')](handleError(_0x5118fc,null));};exports[_0x70b5('0x49')]=function(_0xc08715,_0x554abc){return db[_0x70b5('0x43')][_0x70b5('0x49')](_0xc08715[_0x70b5('0x4a')],{})['then'](respondWithResult(_0x554abc,0xc9))['catch'](handleError(_0x554abc,null));};exports[_0x70b5('0x25')]=function(_0x998676,_0x51ab9c){if(_0x998676['body']['id']){delete _0x998676[_0x70b5('0x4a')]['id'];}return db['ServicenowConfiguration'][_0x70b5('0x48')]({'where':{'id':_0x998676['params']['id']}})['then'](handleEntityNotFound(_0x51ab9c,null))[_0x70b5('0x26')](saveUpdates(_0x998676[_0x70b5('0x4a')],null))['then'](respondWithResult(_0x51ab9c,null))['catch'](handleError(_0x51ab9c,null));};exports['destroy']=function(_0x11d838,_0x36bac1){return db[_0x70b5('0x43')][_0x70b5('0x48')]({'where':{'id':_0x11d838[_0x70b5('0x46')]['id']}})[_0x70b5('0x26')](handleEntityNotFound(_0x36bac1,null))[_0x70b5('0x26')](removeEntity(_0x36bac1,null))[_0x70b5('0x44')](handleError(_0x36bac1,null));};exports[_0x70b5('0x4b')]=function(_0x3fa4d1,_0x4528fc,_0x2da6b0){var _0x366267={};var _0x2cdbdb={};var _0xaa7c;var _0x379e56;return db['ServicenowConfiguration'][_0x70b5('0x4c')]({'where':{'id':_0x3fa4d1[_0x70b5('0x46')]['id']}})[_0x70b5('0x26')](handleEntityNotFound(_0x4528fc,null))[_0x70b5('0x26')](function(_0x49d1ea){if(_0x49d1ea){_0xaa7c=_0x49d1ea;_0x2cdbdb[_0x70b5('0x31')]=_[_0x70b5('0x33')](db[_0x70b5('0x4d')][_0x70b5('0x2e')]);_0x2cdbdb['query']=_[_0x70b5('0x33')](_0x3fa4d1[_0x70b5('0x32')]);_0x2cdbdb[_0x70b5('0x34')]=_[_0x70b5('0x35')](_0x2cdbdb[_0x70b5('0x31')],_0x2cdbdb[_0x70b5('0x32')]);_0x366267['attributes']=_[_0x70b5('0x35')](_0x2cdbdb['model'],qs[_0x70b5('0x37')](_0x3fa4d1[_0x70b5('0x32')][_0x70b5('0x37')]));_0x366267['attributes']=_0x366267[_0x70b5('0x36')][_0x70b5('0x38')]?_0x366267[_0x70b5('0x36')]:_0x2cdbdb[_0x70b5('0x31')];_0x366267[_0x70b5('0x3a')]=qs[_0x70b5('0x3b')](_0x3fa4d1['query']['sort']);_0x366267['where']=qs[_0x70b5('0x34')](_['pick'](_0x3fa4d1['query'],_0x2cdbdb[_0x70b5('0x34')]));if(_0x3fa4d1[_0x70b5('0x32')][_0x70b5('0x3e')]){_0x366267[_0x70b5('0x3c')]=_[_0x70b5('0x40')](_0x366267[_0x70b5('0x3c')],{'$or':_['map'](_0x366267['attributes'],function(_0x2c4900){var _0xfbd1e7={};_0xfbd1e7[_0x2c4900]={'$like':'%'+_0x3fa4d1[_0x70b5('0x32')][_0x70b5('0x3e')]+'%'};return _0xfbd1e7;})});}_0x366267=_['merge']({},_0x366267,_0x3fa4d1[_0x70b5('0x41')]);return _0xaa7c[_0x70b5('0x4b')](_0x366267);}})[_0x70b5('0x26')](function(_0x31fc06){if(_0x31fc06){_0x379e56=_0x31fc06[_0x70b5('0x38')];if(!_0x3fa4d1[_0x70b5('0x32')][_0x70b5('0x4e')](_0x70b5('0x39'))){_0x366267['limit']=qs[_0x70b5('0x20')](_0x3fa4d1[_0x70b5('0x32')][_0x70b5('0x20')]);_0x366267[_0x70b5('0x1e')]=qs['offset'](_0x3fa4d1[_0x70b5('0x32')]['offset']);}return _0xaa7c[_0x70b5('0x4b')](_0x366267);}})[_0x70b5('0x26')](function(_0x3e4eaf){if(_0x3e4eaf){return _0x3e4eaf?{'count':_0x379e56,'rows':_0x3e4eaf}:null;}})['then'](respondWithResult(_0x4528fc,null))['catch'](handleError(_0x4528fc,null));};exports[_0x70b5('0x4f')]=function(_0x548487,_0x236e01,_0x4e22a2){var _0x57a66c={};var _0x5f1fc6={};var _0x570204;var _0x580eaf;return db['ServicenowConfiguration'][_0x70b5('0x4c')]({'where':{'id':_0x548487['params']['id']}})[_0x70b5('0x26')](handleEntityNotFound(_0x236e01,null))[_0x70b5('0x26')](function(_0x5c77d2){if(_0x5c77d2){_0x570204=_0x5c77d2;_0x5f1fc6[_0x70b5('0x31')]=_[_0x70b5('0x33')](db[_0x70b5('0x4d')][_0x70b5('0x2e')]);_0x5f1fc6[_0x70b5('0x32')]=_['keys'](_0x548487['query']);_0x5f1fc6[_0x70b5('0x34')]=_[_0x70b5('0x35')](_0x5f1fc6[_0x70b5('0x31')],_0x5f1fc6['query']);_0x57a66c['attributes']=_[_0x70b5('0x35')](_0x5f1fc6[_0x70b5('0x31')],qs[_0x70b5('0x37')](_0x548487['query']['fields']));_0x57a66c[_0x70b5('0x36')]=_0x57a66c[_0x70b5('0x36')]['length']?_0x57a66c[_0x70b5('0x36')]:_0x5f1fc6[_0x70b5('0x31')];_0x57a66c[_0x70b5('0x3a')]=qs[_0x70b5('0x3b')](_0x548487[_0x70b5('0x32')][_0x70b5('0x3b')]);_0x57a66c[_0x70b5('0x3c')]=qs['filters'](_['pick'](_0x548487[_0x70b5('0x32')],_0x5f1fc6[_0x70b5('0x34')]));if(_0x548487[_0x70b5('0x32')][_0x70b5('0x3e')]){_0x57a66c['where']=_['merge'](_0x57a66c['where'],{'$or':_[_0x70b5('0x2d')](_0x57a66c[_0x70b5('0x36')],function(_0x2dad18){var _0x487b4b={};_0x487b4b[_0x2dad18]={'$like':'%'+_0x548487['query'][_0x70b5('0x3e')]+'%'};return _0x487b4b;})});}_0x57a66c=_[_0x70b5('0x40')]({},_0x57a66c,_0x548487[_0x70b5('0x41')]);return _0x570204['getSubjects'](_0x57a66c);}})[_0x70b5('0x26')](function(_0x5d2e03){if(_0x5d2e03){_0x580eaf=_0x5d2e03[_0x70b5('0x38')];if(!_0x548487['query'][_0x70b5('0x4e')](_0x70b5('0x39'))){_0x57a66c[_0x70b5('0x20')]=qs['limit'](_0x548487['query'][_0x70b5('0x20')]);_0x57a66c[_0x70b5('0x1e')]=qs[_0x70b5('0x1e')](_0x548487['query'][_0x70b5('0x1e')]);}return _0x570204[_0x70b5('0x4f')](_0x57a66c);}})[_0x70b5('0x26')](function(_0x18d441){if(_0x18d441){return _0x18d441?{'count':_0x580eaf,'rows':_0x18d441}:null;}})[_0x70b5('0x26')](respondWithResult(_0x236e01,null))[_0x70b5('0x44')](handleError(_0x236e01,null));};exports[_0x70b5('0x50')]=function(_0x428ee5,_0x1b5f52,_0x5dd5f3){var _0x73a740={};var _0x1c0789={};var _0x2212ac;var _0x30e316;return db[_0x70b5('0x43')]['findOne']({'where':{'id':_0x428ee5[_0x70b5('0x46')]['id']}})[_0x70b5('0x26')](handleEntityNotFound(_0x1b5f52,null))[_0x70b5('0x26')](function(_0xa99c84){if(_0xa99c84){_0x2212ac=_0xa99c84;_0x1c0789[_0x70b5('0x31')]=_[_0x70b5('0x33')](db[_0x70b5('0x4d')][_0x70b5('0x2e')]);_0x1c0789['query']=_[_0x70b5('0x33')](_0x428ee5['query']);_0x1c0789[_0x70b5('0x34')]=_['intersection'](_0x1c0789[_0x70b5('0x31')],_0x1c0789[_0x70b5('0x32')]);_0x73a740['attributes']=_[_0x70b5('0x35')](_0x1c0789[_0x70b5('0x31')],qs[_0x70b5('0x37')](_0x428ee5[_0x70b5('0x32')]['fields']));_0x73a740[_0x70b5('0x36')]=_0x73a740[_0x70b5('0x36')][_0x70b5('0x38')]?_0x73a740[_0x70b5('0x36')]:_0x1c0789[_0x70b5('0x31')];_0x73a740[_0x70b5('0x3a')]=qs[_0x70b5('0x3b')](_0x428ee5[_0x70b5('0x32')][_0x70b5('0x3b')]);_0x73a740[_0x70b5('0x3c')]=qs[_0x70b5('0x34')](_[_0x70b5('0x3d')](_0x428ee5[_0x70b5('0x32')],_0x1c0789[_0x70b5('0x34')]));if(_0x428ee5['query'][_0x70b5('0x3e')]){_0x73a740[_0x70b5('0x3c')]=_['merge'](_0x73a740[_0x70b5('0x3c')],{'$or':_[_0x70b5('0x2d')](_0x73a740[_0x70b5('0x36')],function(_0x4ddb73){var _0x5182c2={};_0x5182c2[_0x4ddb73]={'$like':'%'+_0x428ee5[_0x70b5('0x32')][_0x70b5('0x3e')]+'%'};return _0x5182c2;})});}_0x73a740=_[_0x70b5('0x40')]({},_0x73a740,_0x428ee5[_0x70b5('0x41')]);return _0x2212ac[_0x70b5('0x50')](_0x73a740);}})[_0x70b5('0x26')](function(_0x264425){if(_0x264425){_0x30e316=_0x264425[_0x70b5('0x38')];if(!_0x428ee5[_0x70b5('0x32')][_0x70b5('0x4e')](_0x70b5('0x39'))){_0x73a740[_0x70b5('0x20')]=qs[_0x70b5('0x20')](_0x428ee5['query'][_0x70b5('0x20')]);_0x73a740[_0x70b5('0x1e')]=qs[_0x70b5('0x1e')](_0x428ee5['query'][_0x70b5('0x1e')]);}return _0x2212ac[_0x70b5('0x50')](_0x73a740);}})[_0x70b5('0x26')](function(_0x4a2f0d){if(_0x4a2f0d){return _0x4a2f0d?{'count':_0x30e316,'rows':_0x4a2f0d}:null;}})['then'](respondWithResult(_0x1b5f52,null))[_0x70b5('0x44')](handleError(_0x1b5f52,null));};