Built motion from commit 936e8062.|2.5.33
[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 _0x6b3b=['hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','options','includeAll','findAll','rows','catch','show','include','merge','find','body','params','getFields','findOne','ServicenowField','map','getSubjects','getDescriptions','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../mysqldb','status','json','offset','undefined','limit','count','apply','reject','save','then','destroy','end','sendStatus','error','stack','name','send','ServicenowConfiguration','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length'];(function(_0x19e35c,_0x29cd1e){var _0x3e1fe8=function(_0x17258b){while(--_0x17258b){_0x19e35c['push'](_0x19e35c['shift']());}};_0x3e1fe8(++_0x29cd1e);}(_0x6b3b,0x6a));var _0xb6b3=function(_0x48863d,_0xb57402){_0x48863d=_0x48863d-0x0;var _0x16c8f1=_0x6b3b[_0x48863d];return _0x16c8f1;};'use strict';var emlformat=require(_0xb6b3('0x0'));var rimraf=require(_0xb6b3('0x1'));var zipdir=require(_0xb6b3('0x2'));var jsonpatch=require(_0xb6b3('0x3'));var rp=require('request-promise');var moment=require(_0xb6b3('0x4'));var BPromise=require(_0xb6b3('0x5'));var Mustache=require(_0xb6b3('0x6'));var util=require(_0xb6b3('0x7'));var path=require(_0xb6b3('0x8'));var sox=require('sox');var csv=require(_0xb6b3('0x9'));var ejs=require(_0xb6b3('0xa'));var fs=require('fs');var fs_extra=require(_0xb6b3('0xb'));var _=require(_0xb6b3('0xc'));var squel=require(_0xb6b3('0xd'));var crypto=require(_0xb6b3('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xb6b3('0xf'));var toCsv=require(_0xb6b3('0x9'));var querystring=require(_0xb6b3('0x10'));var Papa=require(_0xb6b3('0x11'));var Redis=require(_0xb6b3('0x12'));var authService=require(_0xb6b3('0x13'));var qs=require(_0xb6b3('0x14'));var as=require(_0xb6b3('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb6b3('0x16'))(_0xb6b3('0x17'));var utils=require('../../config/utils');var config=require(_0xb6b3('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0xb6b3('0x19'))['db'];function respondWithStatusCode(_0x30223c,_0x11980b){_0x11980b=_0x11980b||0xcc;return function(_0x734aba){if(_0x734aba){return _0x30223c['sendStatus'](_0x11980b);}return _0x30223c['status'](_0x11980b)['end']();};}function respondWithResult(_0x3b7834,_0x370a4b){_0x370a4b=_0x370a4b||0xc8;return function(_0x7b03e5){if(_0x7b03e5){return _0x3b7834[_0xb6b3('0x1a')](_0x370a4b)[_0xb6b3('0x1b')](_0x7b03e5);}};}function respondWithFilteredResult(_0x4a7f72,_0x362f47){return function(_0x37231d){if(_0x37231d){var _0x337ab6=typeof _0x362f47[_0xb6b3('0x1c')]===_0xb6b3('0x1d')&&typeof _0x362f47[_0xb6b3('0x1e')]===_0xb6b3('0x1d');var _0x3e633f=_0x37231d['count'];var _0x279542=_0x337ab6?0x0:_0x362f47['offset'];var _0x153682=_0x337ab6?_0x37231d[_0xb6b3('0x1f')]:_0x362f47[_0xb6b3('0x1c')]+_0x362f47[_0xb6b3('0x1e')];var _0x2b9879;if(_0x153682>=_0x3e633f){_0x153682=_0x3e633f;_0x2b9879=0xc8;}else{_0x2b9879=0xce;}_0x4a7f72[_0xb6b3('0x1a')](_0x2b9879);return _0x4a7f72['set']('Content-Range',_0x279542+'-'+_0x153682+'/'+_0x3e633f)[_0xb6b3('0x1b')](_0x37231d);}return null;};}function patchUpdates(_0x203a62){return function(_0x383bfc){try{jsonpatch[_0xb6b3('0x20')](_0x383bfc,_0x203a62,!![]);}catch(_0x30a80c){return BPromise[_0xb6b3('0x21')](_0x30a80c);}return _0x383bfc[_0xb6b3('0x22')]();};}function saveUpdates(_0x49a0ad,_0x49dcc3){return function(_0x324290){if(_0x324290){return _0x324290['update'](_0x49a0ad)[_0xb6b3('0x23')](function(_0x4972fe){return _0x4972fe;});}return null;};}function removeEntity(_0x58de64,_0x5b55ae){return function(_0x53345c){if(_0x53345c){return _0x53345c[_0xb6b3('0x24')]()[_0xb6b3('0x23')](function(){_0x58de64[_0xb6b3('0x1a')](0xcc)[_0xb6b3('0x25')]();});}};}function handleEntityNotFound(_0x2cf2df,_0x184db3){return function(_0x5c989f){if(!_0x5c989f){_0x2cf2df[_0xb6b3('0x26')](0x194);}return _0x5c989f;};}function handleError(_0x1a58fc,_0x2b727e){_0x2b727e=_0x2b727e||0x1f4;return function(_0x3525cc){logger[_0xb6b3('0x27')](_0x3525cc[_0xb6b3('0x28')]);if(_0x3525cc[_0xb6b3('0x29')]){delete _0x3525cc[_0xb6b3('0x29')];}_0x1a58fc[_0xb6b3('0x1a')](_0x2b727e)[_0xb6b3('0x2a')](_0x3525cc);};}exports['index']=function(_0x2006a9,_0x41be54){var _0xf047c4={},_0x380f4d={},_0x577c54={'count':0x0,'rows':[]};var _0x266887=_['map'](db[_0xb6b3('0x2b')][_0xb6b3('0x2c')],function(_0x5454af){return{'name':_0x5454af[_0xb6b3('0x2d')],'type':_0x5454af[_0xb6b3('0x2e')][_0xb6b3('0x2f')]};});_0x380f4d[_0xb6b3('0x30')]=_['map'](_0x266887,_0xb6b3('0x29'));_0x380f4d['query']=_[_0xb6b3('0x31')](_0x2006a9[_0xb6b3('0x32')]);_0x380f4d[_0xb6b3('0x33')]=_[_0xb6b3('0x34')](_0x380f4d[_0xb6b3('0x30')],_0x380f4d[_0xb6b3('0x32')]);_0xf047c4[_0xb6b3('0x35')]=_[_0xb6b3('0x34')](_0x380f4d[_0xb6b3('0x30')],qs[_0xb6b3('0x36')](_0x2006a9[_0xb6b3('0x32')][_0xb6b3('0x36')]));_0xf047c4[_0xb6b3('0x35')]=_0xf047c4[_0xb6b3('0x35')][_0xb6b3('0x37')]?_0xf047c4[_0xb6b3('0x35')]:_0x380f4d['model'];if(!_0x2006a9[_0xb6b3('0x32')][_0xb6b3('0x38')](_0xb6b3('0x39'))){_0xf047c4[_0xb6b3('0x1e')]=qs[_0xb6b3('0x1e')](_0x2006a9[_0xb6b3('0x32')][_0xb6b3('0x1e')]);_0xf047c4[_0xb6b3('0x1c')]=qs[_0xb6b3('0x1c')](_0x2006a9['query']['offset']);}_0xf047c4[_0xb6b3('0x3a')]=qs[_0xb6b3('0x3b')](_0x2006a9['query'][_0xb6b3('0x3b')]);_0xf047c4['where']=qs[_0xb6b3('0x33')](_[_0xb6b3('0x3c')](_0x2006a9['query'],_0x380f4d[_0xb6b3('0x33')]),_0x266887);if(_0x2006a9['query'][_0xb6b3('0x3d')]){_0xf047c4['where']=_['merge'](_0xf047c4[_0xb6b3('0x3e')],{'$or':_['map'](_0x266887,function(_0x3fbbba){if(_0x3fbbba['type']!==_0xb6b3('0x3f')){var _0x43b469={};_0x43b469[_0x3fbbba[_0xb6b3('0x29')]]={'$like':'%'+_0x2006a9['query'][_0xb6b3('0x3d')]+'%'};return _0x43b469;}})});}_0xf047c4=_['merge']({},_0xf047c4,_0x2006a9[_0xb6b3('0x40')]);var _0x2589f8={'where':_0xf047c4[_0xb6b3('0x3e')]};return db['ServicenowConfiguration'][_0xb6b3('0x1f')](_0x2589f8)['then'](function(_0x5e71c6){_0x577c54[_0xb6b3('0x1f')]=_0x5e71c6;if(_0x2006a9[_0xb6b3('0x32')][_0xb6b3('0x41')]){_0xf047c4['include']=[{'all':!![]}];}return db[_0xb6b3('0x2b')][_0xb6b3('0x42')](_0xf047c4);})[_0xb6b3('0x23')](function(_0x35872a){_0x577c54[_0xb6b3('0x43')]=_0x35872a;return _0x577c54;})[_0xb6b3('0x23')](respondWithFilteredResult(_0x41be54,_0xf047c4))[_0xb6b3('0x44')](handleError(_0x41be54,null));};exports[_0xb6b3('0x45')]=function(_0x3f886f,_0x434a8a){var _0x36a1c1={'raw':![],'where':{'id':_0x3f886f['params']['id']}},_0x5a4b8f={};_0x5a4b8f['model']=_[_0xb6b3('0x31')](db[_0xb6b3('0x2b')][_0xb6b3('0x2c')]);_0x5a4b8f['query']=_[_0xb6b3('0x31')](_0x3f886f['query']);_0x5a4b8f[_0xb6b3('0x33')]=_[_0xb6b3('0x34')](_0x5a4b8f[_0xb6b3('0x30')],_0x5a4b8f[_0xb6b3('0x32')]);_0x36a1c1[_0xb6b3('0x35')]=_[_0xb6b3('0x34')](_0x5a4b8f[_0xb6b3('0x30')],qs[_0xb6b3('0x36')](_0x3f886f[_0xb6b3('0x32')][_0xb6b3('0x36')]));_0x36a1c1[_0xb6b3('0x35')]=_0x36a1c1[_0xb6b3('0x35')][_0xb6b3('0x37')]?_0x36a1c1[_0xb6b3('0x35')]:_0x5a4b8f['model'];if(_0x3f886f['query'][_0xb6b3('0x41')]){_0x36a1c1[_0xb6b3('0x46')]=[{'all':!![]}];}_0x36a1c1=_[_0xb6b3('0x47')]({},_0x36a1c1,_0x3f886f[_0xb6b3('0x40')]);return db['ServicenowConfiguration'][_0xb6b3('0x48')](_0x36a1c1)[_0xb6b3('0x23')](handleEntityNotFound(_0x434a8a,null))[_0xb6b3('0x23')](respondWithResult(_0x434a8a,null))[_0xb6b3('0x44')](handleError(_0x434a8a,null));};exports['create']=function(_0x38de03,_0x330ad5){return db[_0xb6b3('0x2b')]['create'](_0x38de03[_0xb6b3('0x49')],{})['then'](respondWithResult(_0x330ad5,0xc9))[_0xb6b3('0x44')](handleError(_0x330ad5,null));};exports['update']=function(_0x386879,_0x137a73){if(_0x386879[_0xb6b3('0x49')]['id']){delete _0x386879['body']['id'];}return db[_0xb6b3('0x2b')][_0xb6b3('0x48')]({'where':{'id':_0x386879[_0xb6b3('0x4a')]['id']}})[_0xb6b3('0x23')](handleEntityNotFound(_0x137a73,null))[_0xb6b3('0x23')](saveUpdates(_0x386879[_0xb6b3('0x49')],null))[_0xb6b3('0x23')](respondWithResult(_0x137a73,null))['catch'](handleError(_0x137a73,null));};exports[_0xb6b3('0x24')]=function(_0x6cfbb7,_0x27cf0c){return db['ServicenowConfiguration'][_0xb6b3('0x48')]({'where':{'id':_0x6cfbb7[_0xb6b3('0x4a')]['id']}})[_0xb6b3('0x23')](handleEntityNotFound(_0x27cf0c,null))['then'](removeEntity(_0x27cf0c,null))['catch'](handleError(_0x27cf0c,null));};exports[_0xb6b3('0x4b')]=function(_0x405070,_0x57c907,_0x3def65){var _0x3e16ab={};var _0x525786={};var _0x5992d2;var _0x34fea5;return db[_0xb6b3('0x2b')][_0xb6b3('0x4c')]({'where':{'id':_0x405070[_0xb6b3('0x4a')]['id']}})[_0xb6b3('0x23')](handleEntityNotFound(_0x57c907,null))[_0xb6b3('0x23')](function(_0x5e3d57){if(_0x5e3d57){_0x5992d2=_0x5e3d57;_0x525786[_0xb6b3('0x30')]=_[_0xb6b3('0x31')](db[_0xb6b3('0x4d')]['rawAttributes']);_0x525786[_0xb6b3('0x32')]=_['keys'](_0x405070['query']);_0x525786['filters']=_[_0xb6b3('0x34')](_0x525786[_0xb6b3('0x30')],_0x525786[_0xb6b3('0x32')]);_0x3e16ab[_0xb6b3('0x35')]=_[_0xb6b3('0x34')](_0x525786['model'],qs[_0xb6b3('0x36')](_0x405070[_0xb6b3('0x32')]['fields']));_0x3e16ab[_0xb6b3('0x35')]=_0x3e16ab[_0xb6b3('0x35')][_0xb6b3('0x37')]?_0x3e16ab[_0xb6b3('0x35')]:_0x525786[_0xb6b3('0x30')];_0x3e16ab[_0xb6b3('0x3a')]=qs[_0xb6b3('0x3b')](_0x405070['query'][_0xb6b3('0x3b')]);_0x3e16ab['where']=qs[_0xb6b3('0x33')](_[_0xb6b3('0x3c')](_0x405070[_0xb6b3('0x32')],_0x525786[_0xb6b3('0x33')]));if(_0x405070[_0xb6b3('0x32')][_0xb6b3('0x3d')]){_0x3e16ab[_0xb6b3('0x3e')]=_[_0xb6b3('0x47')](_0x3e16ab[_0xb6b3('0x3e')],{'$or':_['map'](_0x3e16ab['attributes'],function(_0xb35c27){var _0x103b68={};_0x103b68[_0xb35c27]={'$like':'%'+_0x405070['query'][_0xb6b3('0x3d')]+'%'};return _0x103b68;})});}_0x3e16ab=_[_0xb6b3('0x47')]({},_0x3e16ab,_0x405070[_0xb6b3('0x40')]);return _0x5992d2['getFields'](_0x3e16ab);}})[_0xb6b3('0x23')](function(_0x349b80){if(_0x349b80){_0x34fea5=_0x349b80[_0xb6b3('0x37')];if(!_0x405070[_0xb6b3('0x32')][_0xb6b3('0x38')](_0xb6b3('0x39'))){_0x3e16ab[_0xb6b3('0x1e')]=qs[_0xb6b3('0x1e')](_0x405070[_0xb6b3('0x32')][_0xb6b3('0x1e')]);_0x3e16ab['offset']=qs[_0xb6b3('0x1c')](_0x405070[_0xb6b3('0x32')][_0xb6b3('0x1c')]);}return _0x5992d2[_0xb6b3('0x4b')](_0x3e16ab);}})[_0xb6b3('0x23')](function(_0x53e947){if(_0x53e947){return _0x53e947?{'count':_0x34fea5,'rows':_0x53e947}:null;}})['then'](respondWithResult(_0x57c907,null))['catch'](handleError(_0x57c907,null));};exports['getSubjects']=function(_0x4ae900,_0x1375d4,_0x2e58d0){var _0x58a700={};var _0x55d3ba={};var _0x4ded38;var _0xdd64a9;return db[_0xb6b3('0x2b')][_0xb6b3('0x4c')]({'where':{'id':_0x4ae900[_0xb6b3('0x4a')]['id']}})[_0xb6b3('0x23')](handleEntityNotFound(_0x1375d4,null))[_0xb6b3('0x23')](function(_0x3f2df8){if(_0x3f2df8){_0x4ded38=_0x3f2df8;_0x55d3ba[_0xb6b3('0x30')]=_[_0xb6b3('0x31')](db['ServicenowField'][_0xb6b3('0x2c')]);_0x55d3ba[_0xb6b3('0x32')]=_[_0xb6b3('0x31')](_0x4ae900[_0xb6b3('0x32')]);_0x55d3ba[_0xb6b3('0x33')]=_['intersection'](_0x55d3ba['model'],_0x55d3ba[_0xb6b3('0x32')]);_0x58a700[_0xb6b3('0x35')]=_[_0xb6b3('0x34')](_0x55d3ba[_0xb6b3('0x30')],qs[_0xb6b3('0x36')](_0x4ae900['query'][_0xb6b3('0x36')]));_0x58a700['attributes']=_0x58a700[_0xb6b3('0x35')][_0xb6b3('0x37')]?_0x58a700['attributes']:_0x55d3ba['model'];_0x58a700['order']=qs[_0xb6b3('0x3b')](_0x4ae900[_0xb6b3('0x32')][_0xb6b3('0x3b')]);_0x58a700[_0xb6b3('0x3e')]=qs[_0xb6b3('0x33')](_[_0xb6b3('0x3c')](_0x4ae900['query'],_0x55d3ba['filters']));if(_0x4ae900['query']['filter']){_0x58a700[_0xb6b3('0x3e')]=_[_0xb6b3('0x47')](_0x58a700[_0xb6b3('0x3e')],{'$or':_[_0xb6b3('0x4e')](_0x58a700[_0xb6b3('0x35')],function(_0x229308){var _0x5ef21a={};_0x5ef21a[_0x229308]={'$like':'%'+_0x4ae900['query'][_0xb6b3('0x3d')]+'%'};return _0x5ef21a;})});}_0x58a700=_[_0xb6b3('0x47')]({},_0x58a700,_0x4ae900[_0xb6b3('0x40')]);return _0x4ded38[_0xb6b3('0x4f')](_0x58a700);}})[_0xb6b3('0x23')](function(_0x54b5fb){if(_0x54b5fb){_0xdd64a9=_0x54b5fb[_0xb6b3('0x37')];if(!_0x4ae900['query'][_0xb6b3('0x38')](_0xb6b3('0x39'))){_0x58a700[_0xb6b3('0x1e')]=qs[_0xb6b3('0x1e')](_0x4ae900['query'][_0xb6b3('0x1e')]);_0x58a700['offset']=qs[_0xb6b3('0x1c')](_0x4ae900[_0xb6b3('0x32')][_0xb6b3('0x1c')]);}return _0x4ded38['getSubjects'](_0x58a700);}})['then'](function(_0x342a5d){if(_0x342a5d){return _0x342a5d?{'count':_0xdd64a9,'rows':_0x342a5d}:null;}})[_0xb6b3('0x23')](respondWithResult(_0x1375d4,null))[_0xb6b3('0x44')](handleError(_0x1375d4,null));};exports[_0xb6b3('0x50')]=function(_0x471144,_0x44db6d,_0x1bf315){var _0xc0bfac={};var _0x166299={};var _0x39a1f3;var _0xd9b9e0;return db[_0xb6b3('0x2b')][_0xb6b3('0x4c')]({'where':{'id':_0x471144[_0xb6b3('0x4a')]['id']}})[_0xb6b3('0x23')](handleEntityNotFound(_0x44db6d,null))['then'](function(_0x457c36){if(_0x457c36){_0x39a1f3=_0x457c36;_0x166299[_0xb6b3('0x30')]=_[_0xb6b3('0x31')](db['ServicenowField']['rawAttributes']);_0x166299[_0xb6b3('0x32')]=_[_0xb6b3('0x31')](_0x471144[_0xb6b3('0x32')]);_0x166299[_0xb6b3('0x33')]=_[_0xb6b3('0x34')](_0x166299['model'],_0x166299[_0xb6b3('0x32')]);_0xc0bfac[_0xb6b3('0x35')]=_['intersection'](_0x166299[_0xb6b3('0x30')],qs[_0xb6b3('0x36')](_0x471144[_0xb6b3('0x32')][_0xb6b3('0x36')]));_0xc0bfac[_0xb6b3('0x35')]=_0xc0bfac['attributes'][_0xb6b3('0x37')]?_0xc0bfac[_0xb6b3('0x35')]:_0x166299['model'];_0xc0bfac[_0xb6b3('0x3a')]=qs[_0xb6b3('0x3b')](_0x471144['query']['sort']);_0xc0bfac[_0xb6b3('0x3e')]=qs[_0xb6b3('0x33')](_['pick'](_0x471144[_0xb6b3('0x32')],_0x166299[_0xb6b3('0x33')]));if(_0x471144['query'][_0xb6b3('0x3d')]){_0xc0bfac[_0xb6b3('0x3e')]=_[_0xb6b3('0x47')](_0xc0bfac[_0xb6b3('0x3e')],{'$or':_[_0xb6b3('0x4e')](_0xc0bfac['attributes'],function(_0x294870){var _0x36059b={};_0x36059b[_0x294870]={'$like':'%'+_0x471144[_0xb6b3('0x32')][_0xb6b3('0x3d')]+'%'};return _0x36059b;})});}_0xc0bfac=_[_0xb6b3('0x47')]({},_0xc0bfac,_0x471144[_0xb6b3('0x40')]);return _0x39a1f3['getDescriptions'](_0xc0bfac);}})['then'](function(_0x3e820d){if(_0x3e820d){_0xd9b9e0=_0x3e820d[_0xb6b3('0x37')];if(!_0x471144['query'][_0xb6b3('0x38')](_0xb6b3('0x39'))){_0xc0bfac[_0xb6b3('0x1e')]=qs[_0xb6b3('0x1e')](_0x471144[_0xb6b3('0x32')][_0xb6b3('0x1e')]);_0xc0bfac[_0xb6b3('0x1c')]=qs[_0xb6b3('0x1c')](_0x471144['query'][_0xb6b3('0x1c')]);}return _0x39a1f3[_0xb6b3('0x50')](_0xc0bfac);}})[_0xb6b3('0x23')](function(_0x3dd593){if(_0x3dd593){return _0x3dd593?{'count':_0xd9b9e0,'rows':_0x3dd593}:null;}})[_0xb6b3('0x23')](respondWithResult(_0x44db6d,null))[_0xb6b3('0x44')](handleError(_0x44db6d,null));};