0f8c74596e8badbfdc742ecf9c1dbd5eca2301c4
[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 _0xf03f=['name','send','index','ServicenowConfiguration','rawAttributes','fieldName','key','model','map','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filters','VIRTUAL','filter','merge','options','includeAll','include','rows','catch','show','params','keys','find','create','body','destroy','getFields','findOne','ServicenowField','order','getSubjects','getDescriptions','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','stack'];(function(_0x30c1dd,_0x23a13c){var _0x57dfaf=function(_0x43afa5){while(--_0x43afa5){_0x30c1dd['push'](_0x30c1dd['shift']());}};_0x57dfaf(++_0x23a13c);}(_0xf03f,0x1d7));var _0xff03=function(_0x40b66c,_0x578758){_0x40b66c=_0x40b66c-0x0;var _0x2fd22b=_0xf03f[_0x40b66c];return _0x2fd22b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xff03('0x0'));var zipdir=require(_0xff03('0x1'));var jsonpatch=require(_0xff03('0x2'));var rp=require(_0xff03('0x3'));var moment=require(_0xff03('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xff03('0x5'));var util=require(_0xff03('0x6'));var path=require(_0xff03('0x7'));var sox=require(_0xff03('0x8'));var csv=require(_0xff03('0x9'));var ejs=require(_0xff03('0xa'));var fs=require('fs');var fs_extra=require(_0xff03('0xb'));var _=require(_0xff03('0xc'));var squel=require(_0xff03('0xd'));var crypto=require('crypto');var jsforce=require(_0xff03('0xe'));var deskjs=require(_0xff03('0xf'));var toCsv=require(_0xff03('0x9'));var querystring=require(_0xff03('0x10'));var Papa=require(_0xff03('0x11'));var Redis=require(_0xff03('0x12'));var authService=require(_0xff03('0x13'));var qs=require(_0xff03('0x14'));var as=require(_0xff03('0x15'));var hardwareService=require(_0xff03('0x16'));var logger=require(_0xff03('0x17'))(_0xff03('0x18'));var utils=require(_0xff03('0x19'));var config=require(_0xff03('0x1a'));var licenseUtil=require(_0xff03('0x1b'));var db=require(_0xff03('0x1c'))['db'];function respondWithStatusCode(_0x9ae090,_0x38e341){_0x38e341=_0x38e341||0xcc;return function(_0x5880a9){if(_0x5880a9){return _0x9ae090[_0xff03('0x1d')](_0x38e341);}return _0x9ae090[_0xff03('0x1e')](_0x38e341)[_0xff03('0x1f')]();};}function respondWithResult(_0x19de1f,_0x3af595){_0x3af595=_0x3af595||0xc8;return function(_0x24ed7c){if(_0x24ed7c){return _0x19de1f[_0xff03('0x1e')](_0x3af595)[_0xff03('0x20')](_0x24ed7c);}};}function respondWithFilteredResult(_0xd2fa8a,_0x41ee60){return function(_0x21245a){if(_0x21245a){var _0x45c146=typeof _0x41ee60[_0xff03('0x21')]===_0xff03('0x22')&&typeof _0x41ee60[_0xff03('0x23')]===_0xff03('0x22');var _0x4e9696=_0x21245a[_0xff03('0x24')];var _0x174cea=_0x45c146?0x0:_0x41ee60[_0xff03('0x21')];var _0x4a1e08=_0x45c146?_0x21245a[_0xff03('0x24')]:_0x41ee60[_0xff03('0x21')]+_0x41ee60[_0xff03('0x23')];var _0x324090;if(_0x4a1e08>=_0x4e9696){_0x4a1e08=_0x4e9696;_0x324090=0xc8;}else{_0x324090=0xce;}_0xd2fa8a['status'](_0x324090);return _0xd2fa8a[_0xff03('0x25')](_0xff03('0x26'),_0x174cea+'-'+_0x4a1e08+'/'+_0x4e9696)[_0xff03('0x20')](_0x21245a);}return null;};}function patchUpdates(_0x347072){return function(_0x45610c){try{jsonpatch[_0xff03('0x27')](_0x45610c,_0x347072,!![]);}catch(_0x146639){return BPromise[_0xff03('0x28')](_0x146639);}return _0x45610c[_0xff03('0x29')]();};}function saveUpdates(_0x4e79ec,_0xadd639){return function(_0x3bf864){if(_0x3bf864){return _0x3bf864[_0xff03('0x2a')](_0x4e79ec)[_0xff03('0x2b')](function(_0x59d33a){return _0x59d33a;});}return null;};}function removeEntity(_0x38ad86,_0x43d1ad){return function(_0x1ad43b){if(_0x1ad43b){return _0x1ad43b['destroy']()['then'](function(){_0x38ad86[_0xff03('0x1e')](0xcc)[_0xff03('0x1f')]();});}};}function handleEntityNotFound(_0x420761,_0x5b4f7b){return function(_0x5c7bed){if(!_0x5c7bed){_0x420761[_0xff03('0x1d')](0x194);}return _0x5c7bed;};}function handleError(_0x5c1390,_0x1f094b){_0x1f094b=_0x1f094b||0x1f4;return function(_0x11658a){logger['error'](_0x11658a[_0xff03('0x2c')]);if(_0x11658a[_0xff03('0x2d')]){delete _0x11658a[_0xff03('0x2d')];}_0x5c1390[_0xff03('0x1e')](_0x1f094b)[_0xff03('0x2e')](_0x11658a);};}exports[_0xff03('0x2f')]=function(_0x32a69e,_0x1e250a){var _0x22b58a={},_0x3ed0dc={},_0x94339f={'count':0x0,'rows':[]};var _0x40f455=_['map'](db[_0xff03('0x30')][_0xff03('0x31')],function(_0x4f1654){return{'name':_0x4f1654[_0xff03('0x32')],'type':_0x4f1654['type'][_0xff03('0x33')]};});_0x3ed0dc[_0xff03('0x34')]=_[_0xff03('0x35')](_0x40f455,_0xff03('0x2d'));_0x3ed0dc[_0xff03('0x36')]=_['keys'](_0x32a69e[_0xff03('0x36')]);_0x3ed0dc['filters']=_[_0xff03('0x37')](_0x3ed0dc[_0xff03('0x34')],_0x3ed0dc[_0xff03('0x36')]);_0x22b58a[_0xff03('0x38')]=_[_0xff03('0x37')](_0x3ed0dc[_0xff03('0x34')],qs['fields'](_0x32a69e[_0xff03('0x36')][_0xff03('0x39')]));_0x22b58a[_0xff03('0x38')]=_0x22b58a['attributes'][_0xff03('0x3a')]?_0x22b58a[_0xff03('0x38')]:_0x3ed0dc[_0xff03('0x34')];if(!_0x32a69e[_0xff03('0x36')][_0xff03('0x3b')](_0xff03('0x3c'))){_0x22b58a[_0xff03('0x23')]=qs[_0xff03('0x23')](_0x32a69e[_0xff03('0x36')][_0xff03('0x23')]);_0x22b58a[_0xff03('0x21')]=qs[_0xff03('0x21')](_0x32a69e['query']['offset']);}_0x22b58a['order']=qs[_0xff03('0x3d')](_0x32a69e['query'][_0xff03('0x3d')]);_0x22b58a[_0xff03('0x3e')]=qs['filters'](_[_0xff03('0x3f')](_0x32a69e[_0xff03('0x36')],_0x3ed0dc[_0xff03('0x40')]),_0x40f455);if(_0x32a69e['query']['filter']){_0x22b58a[_0xff03('0x3e')]=_['merge'](_0x22b58a['where'],{'$or':_[_0xff03('0x35')](_0x40f455,function(_0x3412fe){if(_0x3412fe['type']!==_0xff03('0x41')){var _0x303935={};_0x303935[_0x3412fe['name']]={'$like':'%'+_0x32a69e[_0xff03('0x36')][_0xff03('0x42')]+'%'};return _0x303935;}})});}_0x22b58a=_[_0xff03('0x43')]({},_0x22b58a,_0x32a69e[_0xff03('0x44')]);var _0xb08989={'where':_0x22b58a['where']};return db[_0xff03('0x30')][_0xff03('0x24')](_0xb08989)[_0xff03('0x2b')](function(_0x49ef30){_0x94339f['count']=_0x49ef30;if(_0x32a69e[_0xff03('0x36')][_0xff03('0x45')]){_0x22b58a[_0xff03('0x46')]=[{'all':!![]}];}return db[_0xff03('0x30')]['findAll'](_0x22b58a);})['then'](function(_0x482bbe){_0x94339f[_0xff03('0x47')]=_0x482bbe;return _0x94339f;})['then'](respondWithFilteredResult(_0x1e250a,_0x22b58a))[_0xff03('0x48')](handleError(_0x1e250a,null));};exports[_0xff03('0x49')]=function(_0x2c5937,_0x454928){var _0x58ce49={'raw':![],'where':{'id':_0x2c5937[_0xff03('0x4a')]['id']}},_0xdf5ad4={};_0xdf5ad4[_0xff03('0x34')]=_[_0xff03('0x4b')](db['ServicenowConfiguration'][_0xff03('0x31')]);_0xdf5ad4[_0xff03('0x36')]=_['keys'](_0x2c5937[_0xff03('0x36')]);_0xdf5ad4[_0xff03('0x40')]=_['intersection'](_0xdf5ad4[_0xff03('0x34')],_0xdf5ad4['query']);_0x58ce49[_0xff03('0x38')]=_[_0xff03('0x37')](_0xdf5ad4[_0xff03('0x34')],qs[_0xff03('0x39')](_0x2c5937[_0xff03('0x36')][_0xff03('0x39')]));_0x58ce49[_0xff03('0x38')]=_0x58ce49[_0xff03('0x38')][_0xff03('0x3a')]?_0x58ce49[_0xff03('0x38')]:_0xdf5ad4['model'];if(_0x2c5937[_0xff03('0x36')][_0xff03('0x45')]){_0x58ce49[_0xff03('0x46')]=[{'all':!![]}];}_0x58ce49=_[_0xff03('0x43')]({},_0x58ce49,_0x2c5937[_0xff03('0x44')]);return db[_0xff03('0x30')][_0xff03('0x4c')](_0x58ce49)['then'](handleEntityNotFound(_0x454928,null))[_0xff03('0x2b')](respondWithResult(_0x454928,null))['catch'](handleError(_0x454928,null));};exports[_0xff03('0x4d')]=function(_0x497499,_0x3f3652){return db[_0xff03('0x30')][_0xff03('0x4d')](_0x497499['body'],{})[_0xff03('0x2b')](respondWithResult(_0x3f3652,0xc9))['catch'](handleError(_0x3f3652,null));};exports[_0xff03('0x2a')]=function(_0x1b5c53,_0x487b53){if(_0x1b5c53['body']['id']){delete _0x1b5c53[_0xff03('0x4e')]['id'];}return db[_0xff03('0x30')][_0xff03('0x4c')]({'where':{'id':_0x1b5c53['params']['id']}})[_0xff03('0x2b')](handleEntityNotFound(_0x487b53,null))['then'](saveUpdates(_0x1b5c53['body'],null))[_0xff03('0x2b')](respondWithResult(_0x487b53,null))[_0xff03('0x48')](handleError(_0x487b53,null));};exports[_0xff03('0x4f')]=function(_0x5b01f6,_0x1b4ecd){return db[_0xff03('0x30')][_0xff03('0x4c')]({'where':{'id':_0x5b01f6[_0xff03('0x4a')]['id']}})['then'](handleEntityNotFound(_0x1b4ecd,null))[_0xff03('0x2b')](removeEntity(_0x1b4ecd,null))['catch'](handleError(_0x1b4ecd,null));};exports[_0xff03('0x50')]=function(_0x3cc33b,_0x192ea0,_0x2a3f52){var _0x2aec9c={};var _0x5f10b0={};var _0x44b03e;var _0x316512;return db['ServicenowConfiguration'][_0xff03('0x51')]({'where':{'id':_0x3cc33b[_0xff03('0x4a')]['id']}})['then'](handleEntityNotFound(_0x192ea0,null))[_0xff03('0x2b')](function(_0x75fcbe){if(_0x75fcbe){_0x44b03e=_0x75fcbe;_0x5f10b0[_0xff03('0x34')]=_[_0xff03('0x4b')](db[_0xff03('0x52')]['rawAttributes']);_0x5f10b0['query']=_[_0xff03('0x4b')](_0x3cc33b['query']);_0x5f10b0[_0xff03('0x40')]=_['intersection'](_0x5f10b0[_0xff03('0x34')],_0x5f10b0[_0xff03('0x36')]);_0x2aec9c['attributes']=_['intersection'](_0x5f10b0[_0xff03('0x34')],qs[_0xff03('0x39')](_0x3cc33b[_0xff03('0x36')][_0xff03('0x39')]));_0x2aec9c[_0xff03('0x38')]=_0x2aec9c[_0xff03('0x38')][_0xff03('0x3a')]?_0x2aec9c[_0xff03('0x38')]:_0x5f10b0['model'];_0x2aec9c[_0xff03('0x53')]=qs[_0xff03('0x3d')](_0x3cc33b['query'][_0xff03('0x3d')]);_0x2aec9c[_0xff03('0x3e')]=qs[_0xff03('0x40')](_['pick'](_0x3cc33b[_0xff03('0x36')],_0x5f10b0['filters']));if(_0x3cc33b['query']['filter']){_0x2aec9c[_0xff03('0x3e')]=_['merge'](_0x2aec9c[_0xff03('0x3e')],{'$or':_[_0xff03('0x35')](_0x2aec9c[_0xff03('0x38')],function(_0x41fd9c){var _0x320e29={};_0x320e29[_0x41fd9c]={'$like':'%'+_0x3cc33b['query'][_0xff03('0x42')]+'%'};return _0x320e29;})});}_0x2aec9c=_['merge']({},_0x2aec9c,_0x3cc33b[_0xff03('0x44')]);return _0x44b03e[_0xff03('0x50')](_0x2aec9c);}})[_0xff03('0x2b')](function(_0x2e7e8d){if(_0x2e7e8d){_0x316512=_0x2e7e8d[_0xff03('0x3a')];if(!_0x3cc33b[_0xff03('0x36')][_0xff03('0x3b')](_0xff03('0x3c'))){_0x2aec9c[_0xff03('0x23')]=qs[_0xff03('0x23')](_0x3cc33b['query'][_0xff03('0x23')]);_0x2aec9c[_0xff03('0x21')]=qs[_0xff03('0x21')](_0x3cc33b['query']['offset']);}return _0x44b03e[_0xff03('0x50')](_0x2aec9c);}})[_0xff03('0x2b')](function(_0x350ed6){if(_0x350ed6){return _0x350ed6?{'count':_0x316512,'rows':_0x350ed6}:null;}})[_0xff03('0x2b')](respondWithResult(_0x192ea0,null))['catch'](handleError(_0x192ea0,null));};exports[_0xff03('0x54')]=function(_0x1ec31f,_0x46fd62,_0x1ec622){var _0x4093f5={};var _0x39ce9f={};var _0x89c623;var _0x4f3a4d;return db[_0xff03('0x30')]['findOne']({'where':{'id':_0x1ec31f['params']['id']}})[_0xff03('0x2b')](handleEntityNotFound(_0x46fd62,null))[_0xff03('0x2b')](function(_0x35a24b){if(_0x35a24b){_0x89c623=_0x35a24b;_0x39ce9f['model']=_[_0xff03('0x4b')](db[_0xff03('0x52')][_0xff03('0x31')]);_0x39ce9f['query']=_[_0xff03('0x4b')](_0x1ec31f[_0xff03('0x36')]);_0x39ce9f[_0xff03('0x40')]=_[_0xff03('0x37')](_0x39ce9f['model'],_0x39ce9f[_0xff03('0x36')]);_0x4093f5[_0xff03('0x38')]=_['intersection'](_0x39ce9f['model'],qs[_0xff03('0x39')](_0x1ec31f[_0xff03('0x36')][_0xff03('0x39')]));_0x4093f5['attributes']=_0x4093f5[_0xff03('0x38')]['length']?_0x4093f5['attributes']:_0x39ce9f[_0xff03('0x34')];_0x4093f5['order']=qs['sort'](_0x1ec31f[_0xff03('0x36')][_0xff03('0x3d')]);_0x4093f5[_0xff03('0x3e')]=qs[_0xff03('0x40')](_[_0xff03('0x3f')](_0x1ec31f['query'],_0x39ce9f[_0xff03('0x40')]));if(_0x1ec31f[_0xff03('0x36')]['filter']){_0x4093f5[_0xff03('0x3e')]=_[_0xff03('0x43')](_0x4093f5[_0xff03('0x3e')],{'$or':_[_0xff03('0x35')](_0x4093f5['attributes'],function(_0x11b7bf){var _0x182635={};_0x182635[_0x11b7bf]={'$like':'%'+_0x1ec31f['query'][_0xff03('0x42')]+'%'};return _0x182635;})});}_0x4093f5=_[_0xff03('0x43')]({},_0x4093f5,_0x1ec31f[_0xff03('0x44')]);return _0x89c623[_0xff03('0x54')](_0x4093f5);}})[_0xff03('0x2b')](function(_0x5231de){if(_0x5231de){_0x4f3a4d=_0x5231de[_0xff03('0x3a')];if(!_0x1ec31f[_0xff03('0x36')][_0xff03('0x3b')]('nolimit')){_0x4093f5[_0xff03('0x23')]=qs[_0xff03('0x23')](_0x1ec31f[_0xff03('0x36')][_0xff03('0x23')]);_0x4093f5[_0xff03('0x21')]=qs[_0xff03('0x21')](_0x1ec31f['query'][_0xff03('0x21')]);}return _0x89c623[_0xff03('0x54')](_0x4093f5);}})[_0xff03('0x2b')](function(_0x164d43){if(_0x164d43){return _0x164d43?{'count':_0x4f3a4d,'rows':_0x164d43}:null;}})['then'](respondWithResult(_0x46fd62,null))[_0xff03('0x48')](handleError(_0x46fd62,null));};exports[_0xff03('0x55')]=function(_0x24ae0c,_0x263f79,_0x2b9643){var _0x350c8f={};var _0xe81aca={};var _0x4623a3;var _0x47c589;return db['ServicenowConfiguration'][_0xff03('0x51')]({'where':{'id':_0x24ae0c[_0xff03('0x4a')]['id']}})['then'](handleEntityNotFound(_0x263f79,null))[_0xff03('0x2b')](function(_0x5e6c48){if(_0x5e6c48){_0x4623a3=_0x5e6c48;_0xe81aca[_0xff03('0x34')]=_[_0xff03('0x4b')](db[_0xff03('0x52')][_0xff03('0x31')]);_0xe81aca[_0xff03('0x36')]=_['keys'](_0x24ae0c[_0xff03('0x36')]);_0xe81aca[_0xff03('0x40')]=_[_0xff03('0x37')](_0xe81aca[_0xff03('0x34')],_0xe81aca[_0xff03('0x36')]);_0x350c8f[_0xff03('0x38')]=_['intersection'](_0xe81aca[_0xff03('0x34')],qs[_0xff03('0x39')](_0x24ae0c[_0xff03('0x36')][_0xff03('0x39')]));_0x350c8f['attributes']=_0x350c8f[_0xff03('0x38')]['length']?_0x350c8f[_0xff03('0x38')]:_0xe81aca[_0xff03('0x34')];_0x350c8f['order']=qs[_0xff03('0x3d')](_0x24ae0c[_0xff03('0x36')][_0xff03('0x3d')]);_0x350c8f[_0xff03('0x3e')]=qs[_0xff03('0x40')](_[_0xff03('0x3f')](_0x24ae0c[_0xff03('0x36')],_0xe81aca[_0xff03('0x40')]));if(_0x24ae0c[_0xff03('0x36')]['filter']){_0x350c8f[_0xff03('0x3e')]=_[_0xff03('0x43')](_0x350c8f[_0xff03('0x3e')],{'$or':_[_0xff03('0x35')](_0x350c8f[_0xff03('0x38')],function(_0x16166a){var _0x56cf77={};_0x56cf77[_0x16166a]={'$like':'%'+_0x24ae0c[_0xff03('0x36')]['filter']+'%'};return _0x56cf77;})});}_0x350c8f=_[_0xff03('0x43')]({},_0x350c8f,_0x24ae0c[_0xff03('0x44')]);return _0x4623a3[_0xff03('0x55')](_0x350c8f);}})[_0xff03('0x2b')](function(_0x16d4a0){if(_0x16d4a0){_0x47c589=_0x16d4a0[_0xff03('0x3a')];if(!_0x24ae0c[_0xff03('0x36')][_0xff03('0x3b')](_0xff03('0x3c'))){_0x350c8f[_0xff03('0x23')]=qs[_0xff03('0x23')](_0x24ae0c[_0xff03('0x36')][_0xff03('0x23')]);_0x350c8f[_0xff03('0x21')]=qs[_0xff03('0x21')](_0x24ae0c[_0xff03('0x36')][_0xff03('0x21')]);}return _0x4623a3[_0xff03('0x55')](_0x350c8f);}})[_0xff03('0x2b')](function(_0x5afc44){if(_0x5afc44){return _0x5afc44?{'count':_0x47c589,'rows':_0x5afc44}:null;}})[_0xff03('0x2b')](respondWithResult(_0x263f79,null))[_0xff03('0x48')](handleError(_0x263f79,null));};