Built motion from commit (unavailable).|2.5.0
[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 _0x62f0=['create','body','findOne','keys','ServicenowField','getFields','getSubjects','getDescriptions','html-pdf','eml-format','rimraf','zip-dir','moment','path','sox','ejs','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','client','test','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','ServicenowConfiguration,\x20%s,\x20%s','request\x20sent','debug','ServicenowConfiguration,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','status','end','json','count','offset','limit','set','apply','reject','save','update','destroy','stack','name','send','index','map','rawAttributes','fieldName','query','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','ServicenowConfiguration','includeAll','include','findAll','rows','show','params','length','find'];(function(_0x216428,_0x5d20ea){var _0x313dd4=function(_0x447e0d){while(--_0x447e0d){_0x216428['push'](_0x216428['shift']());}};_0x313dd4(++_0x5d20ea);}(_0x62f0,0x67));var _0x062f=function(_0x56085e,_0x5c69e9){_0x56085e=_0x56085e-0x0;var _0x4de130=_0x62f0[_0x56085e];return _0x4de130;};'use strict';var pdf=require(_0x062f('0x0'));var emlformat=require(_0x062f('0x1'));var rimraf=require(_0x062f('0x2'));var zipdir=require(_0x062f('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x062f('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x062f('0x5'));var sox=require(_0x062f('0x6'));var csv=require('to-csv');var ejs=require(_0x062f('0x7'));var fs=require('fs');var _=require('lodash');var squel=require(_0x062f('0x8'));var crypto=require(_0x062f('0x9'));var jsforce=require(_0x062f('0xa'));var deskjs=require(_0x062f('0xb'));var toCsv=require(_0x062f('0xc'));var querystring=require(_0x062f('0xd'));var Papa=require(_0x062f('0xe'));var Redis=require(_0x062f('0xf'));var authService=require(_0x062f('0x10'));var qs=require(_0x062f('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x062f('0x12'));var logger=require(_0x062f('0x13'))(_0x062f('0x14'));var utils=require(_0x062f('0x15'));var config=require(_0x062f('0x16'));var db=require(_0x062f('0x17'))['db'];var jayson=require(_0x062f('0x18'));var client=jayson[_0x062f('0x19')]['http']({'port':0x232a});function checkPasswordPattern(_0x32bae9,_0x1bd148,_0x25a933){if(_0x25a933){var _0x3a89a0=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x3a89a0[_0x062f('0x1a')](_0x1bd148)){return _0x32bae9;}else{throw new db['Sequelize'][(_0x062f('0x1b'))](_0x062f('0x1c'));}}else{return _0x32bae9;}}function respondWithRpcPromise(_0x291d70,_0x5ec273,_0x3b7c96,_0x2ddb74){return new BPromise(function(_0x5dd6bc,_0x50399a){var _0x335b24=_0x2ddb74||client;return _0x335b24[_0x062f('0x1d')](_0x291d70,_0x3b7c96)[_0x062f('0x1e')](function(_0x57c190){logger['info'](_0x062f('0x1f'),_0x5ec273,_0x062f('0x20'));logger[_0x062f('0x21')](_0x062f('0x22'),_0x5ec273,_0x062f('0x20'),JSON[_0x062f('0x23')](_0x57c190));if(_0x57c190[_0x062f('0x24')]){if(_0x57c190['error'][_0x062f('0x25')]===0x1f4){logger['error'](_0x062f('0x1f'),_0x5ec273,_0x57c190[_0x062f('0x24')][_0x062f('0x26')]);return _0x50399a(_0x57c190['error'][_0x062f('0x26')]);}logger[_0x062f('0x24')](_0x062f('0x1f'),_0x5ec273,_0x57c190[_0x062f('0x24')][_0x062f('0x26')]);return _0x5dd6bc(_0x57c190[_0x062f('0x24')][_0x062f('0x26')]);}else{logger[_0x062f('0x27')](_0x062f('0x1f'),_0x5ec273,_0x062f('0x20'));_0x5dd6bc(_0x57c190[_0x062f('0x28')][_0x062f('0x26')]);}})[_0x062f('0x29')](function(_0x5733c9){logger['error'](_0x062f('0x1f'),_0x5ec273,_0x5733c9);_0x50399a(_0x5733c9);});});}function respondWithStatusCode(_0xf61c11,_0x406234){_0x406234=_0x406234||0xcc;return function(_0x14f1f1){if(_0x14f1f1){return _0xf61c11[_0x062f('0x2a')](_0x406234);}return _0xf61c11[_0x062f('0x2b')](_0x406234)[_0x062f('0x2c')]();};}function respondWithResult(_0x52daba,_0x446a32){_0x446a32=_0x446a32||0xc8;return function(_0x3a4747){if(_0x3a4747){return _0x52daba[_0x062f('0x2b')](_0x446a32)[_0x062f('0x2d')](_0x3a4747);}};}function respondWithFilteredResult(_0x27c0c7,_0x4d1504){return function(_0x42fa9d){if(_0x42fa9d){var _0x36bf18=_0x42fa9d[_0x062f('0x2e')],_0x22ce8e=_0x4d1504['offset'],_0x35e4e2=_0x4d1504[_0x062f('0x2f')]+_0x4d1504[_0x062f('0x30')],_0x1c562d;if(_0x35e4e2>=_0x36bf18){_0x35e4e2=_0x36bf18;_0x1c562d=0xc8;}else{_0x1c562d=0xce;}_0x27c0c7[_0x062f('0x2b')](_0x1c562d);return _0x27c0c7[_0x062f('0x31')]('Content-Range',_0x22ce8e+'-'+_0x35e4e2+'/'+_0x36bf18)[_0x062f('0x2d')](_0x42fa9d);}return null;};}function patchUpdates(_0x4feb0f){return function(_0x421d04){try{jsonpatch[_0x062f('0x32')](_0x421d04,_0x4feb0f,!![]);}catch(_0x4c63a6){return BPromise[_0x062f('0x33')](_0x4c63a6);}return _0x421d04[_0x062f('0x34')]();};}function saveUpdates(_0x56d148,_0x42e565){return function(_0x15bbef){if(_0x15bbef){return _0x15bbef[_0x062f('0x35')](_0x56d148)['then'](function(_0xdd8a36){return _0xdd8a36;});}return null;};}function removeEntity(_0x5c907e,_0x2a9a9f){return function(_0x1e40f9){if(_0x1e40f9){return _0x1e40f9[_0x062f('0x36')]()['then'](function(){_0x5c907e['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xb966d0,_0x531bb6){return function(_0x6f04f5){if(!_0x6f04f5){_0xb966d0[_0x062f('0x2a')](0x194);}return _0x6f04f5;};}function handleError(_0x345566,_0x10d489){_0x10d489=_0x10d489||0x1f4;return function(_0x2e15ee){logger['error'](_0x2e15ee[_0x062f('0x37')]);if(_0x2e15ee[_0x062f('0x38')]){delete _0x2e15ee[_0x062f('0x38')];}_0x345566[_0x062f('0x2b')](_0x10d489)[_0x062f('0x39')](_0x2e15ee);};}exports[_0x062f('0x3a')]=function(_0x59179a,_0x56d388){var _0x501965={},_0x49768b={},_0x27f055={'count':0x0,'rows':[]};var _0x1fc0a9=_[_0x062f('0x3b')](db['ServicenowConfiguration'][_0x062f('0x3c')],function(_0x53a496){return{'name':_0x53a496[_0x062f('0x3d')],'type':_0x53a496['type']['key']};});_0x49768b['model']=_[_0x062f('0x3b')](_0x1fc0a9,_0x062f('0x38'));_0x49768b['query']=_['keys'](_0x59179a[_0x062f('0x3e')]);_0x49768b[_0x062f('0x3f')]=_[_0x062f('0x40')](_0x49768b[_0x062f('0x41')],_0x49768b['query']);_0x501965[_0x062f('0x42')]=_[_0x062f('0x40')](_0x49768b[_0x062f('0x41')],qs[_0x062f('0x43')](_0x59179a[_0x062f('0x3e')][_0x062f('0x43')]));_0x501965['attributes']=_0x501965[_0x062f('0x42')]['length']?_0x501965[_0x062f('0x42')]:_0x49768b['model'];if(!_0x59179a[_0x062f('0x3e')][_0x062f('0x44')](_0x062f('0x45'))){_0x501965['limit']=qs['limit'](_0x59179a['query'][_0x062f('0x30')]);_0x501965[_0x062f('0x2f')]=qs['offset'](_0x59179a[_0x062f('0x3e')][_0x062f('0x2f')]);}_0x501965[_0x062f('0x46')]=qs[_0x062f('0x47')](_0x59179a[_0x062f('0x3e')][_0x062f('0x47')]);_0x501965[_0x062f('0x48')]=qs[_0x062f('0x3f')](_[_0x062f('0x49')](_0x59179a[_0x062f('0x3e')],_0x49768b[_0x062f('0x3f')]));if(_0x59179a[_0x062f('0x3e')][_0x062f('0x4a')]){_0x501965[_0x062f('0x48')]=_[_0x062f('0x4b')](_0x501965[_0x062f('0x48')],{'$or':_[_0x062f('0x3b')](_0x1fc0a9,function(_0x54dccf){if(_0x54dccf['type']!==_0x062f('0x4c')){var _0x230d11={};_0x230d11[_0x54dccf[_0x062f('0x38')]]={'$like':'%'+_0x59179a[_0x062f('0x3e')][_0x062f('0x4a')]+'%'};return _0x230d11;}})});}_0x501965=_[_0x062f('0x4b')]({},_0x501965,_0x59179a[_0x062f('0x4d')]);var _0x1a6365={'where':_0x501965['where']};return db[_0x062f('0x4e')][_0x062f('0x2e')](_0x1a6365)['then'](function(_0x23f682){_0x27f055[_0x062f('0x2e')]=_0x23f682;if(_0x59179a[_0x062f('0x3e')][_0x062f('0x4f')]){_0x501965[_0x062f('0x50')]=[{'all':!![]}];}return db[_0x062f('0x4e')][_0x062f('0x51')](_0x501965);})[_0x062f('0x1e')](function(_0x23ee7a){_0x27f055[_0x062f('0x52')]=_0x23ee7a;return _0x27f055;})['then'](respondWithFilteredResult(_0x56d388,_0x501965))['catch'](handleError(_0x56d388,null));};exports[_0x062f('0x53')]=function(_0x2ee74c,_0x4fffad){var _0x56ecac={'raw':![],'where':{'id':_0x2ee74c[_0x062f('0x54')]['id']}},_0x1cc499={};_0x1cc499[_0x062f('0x41')]=_['keys'](db[_0x062f('0x4e')][_0x062f('0x3c')]);_0x1cc499[_0x062f('0x3e')]=_['keys'](_0x2ee74c[_0x062f('0x3e')]);_0x1cc499[_0x062f('0x3f')]=_['intersection'](_0x1cc499[_0x062f('0x41')],_0x1cc499['query']);_0x56ecac['attributes']=_[_0x062f('0x40')](_0x1cc499['model'],qs[_0x062f('0x43')](_0x2ee74c[_0x062f('0x3e')][_0x062f('0x43')]));_0x56ecac[_0x062f('0x42')]=_0x56ecac[_0x062f('0x42')][_0x062f('0x55')]?_0x56ecac[_0x062f('0x42')]:_0x1cc499[_0x062f('0x41')];if(_0x2ee74c[_0x062f('0x3e')]['includeAll']){_0x56ecac['include']=[{'all':!![]}];}_0x56ecac=_[_0x062f('0x4b')]({},_0x56ecac,_0x2ee74c[_0x062f('0x4d')]);return db['ServicenowConfiguration'][_0x062f('0x56')](_0x56ecac)[_0x062f('0x1e')](handleEntityNotFound(_0x4fffad,null))[_0x062f('0x1e')](respondWithResult(_0x4fffad,null))['catch'](handleError(_0x4fffad,null));};exports['create']=function(_0x2ef330,_0x22b348){return db[_0x062f('0x4e')][_0x062f('0x57')](_0x2ef330['body'],{})[_0x062f('0x1e')](respondWithResult(_0x22b348,0xc9))[_0x062f('0x29')](handleError(_0x22b348,null));};exports[_0x062f('0x35')]=function(_0x1f5872,_0x39b85c){if(_0x1f5872[_0x062f('0x58')]['id']){delete _0x1f5872['body']['id'];}return db[_0x062f('0x4e')][_0x062f('0x56')]({'where':{'id':_0x1f5872[_0x062f('0x54')]['id']}})['then'](handleEntityNotFound(_0x39b85c,null))[_0x062f('0x1e')](saveUpdates(_0x1f5872['body'],null))[_0x062f('0x1e')](respondWithResult(_0x39b85c,null))[_0x062f('0x29')](handleError(_0x39b85c,null));};exports[_0x062f('0x36')]=function(_0x84a977,_0x3bcd88){return db['ServicenowConfiguration'][_0x062f('0x56')]({'where':{'id':_0x84a977[_0x062f('0x54')]['id']}})[_0x062f('0x1e')](handleEntityNotFound(_0x3bcd88,null))['then'](removeEntity(_0x3bcd88,null))[_0x062f('0x29')](handleError(_0x3bcd88,null));};exports['getFields']=function(_0x454543,_0x37e89c,_0x334ae8){var _0x44ea81={};var _0x4a20da={};var _0x2dc9b3;var _0x252486;return db[_0x062f('0x4e')][_0x062f('0x59')]({'where':{'id':_0x454543['params']['id']}})[_0x062f('0x1e')](handleEntityNotFound(_0x37e89c,null))['then'](function(_0x346d46){if(_0x346d46){_0x2dc9b3=_0x346d46;_0x4a20da[_0x062f('0x41')]=_[_0x062f('0x5a')](db[_0x062f('0x5b')][_0x062f('0x3c')]);_0x4a20da[_0x062f('0x3e')]=_[_0x062f('0x5a')](_0x454543[_0x062f('0x3e')]);_0x4a20da[_0x062f('0x3f')]=_[_0x062f('0x40')](_0x4a20da[_0x062f('0x41')],_0x4a20da[_0x062f('0x3e')]);_0x44ea81[_0x062f('0x42')]=_[_0x062f('0x40')](_0x4a20da['model'],qs['fields'](_0x454543[_0x062f('0x3e')][_0x062f('0x43')]));_0x44ea81[_0x062f('0x42')]=_0x44ea81[_0x062f('0x42')][_0x062f('0x55')]?_0x44ea81[_0x062f('0x42')]:_0x4a20da[_0x062f('0x41')];_0x44ea81[_0x062f('0x46')]=qs[_0x062f('0x47')](_0x454543[_0x062f('0x3e')][_0x062f('0x47')]);_0x44ea81[_0x062f('0x48')]=qs['filters'](_[_0x062f('0x49')](_0x454543[_0x062f('0x3e')],_0x4a20da[_0x062f('0x3f')]));if(_0x454543[_0x062f('0x3e')][_0x062f('0x4a')]){_0x44ea81[_0x062f('0x48')]=_[_0x062f('0x4b')](_0x44ea81['where'],{'$or':_[_0x062f('0x3b')](_0x44ea81[_0x062f('0x42')],function(_0x1b280e){var _0x1b5911={};_0x1b5911[_0x1b280e]={'$like':'%'+_0x454543[_0x062f('0x3e')]['filter']+'%'};return _0x1b5911;})});}_0x44ea81=_[_0x062f('0x4b')]({},_0x44ea81,_0x454543[_0x062f('0x4d')]);return _0x2dc9b3[_0x062f('0x5c')](_0x44ea81);}})['then'](function(_0x17076c){if(_0x17076c){_0x252486=_0x17076c[_0x062f('0x55')];if(!_0x454543[_0x062f('0x3e')][_0x062f('0x44')](_0x062f('0x45'))){_0x44ea81[_0x062f('0x30')]=qs[_0x062f('0x30')](_0x454543['query'][_0x062f('0x30')]);_0x44ea81[_0x062f('0x2f')]=qs['offset'](_0x454543['query'][_0x062f('0x2f')]);}return _0x2dc9b3[_0x062f('0x5c')](_0x44ea81);}})[_0x062f('0x1e')](function(_0x56edae){if(_0x56edae){return _0x56edae?{'count':_0x252486,'rows':_0x56edae}:null;}})[_0x062f('0x1e')](respondWithResult(_0x37e89c,null))[_0x062f('0x29')](handleError(_0x37e89c,null));};exports[_0x062f('0x5d')]=function(_0x3d1aee,_0x31f45d,_0x156720){var _0x41379d={};var _0x4e9116={};var _0x57b478;var _0x5e764a;return db[_0x062f('0x4e')]['findOne']({'where':{'id':_0x3d1aee[_0x062f('0x54')]['id']}})[_0x062f('0x1e')](handleEntityNotFound(_0x31f45d,null))[_0x062f('0x1e')](function(_0x51ca8b){if(_0x51ca8b){_0x57b478=_0x51ca8b;_0x4e9116[_0x062f('0x41')]=_['keys'](db[_0x062f('0x5b')][_0x062f('0x3c')]);_0x4e9116['query']=_[_0x062f('0x5a')](_0x3d1aee[_0x062f('0x3e')]);_0x4e9116['filters']=_[_0x062f('0x40')](_0x4e9116[_0x062f('0x41')],_0x4e9116[_0x062f('0x3e')]);_0x41379d[_0x062f('0x42')]=_[_0x062f('0x40')](_0x4e9116[_0x062f('0x41')],qs['fields'](_0x3d1aee[_0x062f('0x3e')]['fields']));_0x41379d['attributes']=_0x41379d[_0x062f('0x42')][_0x062f('0x55')]?_0x41379d[_0x062f('0x42')]:_0x4e9116[_0x062f('0x41')];_0x41379d[_0x062f('0x46')]=qs[_0x062f('0x47')](_0x3d1aee['query'][_0x062f('0x47')]);_0x41379d['where']=qs['filters'](_[_0x062f('0x49')](_0x3d1aee[_0x062f('0x3e')],_0x4e9116[_0x062f('0x3f')]));if(_0x3d1aee['query'][_0x062f('0x4a')]){_0x41379d[_0x062f('0x48')]=_[_0x062f('0x4b')](_0x41379d[_0x062f('0x48')],{'$or':_[_0x062f('0x3b')](_0x41379d[_0x062f('0x42')],function(_0x4f6aaf){var _0x16693e={};_0x16693e[_0x4f6aaf]={'$like':'%'+_0x3d1aee[_0x062f('0x3e')][_0x062f('0x4a')]+'%'};return _0x16693e;})});}_0x41379d=_['merge']({},_0x41379d,_0x3d1aee[_0x062f('0x4d')]);return _0x57b478[_0x062f('0x5d')](_0x41379d);}})[_0x062f('0x1e')](function(_0x3e8777){if(_0x3e8777){_0x5e764a=_0x3e8777['length'];if(!_0x3d1aee[_0x062f('0x3e')][_0x062f('0x44')](_0x062f('0x45'))){_0x41379d[_0x062f('0x30')]=qs['limit'](_0x3d1aee['query'][_0x062f('0x30')]);_0x41379d[_0x062f('0x2f')]=qs[_0x062f('0x2f')](_0x3d1aee[_0x062f('0x3e')][_0x062f('0x2f')]);}return _0x57b478['getSubjects'](_0x41379d);}})['then'](function(_0x529d8f){if(_0x529d8f){return _0x529d8f?{'count':_0x5e764a,'rows':_0x529d8f}:null;}})[_0x062f('0x1e')](respondWithResult(_0x31f45d,null))[_0x062f('0x29')](handleError(_0x31f45d,null));};exports[_0x062f('0x5e')]=function(_0x2da0e5,_0x18a72c,_0x300989){var _0x41d626={};var _0x43d3ad={};var _0x18cc52;var _0x556ab5;return db[_0x062f('0x4e')][_0x062f('0x59')]({'where':{'id':_0x2da0e5['params']['id']}})['then'](handleEntityNotFound(_0x18a72c,null))[_0x062f('0x1e')](function(_0x1c98d8){if(_0x1c98d8){_0x18cc52=_0x1c98d8;_0x43d3ad[_0x062f('0x41')]=_['keys'](db[_0x062f('0x5b')][_0x062f('0x3c')]);_0x43d3ad[_0x062f('0x3e')]=_['keys'](_0x2da0e5[_0x062f('0x3e')]);_0x43d3ad[_0x062f('0x3f')]=_[_0x062f('0x40')](_0x43d3ad[_0x062f('0x41')],_0x43d3ad[_0x062f('0x3e')]);_0x41d626['attributes']=_[_0x062f('0x40')](_0x43d3ad[_0x062f('0x41')],qs['fields'](_0x2da0e5['query'][_0x062f('0x43')]));_0x41d626['attributes']=_0x41d626['attributes'][_0x062f('0x55')]?_0x41d626[_0x062f('0x42')]:_0x43d3ad['model'];_0x41d626[_0x062f('0x46')]=qs[_0x062f('0x47')](_0x2da0e5[_0x062f('0x3e')][_0x062f('0x47')]);_0x41d626[_0x062f('0x48')]=qs['filters'](_['pick'](_0x2da0e5[_0x062f('0x3e')],_0x43d3ad['filters']));if(_0x2da0e5[_0x062f('0x3e')][_0x062f('0x4a')]){_0x41d626[_0x062f('0x48')]=_[_0x062f('0x4b')](_0x41d626['where'],{'$or':_[_0x062f('0x3b')](_0x41d626['attributes'],function(_0x189789){var _0x3cf090={};_0x3cf090[_0x189789]={'$like':'%'+_0x2da0e5[_0x062f('0x3e')][_0x062f('0x4a')]+'%'};return _0x3cf090;})});}_0x41d626=_[_0x062f('0x4b')]({},_0x41d626,_0x2da0e5['options']);return _0x18cc52['getDescriptions'](_0x41d626);}})[_0x062f('0x1e')](function(_0xd02f36){if(_0xd02f36){_0x556ab5=_0xd02f36[_0x062f('0x55')];if(!_0x2da0e5['query'][_0x062f('0x44')](_0x062f('0x45'))){_0x41d626[_0x062f('0x30')]=qs[_0x062f('0x30')](_0x2da0e5[_0x062f('0x3e')][_0x062f('0x30')]);_0x41d626[_0x062f('0x2f')]=qs[_0x062f('0x2f')](_0x2da0e5[_0x062f('0x3e')]['offset']);}return _0x18cc52[_0x062f('0x5e')](_0x41d626);}})['then'](function(_0x1a787f){if(_0x1a787f){return _0x1a787f?{'count':_0x556ab5,'rows':_0x1a787f}:null;}})['then'](respondWithResult(_0x18a72c,null))['catch'](handleError(_0x18a72c,null));};