Built motion from commit (unavailable).|2.5.1
[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 _0x410b=['error','code','message','result','catch','sendStatus','status','end','json','offset','limit','set','Content-Range','save','update','destroy','then','stack','name','send','index','ServicenowConfiguration','rawAttributes','type','key','model','map','keys','intersection','query','attributes','fields','hasOwnProperty','order','sort','where','filters','pick','merge','filter','options','count','includeAll','include','findAll','rows','show','length','find','create','body','params','getFields','getSubjects','findOne','ServicenowField','nolimit','getDescriptions','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','jayson/promise','client','http','request','info','ServicenowConfiguration,\x20%s,\x20%s','request\x20sent','debug','ServicenowConfiguration,\x20%s,\x20%s,\x20%s','stringify'];(function(_0x14e8b8,_0x418d3b){var _0x11967e=function(_0x4a0b41){while(--_0x4a0b41){_0x14e8b8['push'](_0x14e8b8['shift']());}};_0x11967e(++_0x418d3b);}(_0x410b,0x14b));var _0xb410=function(_0x22811e,_0x145170){_0x22811e=_0x22811e-0x0;var _0xcc69c4=_0x410b[_0x22811e];return _0xcc69c4;};'use strict';var pdf=require(_0xb410('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xb410('0x1'));var zipdir=require(_0xb410('0x2'));var jsonpatch=require(_0xb410('0x3'));var rp=require(_0xb410('0x4'));var moment=require(_0xb410('0x5'));var BPromise=require(_0xb410('0x6'));var Mustache=require('mustache');var util=require(_0xb410('0x7'));var path=require(_0xb410('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xb410('0x9'));var squel=require(_0xb410('0xa'));var crypto=require(_0xb410('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xb410('0xc'));var toCsv=require(_0xb410('0xd'));var querystring=require(_0xb410('0xe'));var Papa=require(_0xb410('0xf'));var Redis=require('ioredis');var authService=require(_0xb410('0x10'));var qs=require(_0xb410('0x11'));var as=require(_0xb410('0x12'));var hardwareService=require(_0xb410('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xb410('0x14'));var config=require(_0xb410('0x15'));var licenseUtil=require(_0xb410('0x16'));var db=require('../../mysqldb')['db'];var jayson=require(_0xb410('0x17'));var client=jayson[_0xb410('0x18')][_0xb410('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x5e3fcc,_0x4a34a3,_0x48949b,_0x13c86f){return new BPromise(function(_0x57a0bd,_0x3eaa49){var _0x5908dd=_0x13c86f||client;return _0x5908dd[_0xb410('0x1a')](_0x5e3fcc,_0x48949b)['then'](function(_0x539263){logger[_0xb410('0x1b')](_0xb410('0x1c'),_0x4a34a3,_0xb410('0x1d'));logger[_0xb410('0x1e')](_0xb410('0x1f'),_0x4a34a3,_0xb410('0x1d'),JSON[_0xb410('0x20')](_0x539263));if(_0x539263[_0xb410('0x21')]){if(_0x539263[_0xb410('0x21')][_0xb410('0x22')]===0x1f4){logger['error'](_0xb410('0x1c'),_0x4a34a3,_0x539263[_0xb410('0x21')][_0xb410('0x23')]);return _0x3eaa49(_0x539263['error']['message']);}logger['error'](_0xb410('0x1c'),_0x4a34a3,_0x539263[_0xb410('0x21')][_0xb410('0x23')]);return _0x57a0bd(_0x539263[_0xb410('0x21')][_0xb410('0x23')]);}else{logger[_0xb410('0x1b')](_0xb410('0x1c'),_0x4a34a3,_0xb410('0x1d'));_0x57a0bd(_0x539263[_0xb410('0x24')][_0xb410('0x23')]);}})[_0xb410('0x25')](function(_0x843e15){logger[_0xb410('0x21')](_0xb410('0x1c'),_0x4a34a3,_0x843e15);_0x3eaa49(_0x843e15);});});}function respondWithStatusCode(_0x3225b7,_0x26c951){_0x26c951=_0x26c951||0xcc;return function(_0x1d8914){if(_0x1d8914){return _0x3225b7[_0xb410('0x26')](_0x26c951);}return _0x3225b7[_0xb410('0x27')](_0x26c951)[_0xb410('0x28')]();};}function respondWithResult(_0x571058,_0xe184b2){_0xe184b2=_0xe184b2||0xc8;return function(_0x13c75e){if(_0x13c75e){return _0x571058[_0xb410('0x27')](_0xe184b2)[_0xb410('0x29')](_0x13c75e);}};}function respondWithFilteredResult(_0x1e6e55,_0x904bd5){return function(_0x48f4a3){if(_0x48f4a3){var _0x58d978=_0x48f4a3['count'],_0x177c4c=_0x904bd5['offset'],_0x4e9247=_0x904bd5[_0xb410('0x2a')]+_0x904bd5[_0xb410('0x2b')],_0xcd4c16;if(_0x4e9247>=_0x58d978){_0x4e9247=_0x58d978;_0xcd4c16=0xc8;}else{_0xcd4c16=0xce;}_0x1e6e55[_0xb410('0x27')](_0xcd4c16);return _0x1e6e55[_0xb410('0x2c')](_0xb410('0x2d'),_0x177c4c+'-'+_0x4e9247+'/'+_0x58d978)[_0xb410('0x29')](_0x48f4a3);}return null;};}function patchUpdates(_0x3499da){return function(_0x650bcd){try{jsonpatch['apply'](_0x650bcd,_0x3499da,!![]);}catch(_0x128142){return BPromise['reject'](_0x128142);}return _0x650bcd[_0xb410('0x2e')]();};}function saveUpdates(_0x18ca69,_0x21b01c){return function(_0x50ef39){if(_0x50ef39){return _0x50ef39[_0xb410('0x2f')](_0x18ca69)['then'](function(_0x5e2157){return _0x5e2157;});}return null;};}function removeEntity(_0x31900e,_0x553995){return function(_0x1bf165){if(_0x1bf165){return _0x1bf165[_0xb410('0x30')]()[_0xb410('0x31')](function(){_0x31900e[_0xb410('0x27')](0xcc)[_0xb410('0x28')]();});}};}function handleEntityNotFound(_0x3aaaae,_0x44b976){return function(_0x2e4703){if(!_0x2e4703){_0x3aaaae['sendStatus'](0x194);}return _0x2e4703;};}function handleError(_0x659ebd,_0x50d927){_0x50d927=_0x50d927||0x1f4;return function(_0x2b226a){logger['error'](_0x2b226a[_0xb410('0x32')]);if(_0x2b226a[_0xb410('0x33')]){delete _0x2b226a[_0xb410('0x33')];}_0x659ebd['status'](_0x50d927)[_0xb410('0x34')](_0x2b226a);};}exports[_0xb410('0x35')]=function(_0x9db1d1,_0x19f7ae){var _0x1f8f11={},_0x27142d={},_0xfc0813={'count':0x0,'rows':[]};var _0x39fdd2=_['map'](db[_0xb410('0x36')][_0xb410('0x37')],function(_0x580925){return{'name':_0x580925['fieldName'],'type':_0x580925[_0xb410('0x38')][_0xb410('0x39')]};});_0x27142d[_0xb410('0x3a')]=_[_0xb410('0x3b')](_0x39fdd2,_0xb410('0x33'));_0x27142d['query']=_[_0xb410('0x3c')](_0x9db1d1['query']);_0x27142d['filters']=_[_0xb410('0x3d')](_0x27142d[_0xb410('0x3a')],_0x27142d[_0xb410('0x3e')]);_0x1f8f11[_0xb410('0x3f')]=_['intersection'](_0x27142d['model'],qs[_0xb410('0x40')](_0x9db1d1[_0xb410('0x3e')][_0xb410('0x40')]));_0x1f8f11[_0xb410('0x3f')]=_0x1f8f11['attributes']['length']?_0x1f8f11['attributes']:_0x27142d[_0xb410('0x3a')];if(!_0x9db1d1[_0xb410('0x3e')][_0xb410('0x41')]('nolimit')){_0x1f8f11[_0xb410('0x2b')]=qs[_0xb410('0x2b')](_0x9db1d1[_0xb410('0x3e')][_0xb410('0x2b')]);_0x1f8f11[_0xb410('0x2a')]=qs[_0xb410('0x2a')](_0x9db1d1[_0xb410('0x3e')][_0xb410('0x2a')]);}_0x1f8f11[_0xb410('0x42')]=qs[_0xb410('0x43')](_0x9db1d1[_0xb410('0x3e')]['sort']);_0x1f8f11[_0xb410('0x44')]=qs[_0xb410('0x45')](_[_0xb410('0x46')](_0x9db1d1[_0xb410('0x3e')],_0x27142d[_0xb410('0x45')]),_0x39fdd2);if(_0x9db1d1['query']['filter']){_0x1f8f11[_0xb410('0x44')]=_[_0xb410('0x47')](_0x1f8f11[_0xb410('0x44')],{'$or':_[_0xb410('0x3b')](_0x39fdd2,function(_0x3b2db0){if(_0x3b2db0[_0xb410('0x38')]!=='VIRTUAL'){var _0x541148={};_0x541148[_0x3b2db0[_0xb410('0x33')]]={'$like':'%'+_0x9db1d1[_0xb410('0x3e')][_0xb410('0x48')]+'%'};return _0x541148;}})});}_0x1f8f11=_[_0xb410('0x47')]({},_0x1f8f11,_0x9db1d1[_0xb410('0x49')]);var _0x2b4e75={'where':_0x1f8f11['where']};return db['ServicenowConfiguration'][_0xb410('0x4a')](_0x2b4e75)[_0xb410('0x31')](function(_0x3bd53c){_0xfc0813[_0xb410('0x4a')]=_0x3bd53c;if(_0x9db1d1['query'][_0xb410('0x4b')]){_0x1f8f11[_0xb410('0x4c')]=[{'all':!![]}];}return db[_0xb410('0x36')][_0xb410('0x4d')](_0x1f8f11);})[_0xb410('0x31')](function(_0x4c655a){_0xfc0813[_0xb410('0x4e')]=_0x4c655a;return _0xfc0813;})[_0xb410('0x31')](respondWithFilteredResult(_0x19f7ae,_0x1f8f11))['catch'](handleError(_0x19f7ae,null));};exports[_0xb410('0x4f')]=function(_0x16e049,_0x5b48a2){var _0x62e198={'raw':![],'where':{'id':_0x16e049['params']['id']}},_0x30a5d7={};_0x30a5d7[_0xb410('0x3a')]=_['keys'](db[_0xb410('0x36')][_0xb410('0x37')]);_0x30a5d7[_0xb410('0x3e')]=_[_0xb410('0x3c')](_0x16e049[_0xb410('0x3e')]);_0x30a5d7[_0xb410('0x45')]=_[_0xb410('0x3d')](_0x30a5d7[_0xb410('0x3a')],_0x30a5d7[_0xb410('0x3e')]);_0x62e198['attributes']=_[_0xb410('0x3d')](_0x30a5d7[_0xb410('0x3a')],qs['fields'](_0x16e049[_0xb410('0x3e')][_0xb410('0x40')]));_0x62e198[_0xb410('0x3f')]=_0x62e198[_0xb410('0x3f')][_0xb410('0x50')]?_0x62e198[_0xb410('0x3f')]:_0x30a5d7[_0xb410('0x3a')];if(_0x16e049[_0xb410('0x3e')][_0xb410('0x4b')]){_0x62e198[_0xb410('0x4c')]=[{'all':!![]}];}_0x62e198=_[_0xb410('0x47')]({},_0x62e198,_0x16e049[_0xb410('0x49')]);return db['ServicenowConfiguration'][_0xb410('0x51')](_0x62e198)[_0xb410('0x31')](handleEntityNotFound(_0x5b48a2,null))[_0xb410('0x31')](respondWithResult(_0x5b48a2,null))[_0xb410('0x25')](handleError(_0x5b48a2,null));};exports[_0xb410('0x52')]=function(_0x2edf48,_0x32f356){return db[_0xb410('0x36')][_0xb410('0x52')](_0x2edf48[_0xb410('0x53')],{})[_0xb410('0x31')](respondWithResult(_0x32f356,0xc9))[_0xb410('0x25')](handleError(_0x32f356,null));};exports[_0xb410('0x2f')]=function(_0x2232e9,_0x56bc90){if(_0x2232e9[_0xb410('0x53')]['id']){delete _0x2232e9[_0xb410('0x53')]['id'];}return db[_0xb410('0x36')][_0xb410('0x51')]({'where':{'id':_0x2232e9[_0xb410('0x54')]['id']}})[_0xb410('0x31')](handleEntityNotFound(_0x56bc90,null))[_0xb410('0x31')](saveUpdates(_0x2232e9['body'],null))[_0xb410('0x31')](respondWithResult(_0x56bc90,null))['catch'](handleError(_0x56bc90,null));};exports[_0xb410('0x30')]=function(_0x104851,_0x26af82){return db[_0xb410('0x36')][_0xb410('0x51')]({'where':{'id':_0x104851['params']['id']}})[_0xb410('0x31')](handleEntityNotFound(_0x26af82,null))[_0xb410('0x31')](removeEntity(_0x26af82,null))[_0xb410('0x25')](handleError(_0x26af82,null));};exports[_0xb410('0x55')]=function(_0x1b177c,_0x127ade,_0x23c3c9){var _0x11092d={};var _0xba8de={};var _0x348d93;var _0x23b3c2;return db[_0xb410('0x36')]['findOne']({'where':{'id':_0x1b177c['params']['id']}})[_0xb410('0x31')](handleEntityNotFound(_0x127ade,null))['then'](function(_0x267868){if(_0x267868){_0x348d93=_0x267868;_0xba8de['model']=_['keys'](db['ServicenowField']['rawAttributes']);_0xba8de[_0xb410('0x3e')]=_[_0xb410('0x3c')](_0x1b177c[_0xb410('0x3e')]);_0xba8de[_0xb410('0x45')]=_[_0xb410('0x3d')](_0xba8de[_0xb410('0x3a')],_0xba8de[_0xb410('0x3e')]);_0x11092d[_0xb410('0x3f')]=_[_0xb410('0x3d')](_0xba8de['model'],qs[_0xb410('0x40')](_0x1b177c[_0xb410('0x3e')]['fields']));_0x11092d['attributes']=_0x11092d['attributes'][_0xb410('0x50')]?_0x11092d['attributes']:_0xba8de[_0xb410('0x3a')];_0x11092d[_0xb410('0x42')]=qs['sort'](_0x1b177c[_0xb410('0x3e')]['sort']);_0x11092d['where']=qs[_0xb410('0x45')](_[_0xb410('0x46')](_0x1b177c[_0xb410('0x3e')],_0xba8de[_0xb410('0x45')]));if(_0x1b177c[_0xb410('0x3e')][_0xb410('0x48')]){_0x11092d[_0xb410('0x44')]=_['merge'](_0x11092d[_0xb410('0x44')],{'$or':_['map'](_0x11092d[_0xb410('0x3f')],function(_0x3370f9){var _0x128756={};_0x128756[_0x3370f9]={'$like':'%'+_0x1b177c[_0xb410('0x3e')]['filter']+'%'};return _0x128756;})});}_0x11092d=_['merge']({},_0x11092d,_0x1b177c[_0xb410('0x49')]);return _0x348d93[_0xb410('0x55')](_0x11092d);}})[_0xb410('0x31')](function(_0x2f1019){if(_0x2f1019){_0x23b3c2=_0x2f1019[_0xb410('0x50')];if(!_0x1b177c[_0xb410('0x3e')]['hasOwnProperty']('nolimit')){_0x11092d[_0xb410('0x2b')]=qs[_0xb410('0x2b')](_0x1b177c[_0xb410('0x3e')][_0xb410('0x2b')]);_0x11092d['offset']=qs['offset'](_0x1b177c[_0xb410('0x3e')]['offset']);}return _0x348d93[_0xb410('0x55')](_0x11092d);}})[_0xb410('0x31')](function(_0x3a0084){if(_0x3a0084){return _0x3a0084?{'count':_0x23b3c2,'rows':_0x3a0084}:null;}})['then'](respondWithResult(_0x127ade,null))[_0xb410('0x25')](handleError(_0x127ade,null));};exports[_0xb410('0x56')]=function(_0x155f20,_0x11c35b,_0x28446e){var _0x2b8c93={};var _0x55c562={};var _0x31232d;var _0x59f06f;return db[_0xb410('0x36')][_0xb410('0x57')]({'where':{'id':_0x155f20[_0xb410('0x54')]['id']}})['then'](handleEntityNotFound(_0x11c35b,null))[_0xb410('0x31')](function(_0x2552f1){if(_0x2552f1){_0x31232d=_0x2552f1;_0x55c562[_0xb410('0x3a')]=_['keys'](db[_0xb410('0x58')][_0xb410('0x37')]);_0x55c562[_0xb410('0x3e')]=_[_0xb410('0x3c')](_0x155f20[_0xb410('0x3e')]);_0x55c562[_0xb410('0x45')]=_[_0xb410('0x3d')](_0x55c562['model'],_0x55c562['query']);_0x2b8c93[_0xb410('0x3f')]=_['intersection'](_0x55c562[_0xb410('0x3a')],qs[_0xb410('0x40')](_0x155f20['query'][_0xb410('0x40')]));_0x2b8c93[_0xb410('0x3f')]=_0x2b8c93[_0xb410('0x3f')][_0xb410('0x50')]?_0x2b8c93[_0xb410('0x3f')]:_0x55c562['model'];_0x2b8c93[_0xb410('0x42')]=qs[_0xb410('0x43')](_0x155f20[_0xb410('0x3e')]['sort']);_0x2b8c93['where']=qs[_0xb410('0x45')](_[_0xb410('0x46')](_0x155f20[_0xb410('0x3e')],_0x55c562['filters']));if(_0x155f20[_0xb410('0x3e')][_0xb410('0x48')]){_0x2b8c93[_0xb410('0x44')]=_['merge'](_0x2b8c93[_0xb410('0x44')],{'$or':_['map'](_0x2b8c93[_0xb410('0x3f')],function(_0x33fc5b){var _0x5bcffa={};_0x5bcffa[_0x33fc5b]={'$like':'%'+_0x155f20[_0xb410('0x3e')][_0xb410('0x48')]+'%'};return _0x5bcffa;})});}_0x2b8c93=_['merge']({},_0x2b8c93,_0x155f20[_0xb410('0x49')]);return _0x31232d['getSubjects'](_0x2b8c93);}})['then'](function(_0x12879a){if(_0x12879a){_0x59f06f=_0x12879a[_0xb410('0x50')];if(!_0x155f20[_0xb410('0x3e')]['hasOwnProperty'](_0xb410('0x59'))){_0x2b8c93[_0xb410('0x2b')]=qs['limit'](_0x155f20[_0xb410('0x3e')]['limit']);_0x2b8c93[_0xb410('0x2a')]=qs['offset'](_0x155f20['query'][_0xb410('0x2a')]);}return _0x31232d[_0xb410('0x56')](_0x2b8c93);}})[_0xb410('0x31')](function(_0x228047){if(_0x228047){return _0x228047?{'count':_0x59f06f,'rows':_0x228047}:null;}})[_0xb410('0x31')](respondWithResult(_0x11c35b,null))[_0xb410('0x25')](handleError(_0x11c35b,null));};exports['getDescriptions']=function(_0x38fd0e,_0x91b841,_0x455eb1){var _0x1d3cf4={};var _0x3fe098={};var _0x539804;var _0x15a405;return db[_0xb410('0x36')][_0xb410('0x57')]({'where':{'id':_0x38fd0e[_0xb410('0x54')]['id']}})[_0xb410('0x31')](handleEntityNotFound(_0x91b841,null))[_0xb410('0x31')](function(_0x1d41b9){if(_0x1d41b9){_0x539804=_0x1d41b9;_0x3fe098['model']=_['keys'](db['ServicenowField'][_0xb410('0x37')]);_0x3fe098[_0xb410('0x3e')]=_[_0xb410('0x3c')](_0x38fd0e['query']);_0x3fe098['filters']=_[_0xb410('0x3d')](_0x3fe098[_0xb410('0x3a')],_0x3fe098[_0xb410('0x3e')]);_0x1d3cf4[_0xb410('0x3f')]=_[_0xb410('0x3d')](_0x3fe098[_0xb410('0x3a')],qs[_0xb410('0x40')](_0x38fd0e[_0xb410('0x3e')]['fields']));_0x1d3cf4[_0xb410('0x3f')]=_0x1d3cf4[_0xb410('0x3f')][_0xb410('0x50')]?_0x1d3cf4[_0xb410('0x3f')]:_0x3fe098[_0xb410('0x3a')];_0x1d3cf4['order']=qs[_0xb410('0x43')](_0x38fd0e[_0xb410('0x3e')][_0xb410('0x43')]);_0x1d3cf4[_0xb410('0x44')]=qs['filters'](_[_0xb410('0x46')](_0x38fd0e[_0xb410('0x3e')],_0x3fe098['filters']));if(_0x38fd0e[_0xb410('0x3e')][_0xb410('0x48')]){_0x1d3cf4[_0xb410('0x44')]=_[_0xb410('0x47')](_0x1d3cf4[_0xb410('0x44')],{'$or':_['map'](_0x1d3cf4[_0xb410('0x3f')],function(_0x3fe5cc){var _0x2e0d21={};_0x2e0d21[_0x3fe5cc]={'$like':'%'+_0x38fd0e[_0xb410('0x3e')][_0xb410('0x48')]+'%'};return _0x2e0d21;})});}_0x1d3cf4=_[_0xb410('0x47')]({},_0x1d3cf4,_0x38fd0e[_0xb410('0x49')]);return _0x539804[_0xb410('0x5a')](_0x1d3cf4);}})['then'](function(_0xacc143){if(_0xacc143){_0x15a405=_0xacc143[_0xb410('0x50')];if(!_0x38fd0e['query'][_0xb410('0x41')](_0xb410('0x59'))){_0x1d3cf4[_0xb410('0x2b')]=qs[_0xb410('0x2b')](_0x38fd0e['query'][_0xb410('0x2b')]);_0x1d3cf4[_0xb410('0x2a')]=qs['offset'](_0x38fd0e[_0xb410('0x3e')][_0xb410('0x2a')]);}return _0x539804[_0xb410('0x5a')](_0x1d3cf4);}})['then'](function(_0x5112de){if(_0x5112de){return _0x5112de?{'count':_0x15a405,'rows':_0x5112de}:null;}})['then'](respondWithResult(_0x91b841,null))['catch'](handleError(_0x91b841,null));};