Built motion from commit 5b761a7b.|2.5.36
[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 _0x56f4=['key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','where','VIRTUAL','filter','merge','options','includeAll','ServicenowConfiguration','findAll','params','rawAttributes','include','find','create','catch','body','getFields','findOne','ServicenowField','getSubjects','getDescriptions','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/license/util','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','map','fieldName','type'];(function(_0x39495b,_0x4d2d22){var _0x5b09ea=function(_0x1a2079){while(--_0x1a2079){_0x39495b['push'](_0x39495b['shift']());}};_0x5b09ea(++_0x4d2d22);}(_0x56f4,0x70));var _0x456f=function(_0x5e00e2,_0x889d6d){_0x5e00e2=_0x5e00e2-0x0;var _0x4114ba=_0x56f4[_0x5e00e2];return _0x4114ba;};'use strict';var emlformat=require(_0x456f('0x0'));var rimraf=require(_0x456f('0x1'));var zipdir=require(_0x456f('0x2'));var jsonpatch=require(_0x456f('0x3'));var rp=require('request-promise');var moment=require(_0x456f('0x4'));var BPromise=require(_0x456f('0x5'));var Mustache=require('mustache');var util=require(_0x456f('0x6'));var path=require('path');var sox=require(_0x456f('0x7'));var csv=require(_0x456f('0x8'));var ejs=require(_0x456f('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x456f('0xa'));var squel=require(_0x456f('0xb'));var crypto=require(_0x456f('0xc'));var jsforce=require(_0x456f('0xd'));var deskjs=require(_0x456f('0xe'));var toCsv=require(_0x456f('0x8'));var querystring=require(_0x456f('0xf'));var Papa=require(_0x456f('0x10'));var Redis=require('ioredis');var authService=require(_0x456f('0x11'));var qs=require(_0x456f('0x12'));var as=require(_0x456f('0x13'));var hardwareService=require(_0x456f('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x456f('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x456f('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x285b23,_0x1c1774){_0x1c1774=_0x1c1774||0xcc;return function(_0x39a385){if(_0x39a385){return _0x285b23[_0x456f('0x17')](_0x1c1774);}return _0x285b23[_0x456f('0x18')](_0x1c1774)['end']();};}function respondWithResult(_0x4b75b8,_0x55cf4b){_0x55cf4b=_0x55cf4b||0xc8;return function(_0xeb33d6){if(_0xeb33d6){return _0x4b75b8['status'](_0x55cf4b)[_0x456f('0x19')](_0xeb33d6);}};}function respondWithFilteredResult(_0x146ceb,_0x9b17cb){return function(_0x3aa730){if(_0x3aa730){var _0x5582d5=typeof _0x9b17cb[_0x456f('0x1a')]===_0x456f('0x1b')&&typeof _0x9b17cb['limit']===_0x456f('0x1b');var _0xce8291=_0x3aa730['count'];var _0x3bb235=_0x5582d5?0x0:_0x9b17cb[_0x456f('0x1a')];var _0xa0acd9=_0x5582d5?_0x3aa730[_0x456f('0x1c')]:_0x9b17cb[_0x456f('0x1a')]+_0x9b17cb[_0x456f('0x1d')];var _0x8148fb;if(_0xa0acd9>=_0xce8291){_0xa0acd9=_0xce8291;_0x8148fb=0xc8;}else{_0x8148fb=0xce;}_0x146ceb[_0x456f('0x18')](_0x8148fb);return _0x146ceb[_0x456f('0x1e')](_0x456f('0x1f'),_0x3bb235+'-'+_0xa0acd9+'/'+_0xce8291)[_0x456f('0x19')](_0x3aa730);}return null;};}function patchUpdates(_0x567295){return function(_0x5385e7){try{jsonpatch[_0x456f('0x20')](_0x5385e7,_0x567295,!![]);}catch(_0x3d3af2){return BPromise[_0x456f('0x21')](_0x3d3af2);}return _0x5385e7[_0x456f('0x22')]();};}function saveUpdates(_0x119e8f,_0x323bd9){return function(_0x4f0875){if(_0x4f0875){return _0x4f0875[_0x456f('0x23')](_0x119e8f)[_0x456f('0x24')](function(_0x53714d){return _0x53714d;});}return null;};}function removeEntity(_0x1c0392,_0x417e28){return function(_0x4bfc87){if(_0x4bfc87){return _0x4bfc87[_0x456f('0x25')]()[_0x456f('0x24')](function(){_0x1c0392[_0x456f('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3b14d2,_0x28961d){return function(_0xdd9041){if(!_0xdd9041){_0x3b14d2[_0x456f('0x17')](0x194);}return _0xdd9041;};}function handleError(_0x2963c9,_0x1b9237){_0x1b9237=_0x1b9237||0x1f4;return function(_0x3e8ec7){logger['error'](_0x3e8ec7[_0x456f('0x26')]);if(_0x3e8ec7[_0x456f('0x27')]){delete _0x3e8ec7[_0x456f('0x27')];}_0x2963c9[_0x456f('0x18')](_0x1b9237)[_0x456f('0x28')](_0x3e8ec7);};}exports['index']=function(_0x3e4264,_0x3dc4a5){var _0x2f4b0d={},_0x25c100={},_0x27e5c2={'count':0x0,'rows':[]};var _0x4b640f=_[_0x456f('0x29')](db['ServicenowConfiguration']['rawAttributes'],function(_0x5b9410){return{'name':_0x5b9410[_0x456f('0x2a')],'type':_0x5b9410[_0x456f('0x2b')][_0x456f('0x2c')]};});_0x25c100['model']=_[_0x456f('0x29')](_0x4b640f,_0x456f('0x27'));_0x25c100[_0x456f('0x2d')]=_[_0x456f('0x2e')](_0x3e4264[_0x456f('0x2d')]);_0x25c100[_0x456f('0x2f')]=_[_0x456f('0x30')](_0x25c100[_0x456f('0x31')],_0x25c100['query']);_0x2f4b0d[_0x456f('0x32')]=_[_0x456f('0x30')](_0x25c100[_0x456f('0x31')],qs[_0x456f('0x33')](_0x3e4264['query'][_0x456f('0x33')]));_0x2f4b0d[_0x456f('0x32')]=_0x2f4b0d[_0x456f('0x32')][_0x456f('0x34')]?_0x2f4b0d[_0x456f('0x32')]:_0x25c100[_0x456f('0x31')];if(!_0x3e4264[_0x456f('0x2d')][_0x456f('0x35')](_0x456f('0x36'))){_0x2f4b0d[_0x456f('0x1d')]=qs['limit'](_0x3e4264['query'][_0x456f('0x1d')]);_0x2f4b0d[_0x456f('0x1a')]=qs['offset'](_0x3e4264[_0x456f('0x2d')][_0x456f('0x1a')]);}_0x2f4b0d[_0x456f('0x37')]=qs[_0x456f('0x38')](_0x3e4264[_0x456f('0x2d')][_0x456f('0x38')]);_0x2f4b0d['where']=qs[_0x456f('0x2f')](_[_0x456f('0x39')](_0x3e4264[_0x456f('0x2d')],_0x25c100['filters']),_0x4b640f);if(_0x3e4264[_0x456f('0x2d')]['filter']){_0x2f4b0d[_0x456f('0x3a')]=_['merge'](_0x2f4b0d[_0x456f('0x3a')],{'$or':_[_0x456f('0x29')](_0x4b640f,function(_0x591c0c){if(_0x591c0c['type']!==_0x456f('0x3b')){var _0x52abb1={};_0x52abb1[_0x591c0c[_0x456f('0x27')]]={'$like':'%'+_0x3e4264['query'][_0x456f('0x3c')]+'%'};return _0x52abb1;}})});}_0x2f4b0d=_[_0x456f('0x3d')]({},_0x2f4b0d,_0x3e4264[_0x456f('0x3e')]);var _0x464d4f={'where':_0x2f4b0d[_0x456f('0x3a')]};return db['ServicenowConfiguration'][_0x456f('0x1c')](_0x464d4f)[_0x456f('0x24')](function(_0x58f373){_0x27e5c2[_0x456f('0x1c')]=_0x58f373;if(_0x3e4264[_0x456f('0x2d')][_0x456f('0x3f')]){_0x2f4b0d['include']=[{'all':!![]}];}return db[_0x456f('0x40')][_0x456f('0x41')](_0x2f4b0d);})['then'](function(_0x4b7258){_0x27e5c2['rows']=_0x4b7258;return _0x27e5c2;})['then'](respondWithFilteredResult(_0x3dc4a5,_0x2f4b0d))['catch'](handleError(_0x3dc4a5,null));};exports['show']=function(_0x13dd55,_0x3ca93f){var _0x5ac64d={'raw':![],'where':{'id':_0x13dd55[_0x456f('0x42')]['id']}},_0x357aca={};_0x357aca['model']=_[_0x456f('0x2e')](db[_0x456f('0x40')][_0x456f('0x43')]);_0x357aca['query']=_[_0x456f('0x2e')](_0x13dd55[_0x456f('0x2d')]);_0x357aca['filters']=_[_0x456f('0x30')](_0x357aca[_0x456f('0x31')],_0x357aca[_0x456f('0x2d')]);_0x5ac64d[_0x456f('0x32')]=_[_0x456f('0x30')](_0x357aca[_0x456f('0x31')],qs[_0x456f('0x33')](_0x13dd55[_0x456f('0x2d')][_0x456f('0x33')]));_0x5ac64d[_0x456f('0x32')]=_0x5ac64d[_0x456f('0x32')][_0x456f('0x34')]?_0x5ac64d[_0x456f('0x32')]:_0x357aca[_0x456f('0x31')];if(_0x13dd55[_0x456f('0x2d')]['includeAll']){_0x5ac64d[_0x456f('0x44')]=[{'all':!![]}];}_0x5ac64d=_[_0x456f('0x3d')]({},_0x5ac64d,_0x13dd55[_0x456f('0x3e')]);return db[_0x456f('0x40')][_0x456f('0x45')](_0x5ac64d)[_0x456f('0x24')](handleEntityNotFound(_0x3ca93f,null))[_0x456f('0x24')](respondWithResult(_0x3ca93f,null))['catch'](handleError(_0x3ca93f,null));};exports[_0x456f('0x46')]=function(_0x4a3fdb,_0x161e01){return db[_0x456f('0x40')][_0x456f('0x46')](_0x4a3fdb['body'],{})[_0x456f('0x24')](respondWithResult(_0x161e01,0xc9))[_0x456f('0x47')](handleError(_0x161e01,null));};exports[_0x456f('0x23')]=function(_0x32c72d,_0x4ff037){if(_0x32c72d['body']['id']){delete _0x32c72d[_0x456f('0x48')]['id'];}return db[_0x456f('0x40')][_0x456f('0x45')]({'where':{'id':_0x32c72d[_0x456f('0x42')]['id']}})[_0x456f('0x24')](handleEntityNotFound(_0x4ff037,null))[_0x456f('0x24')](saveUpdates(_0x32c72d[_0x456f('0x48')],null))[_0x456f('0x24')](respondWithResult(_0x4ff037,null))[_0x456f('0x47')](handleError(_0x4ff037,null));};exports['destroy']=function(_0x11deba,_0x1cc9aa){return db[_0x456f('0x40')][_0x456f('0x45')]({'where':{'id':_0x11deba['params']['id']}})[_0x456f('0x24')](handleEntityNotFound(_0x1cc9aa,null))[_0x456f('0x24')](removeEntity(_0x1cc9aa,null))['catch'](handleError(_0x1cc9aa,null));};exports[_0x456f('0x49')]=function(_0x3e2eac,_0x14c981,_0x870657){var _0x31468c={};var _0x592312={};var _0x22ed8a;var _0x569b52;return db[_0x456f('0x40')][_0x456f('0x4a')]({'where':{'id':_0x3e2eac[_0x456f('0x42')]['id']}})[_0x456f('0x24')](handleEntityNotFound(_0x14c981,null))[_0x456f('0x24')](function(_0x5a9f0d){if(_0x5a9f0d){_0x22ed8a=_0x5a9f0d;_0x592312[_0x456f('0x31')]=_['keys'](db[_0x456f('0x4b')][_0x456f('0x43')]);_0x592312[_0x456f('0x2d')]=_[_0x456f('0x2e')](_0x3e2eac[_0x456f('0x2d')]);_0x592312[_0x456f('0x2f')]=_[_0x456f('0x30')](_0x592312['model'],_0x592312['query']);_0x31468c[_0x456f('0x32')]=_['intersection'](_0x592312[_0x456f('0x31')],qs[_0x456f('0x33')](_0x3e2eac['query'][_0x456f('0x33')]));_0x31468c[_0x456f('0x32')]=_0x31468c[_0x456f('0x32')][_0x456f('0x34')]?_0x31468c[_0x456f('0x32')]:_0x592312['model'];_0x31468c[_0x456f('0x37')]=qs[_0x456f('0x38')](_0x3e2eac[_0x456f('0x2d')][_0x456f('0x38')]);_0x31468c[_0x456f('0x3a')]=qs[_0x456f('0x2f')](_['pick'](_0x3e2eac['query'],_0x592312['filters']));if(_0x3e2eac[_0x456f('0x2d')][_0x456f('0x3c')]){_0x31468c[_0x456f('0x3a')]=_[_0x456f('0x3d')](_0x31468c['where'],{'$or':_[_0x456f('0x29')](_0x31468c['attributes'],function(_0x5726fc){var _0x55f927={};_0x55f927[_0x5726fc]={'$like':'%'+_0x3e2eac[_0x456f('0x2d')][_0x456f('0x3c')]+'%'};return _0x55f927;})});}_0x31468c=_[_0x456f('0x3d')]({},_0x31468c,_0x3e2eac['options']);return _0x22ed8a[_0x456f('0x49')](_0x31468c);}})[_0x456f('0x24')](function(_0x4166d4){if(_0x4166d4){_0x569b52=_0x4166d4[_0x456f('0x34')];if(!_0x3e2eac[_0x456f('0x2d')][_0x456f('0x35')](_0x456f('0x36'))){_0x31468c[_0x456f('0x1d')]=qs[_0x456f('0x1d')](_0x3e2eac[_0x456f('0x2d')]['limit']);_0x31468c[_0x456f('0x1a')]=qs[_0x456f('0x1a')](_0x3e2eac[_0x456f('0x2d')][_0x456f('0x1a')]);}return _0x22ed8a[_0x456f('0x49')](_0x31468c);}})[_0x456f('0x24')](function(_0x5723f3){if(_0x5723f3){return _0x5723f3?{'count':_0x569b52,'rows':_0x5723f3}:null;}})['then'](respondWithResult(_0x14c981,null))[_0x456f('0x47')](handleError(_0x14c981,null));};exports[_0x456f('0x4c')]=function(_0xac793,_0x5002ed,_0x39e28a){var _0x575ce8={};var _0x358c5c={};var _0x343621;var _0x327255;return db[_0x456f('0x40')][_0x456f('0x4a')]({'where':{'id':_0xac793[_0x456f('0x42')]['id']}})['then'](handleEntityNotFound(_0x5002ed,null))['then'](function(_0x1a09a5){if(_0x1a09a5){_0x343621=_0x1a09a5;_0x358c5c['model']=_['keys'](db[_0x456f('0x4b')]['rawAttributes']);_0x358c5c['query']=_[_0x456f('0x2e')](_0xac793['query']);_0x358c5c[_0x456f('0x2f')]=_[_0x456f('0x30')](_0x358c5c[_0x456f('0x31')],_0x358c5c[_0x456f('0x2d')]);_0x575ce8[_0x456f('0x32')]=_[_0x456f('0x30')](_0x358c5c[_0x456f('0x31')],qs['fields'](_0xac793[_0x456f('0x2d')][_0x456f('0x33')]));_0x575ce8[_0x456f('0x32')]=_0x575ce8[_0x456f('0x32')][_0x456f('0x34')]?_0x575ce8[_0x456f('0x32')]:_0x358c5c[_0x456f('0x31')];_0x575ce8['order']=qs[_0x456f('0x38')](_0xac793['query']['sort']);_0x575ce8['where']=qs['filters'](_[_0x456f('0x39')](_0xac793['query'],_0x358c5c[_0x456f('0x2f')]));if(_0xac793['query'][_0x456f('0x3c')]){_0x575ce8[_0x456f('0x3a')]=_[_0x456f('0x3d')](_0x575ce8['where'],{'$or':_['map'](_0x575ce8[_0x456f('0x32')],function(_0x307021){var _0x6fceb6={};_0x6fceb6[_0x307021]={'$like':'%'+_0xac793['query']['filter']+'%'};return _0x6fceb6;})});}_0x575ce8=_[_0x456f('0x3d')]({},_0x575ce8,_0xac793[_0x456f('0x3e')]);return _0x343621[_0x456f('0x4c')](_0x575ce8);}})[_0x456f('0x24')](function(_0x364433){if(_0x364433){_0x327255=_0x364433['length'];if(!_0xac793[_0x456f('0x2d')][_0x456f('0x35')](_0x456f('0x36'))){_0x575ce8[_0x456f('0x1d')]=qs[_0x456f('0x1d')](_0xac793[_0x456f('0x2d')][_0x456f('0x1d')]);_0x575ce8['offset']=qs[_0x456f('0x1a')](_0xac793[_0x456f('0x2d')][_0x456f('0x1a')]);}return _0x343621[_0x456f('0x4c')](_0x575ce8);}})[_0x456f('0x24')](function(_0x445798){if(_0x445798){return _0x445798?{'count':_0x327255,'rows':_0x445798}:null;}})[_0x456f('0x24')](respondWithResult(_0x5002ed,null))[_0x456f('0x47')](handleError(_0x5002ed,null));};exports[_0x456f('0x4d')]=function(_0x388070,_0x2d5240,_0x15b1e7){var _0xf5d99c={};var _0xaec829={};var _0xc0e6e3;var _0x1ad1ce;return db[_0x456f('0x40')][_0x456f('0x4a')]({'where':{'id':_0x388070[_0x456f('0x42')]['id']}})[_0x456f('0x24')](handleEntityNotFound(_0x2d5240,null))['then'](function(_0x1d5666){if(_0x1d5666){_0xc0e6e3=_0x1d5666;_0xaec829[_0x456f('0x31')]=_[_0x456f('0x2e')](db['ServicenowField']['rawAttributes']);_0xaec829[_0x456f('0x2d')]=_[_0x456f('0x2e')](_0x388070[_0x456f('0x2d')]);_0xaec829['filters']=_['intersection'](_0xaec829[_0x456f('0x31')],_0xaec829[_0x456f('0x2d')]);_0xf5d99c['attributes']=_[_0x456f('0x30')](_0xaec829['model'],qs[_0x456f('0x33')](_0x388070[_0x456f('0x2d')][_0x456f('0x33')]));_0xf5d99c['attributes']=_0xf5d99c['attributes'][_0x456f('0x34')]?_0xf5d99c['attributes']:_0xaec829[_0x456f('0x31')];_0xf5d99c[_0x456f('0x37')]=qs['sort'](_0x388070[_0x456f('0x2d')]['sort']);_0xf5d99c[_0x456f('0x3a')]=qs[_0x456f('0x2f')](_[_0x456f('0x39')](_0x388070[_0x456f('0x2d')],_0xaec829[_0x456f('0x2f')]));if(_0x388070[_0x456f('0x2d')]['filter']){_0xf5d99c[_0x456f('0x3a')]=_['merge'](_0xf5d99c[_0x456f('0x3a')],{'$or':_[_0x456f('0x29')](_0xf5d99c[_0x456f('0x32')],function(_0x4ea1da){var _0x343e89={};_0x343e89[_0x4ea1da]={'$like':'%'+_0x388070[_0x456f('0x2d')]['filter']+'%'};return _0x343e89;})});}_0xf5d99c=_['merge']({},_0xf5d99c,_0x388070['options']);return _0xc0e6e3['getDescriptions'](_0xf5d99c);}})[_0x456f('0x24')](function(_0x43c1ab){if(_0x43c1ab){_0x1ad1ce=_0x43c1ab[_0x456f('0x34')];if(!_0x388070[_0x456f('0x2d')]['hasOwnProperty'](_0x456f('0x36'))){_0xf5d99c[_0x456f('0x1d')]=qs['limit'](_0x388070[_0x456f('0x2d')][_0x456f('0x1d')]);_0xf5d99c[_0x456f('0x1a')]=qs[_0x456f('0x1a')](_0x388070[_0x456f('0x2d')][_0x456f('0x1a')]);}return _0xc0e6e3[_0x456f('0x4d')](_0xf5d99c);}})['then'](function(_0x5aa7eb){if(_0x5aa7eb){return _0x5aa7eb?{'count':_0x1ad1ce,'rows':_0x5aa7eb}:null;}})[_0x456f('0x24')](respondWithResult(_0x2d5240,null))[_0x456f('0x47')](handleError(_0x2d5240,null));};