d0e9c38dc106e4b1331e0132f3efe5d96e7238a9
[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 _0xb846=['map','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','includeAll','include','ServicenowConfiguration','findAll','rows','catch','params','length','create','body','find','getFields','findOne','ServicenowField','pick','getSubjects','getDescriptions','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send'];(function(_0x41adfa,_0x15de34){var _0x520894=function(_0x474a52){while(--_0x474a52){_0x41adfa['push'](_0x41adfa['shift']());}};_0x520894(++_0x15de34);}(_0xb846,0xcb));var _0x6b84=function(_0xd1d19a,_0x1933f0){_0xd1d19a=_0xd1d19a-0x0;var _0x52a79d=_0xb846[_0xd1d19a];return _0x52a79d;};'use strict';var emlformat=require(_0x6b84('0x0'));var rimraf=require(_0x6b84('0x1'));var zipdir=require(_0x6b84('0x2'));var jsonpatch=require(_0x6b84('0x3'));var rp=require(_0x6b84('0x4'));var moment=require('moment');var BPromise=require(_0x6b84('0x5'));var Mustache=require('mustache');var util=require(_0x6b84('0x6'));var path=require(_0x6b84('0x7'));var sox=require('sox');var csv=require(_0x6b84('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x6b84('0x9'));var squel=require(_0x6b84('0xa'));var crypto=require(_0x6b84('0xb'));var jsforce=require(_0x6b84('0xc'));var deskjs=require(_0x6b84('0xd'));var toCsv=require('to-csv');var querystring=require(_0x6b84('0xe'));var Papa=require(_0x6b84('0xf'));var Redis=require(_0x6b84('0x10'));var authService=require(_0x6b84('0x11'));var qs=require(_0x6b84('0x12'));var as=require(_0x6b84('0x13'));var hardwareService=require(_0x6b84('0x14'));var logger=require(_0x6b84('0x15'))(_0x6b84('0x16'));var utils=require('../../config/utils');var config=require(_0x6b84('0x17'));var licenseUtil=require(_0x6b84('0x18'));var db=require(_0x6b84('0x19'))['db'];function respondWithStatusCode(_0x354777,_0x5260ec){_0x5260ec=_0x5260ec||0xcc;return function(_0x25d0e6){if(_0x25d0e6){return _0x354777[_0x6b84('0x1a')](_0x5260ec);}return _0x354777['status'](_0x5260ec)['end']();};}function respondWithResult(_0x1583d5,_0x444f0d){_0x444f0d=_0x444f0d||0xc8;return function(_0x330b6d){if(_0x330b6d){return _0x1583d5[_0x6b84('0x1b')](_0x444f0d)[_0x6b84('0x1c')](_0x330b6d);}};}function respondWithFilteredResult(_0xe799b,_0x4bec7e){return function(_0x581506){if(_0x581506){var _0x2cc202=typeof _0x4bec7e[_0x6b84('0x1d')]===_0x6b84('0x1e')&&typeof _0x4bec7e['limit']===_0x6b84('0x1e');var _0x10c31d=_0x581506[_0x6b84('0x1f')];var _0x11d9d3=_0x2cc202?0x0:_0x4bec7e['offset'];var _0x2b3f53=_0x2cc202?_0x581506[_0x6b84('0x1f')]:_0x4bec7e['offset']+_0x4bec7e[_0x6b84('0x20')];var _0x3c5e14;if(_0x2b3f53>=_0x10c31d){_0x2b3f53=_0x10c31d;_0x3c5e14=0xc8;}else{_0x3c5e14=0xce;}_0xe799b[_0x6b84('0x1b')](_0x3c5e14);return _0xe799b[_0x6b84('0x21')](_0x6b84('0x22'),_0x11d9d3+'-'+_0x2b3f53+'/'+_0x10c31d)[_0x6b84('0x1c')](_0x581506);}return null;};}function patchUpdates(_0x3a1399){return function(_0x380b0d){try{jsonpatch[_0x6b84('0x23')](_0x380b0d,_0x3a1399,!![]);}catch(_0x56b685){return BPromise[_0x6b84('0x24')](_0x56b685);}return _0x380b0d[_0x6b84('0x25')]();};}function saveUpdates(_0x23cca8,_0x5a85ee){return function(_0x42e04d){if(_0x42e04d){return _0x42e04d[_0x6b84('0x26')](_0x23cca8)[_0x6b84('0x27')](function(_0x1c1a65){return _0x1c1a65;});}return null;};}function removeEntity(_0x36b462,_0x1938b2){return function(_0x5e72c1){if(_0x5e72c1){return _0x5e72c1[_0x6b84('0x28')]()['then'](function(){_0x36b462['status'](0xcc)[_0x6b84('0x29')]();});}};}function handleEntityNotFound(_0x2567cd,_0x135da2){return function(_0xd67525){if(!_0xd67525){_0x2567cd['sendStatus'](0x194);}return _0xd67525;};}function handleError(_0x3c6e0d,_0x2f389d){_0x2f389d=_0x2f389d||0x1f4;return function(_0x5f198a){logger[_0x6b84('0x2a')](_0x5f198a[_0x6b84('0x2b')]);if(_0x5f198a[_0x6b84('0x2c')]){delete _0x5f198a[_0x6b84('0x2c')];}_0x3c6e0d[_0x6b84('0x1b')](_0x2f389d)[_0x6b84('0x2d')](_0x5f198a);};}exports['index']=function(_0x17f347,_0x265b02){var _0x96ac08={},_0x184c69={},_0x208bba={'count':0x0,'rows':[]};var _0xddedb3=_[_0x6b84('0x2e')](db['ServicenowConfiguration'][_0x6b84('0x2f')],function(_0x27aa0b){return{'name':_0x27aa0b[_0x6b84('0x30')],'type':_0x27aa0b['type'][_0x6b84('0x31')]};});_0x184c69[_0x6b84('0x32')]=_[_0x6b84('0x2e')](_0xddedb3,_0x6b84('0x2c'));_0x184c69[_0x6b84('0x33')]=_[_0x6b84('0x34')](_0x17f347[_0x6b84('0x33')]);_0x184c69[_0x6b84('0x35')]=_['intersection'](_0x184c69[_0x6b84('0x32')],_0x184c69[_0x6b84('0x33')]);_0x96ac08[_0x6b84('0x36')]=_[_0x6b84('0x37')](_0x184c69[_0x6b84('0x32')],qs['fields'](_0x17f347[_0x6b84('0x33')][_0x6b84('0x38')]));_0x96ac08['attributes']=_0x96ac08[_0x6b84('0x36')]['length']?_0x96ac08['attributes']:_0x184c69['model'];if(!_0x17f347[_0x6b84('0x33')][_0x6b84('0x39')](_0x6b84('0x3a'))){_0x96ac08[_0x6b84('0x20')]=qs[_0x6b84('0x20')](_0x17f347[_0x6b84('0x33')]['limit']);_0x96ac08['offset']=qs[_0x6b84('0x1d')](_0x17f347[_0x6b84('0x33')][_0x6b84('0x1d')]);}_0x96ac08[_0x6b84('0x3b')]=qs[_0x6b84('0x3c')](_0x17f347[_0x6b84('0x33')]['sort']);_0x96ac08[_0x6b84('0x3d')]=qs[_0x6b84('0x35')](_['pick'](_0x17f347[_0x6b84('0x33')],_0x184c69[_0x6b84('0x35')]),_0xddedb3);if(_0x17f347[_0x6b84('0x33')][_0x6b84('0x3e')]){_0x96ac08[_0x6b84('0x3d')]=_[_0x6b84('0x3f')](_0x96ac08[_0x6b84('0x3d')],{'$or':_[_0x6b84('0x2e')](_0xddedb3,function(_0x755404){if(_0x755404['type']!==_0x6b84('0x40')){var _0x4e02fc={};_0x4e02fc[_0x755404['name']]={'$like':'%'+_0x17f347[_0x6b84('0x33')][_0x6b84('0x3e')]+'%'};return _0x4e02fc;}})});}_0x96ac08=_['merge']({},_0x96ac08,_0x17f347[_0x6b84('0x41')]);var _0x3ef880={'where':_0x96ac08[_0x6b84('0x3d')]};return db['ServicenowConfiguration']['count'](_0x3ef880)[_0x6b84('0x27')](function(_0x219729){_0x208bba[_0x6b84('0x1f')]=_0x219729;if(_0x17f347['query'][_0x6b84('0x42')]){_0x96ac08[_0x6b84('0x43')]=[{'all':!![]}];}return db[_0x6b84('0x44')][_0x6b84('0x45')](_0x96ac08);})[_0x6b84('0x27')](function(_0x5eb945){_0x208bba[_0x6b84('0x46')]=_0x5eb945;return _0x208bba;})[_0x6b84('0x27')](respondWithFilteredResult(_0x265b02,_0x96ac08))[_0x6b84('0x47')](handleError(_0x265b02,null));};exports['show']=function(_0x2b6f4a,_0x566fe8){var _0x8d7413={'raw':![],'where':{'id':_0x2b6f4a[_0x6b84('0x48')]['id']}},_0x11c9f6={};_0x11c9f6[_0x6b84('0x32')]=_[_0x6b84('0x34')](db[_0x6b84('0x44')][_0x6b84('0x2f')]);_0x11c9f6[_0x6b84('0x33')]=_[_0x6b84('0x34')](_0x2b6f4a[_0x6b84('0x33')]);_0x11c9f6[_0x6b84('0x35')]=_[_0x6b84('0x37')](_0x11c9f6[_0x6b84('0x32')],_0x11c9f6[_0x6b84('0x33')]);_0x8d7413[_0x6b84('0x36')]=_[_0x6b84('0x37')](_0x11c9f6[_0x6b84('0x32')],qs['fields'](_0x2b6f4a['query'][_0x6b84('0x38')]));_0x8d7413[_0x6b84('0x36')]=_0x8d7413[_0x6b84('0x36')][_0x6b84('0x49')]?_0x8d7413[_0x6b84('0x36')]:_0x11c9f6[_0x6b84('0x32')];if(_0x2b6f4a[_0x6b84('0x33')][_0x6b84('0x42')]){_0x8d7413[_0x6b84('0x43')]=[{'all':!![]}];}_0x8d7413=_[_0x6b84('0x3f')]({},_0x8d7413,_0x2b6f4a['options']);return db[_0x6b84('0x44')]['find'](_0x8d7413)[_0x6b84('0x27')](handleEntityNotFound(_0x566fe8,null))['then'](respondWithResult(_0x566fe8,null))[_0x6b84('0x47')](handleError(_0x566fe8,null));};exports[_0x6b84('0x4a')]=function(_0x30300d,_0x4d5d55){return db[_0x6b84('0x44')][_0x6b84('0x4a')](_0x30300d[_0x6b84('0x4b')],{})[_0x6b84('0x27')](respondWithResult(_0x4d5d55,0xc9))['catch'](handleError(_0x4d5d55,null));};exports['update']=function(_0x449edf,_0x4cf32e){if(_0x449edf['body']['id']){delete _0x449edf[_0x6b84('0x4b')]['id'];}return db[_0x6b84('0x44')][_0x6b84('0x4c')]({'where':{'id':_0x449edf[_0x6b84('0x48')]['id']}})[_0x6b84('0x27')](handleEntityNotFound(_0x4cf32e,null))['then'](saveUpdates(_0x449edf[_0x6b84('0x4b')],null))[_0x6b84('0x27')](respondWithResult(_0x4cf32e,null))[_0x6b84('0x47')](handleError(_0x4cf32e,null));};exports[_0x6b84('0x28')]=function(_0x107b23,_0xc45bef){return db[_0x6b84('0x44')][_0x6b84('0x4c')]({'where':{'id':_0x107b23[_0x6b84('0x48')]['id']}})['then'](handleEntityNotFound(_0xc45bef,null))[_0x6b84('0x27')](removeEntity(_0xc45bef,null))['catch'](handleError(_0xc45bef,null));};exports[_0x6b84('0x4d')]=function(_0xfe00c1,_0xff2f03,_0x587347){var _0x986cda={};var _0x179ebf={};var _0x570277;var _0x55fed4;return db[_0x6b84('0x44')][_0x6b84('0x4e')]({'where':{'id':_0xfe00c1[_0x6b84('0x48')]['id']}})[_0x6b84('0x27')](handleEntityNotFound(_0xff2f03,null))[_0x6b84('0x27')](function(_0x566226){if(_0x566226){_0x570277=_0x566226;_0x179ebf['model']=_[_0x6b84('0x34')](db[_0x6b84('0x4f')][_0x6b84('0x2f')]);_0x179ebf[_0x6b84('0x33')]=_['keys'](_0xfe00c1[_0x6b84('0x33')]);_0x179ebf[_0x6b84('0x35')]=_['intersection'](_0x179ebf[_0x6b84('0x32')],_0x179ebf['query']);_0x986cda[_0x6b84('0x36')]=_['intersection'](_0x179ebf[_0x6b84('0x32')],qs[_0x6b84('0x38')](_0xfe00c1[_0x6b84('0x33')]['fields']));_0x986cda[_0x6b84('0x36')]=_0x986cda[_0x6b84('0x36')][_0x6b84('0x49')]?_0x986cda['attributes']:_0x179ebf['model'];_0x986cda[_0x6b84('0x3b')]=qs['sort'](_0xfe00c1['query']['sort']);_0x986cda[_0x6b84('0x3d')]=qs['filters'](_[_0x6b84('0x50')](_0xfe00c1[_0x6b84('0x33')],_0x179ebf['filters']));if(_0xfe00c1[_0x6b84('0x33')]['filter']){_0x986cda[_0x6b84('0x3d')]=_[_0x6b84('0x3f')](_0x986cda[_0x6b84('0x3d')],{'$or':_['map'](_0x986cda[_0x6b84('0x36')],function(_0x5cc847){var _0x4e20b1={};_0x4e20b1[_0x5cc847]={'$like':'%'+_0xfe00c1['query'][_0x6b84('0x3e')]+'%'};return _0x4e20b1;})});}_0x986cda=_['merge']({},_0x986cda,_0xfe00c1['options']);return _0x570277[_0x6b84('0x4d')](_0x986cda);}})[_0x6b84('0x27')](function(_0x51005b){if(_0x51005b){_0x55fed4=_0x51005b[_0x6b84('0x49')];if(!_0xfe00c1[_0x6b84('0x33')][_0x6b84('0x39')](_0x6b84('0x3a'))){_0x986cda['limit']=qs[_0x6b84('0x20')](_0xfe00c1['query'][_0x6b84('0x20')]);_0x986cda[_0x6b84('0x1d')]=qs[_0x6b84('0x1d')](_0xfe00c1[_0x6b84('0x33')][_0x6b84('0x1d')]);}return _0x570277[_0x6b84('0x4d')](_0x986cda);}})['then'](function(_0xd8dd29){if(_0xd8dd29){return _0xd8dd29?{'count':_0x55fed4,'rows':_0xd8dd29}:null;}})[_0x6b84('0x27')](respondWithResult(_0xff2f03,null))['catch'](handleError(_0xff2f03,null));};exports['getSubjects']=function(_0x52d5be,_0x20ee32,_0x31f8b0){var _0x5cc0bb={};var _0x179be7={};var _0x1b907e;var _0x3c566a;return db[_0x6b84('0x44')][_0x6b84('0x4e')]({'where':{'id':_0x52d5be[_0x6b84('0x48')]['id']}})[_0x6b84('0x27')](handleEntityNotFound(_0x20ee32,null))[_0x6b84('0x27')](function(_0x277f5f){if(_0x277f5f){_0x1b907e=_0x277f5f;_0x179be7['model']=_[_0x6b84('0x34')](db[_0x6b84('0x4f')][_0x6b84('0x2f')]);_0x179be7[_0x6b84('0x33')]=_[_0x6b84('0x34')](_0x52d5be[_0x6b84('0x33')]);_0x179be7['filters']=_[_0x6b84('0x37')](_0x179be7[_0x6b84('0x32')],_0x179be7[_0x6b84('0x33')]);_0x5cc0bb['attributes']=_[_0x6b84('0x37')](_0x179be7[_0x6b84('0x32')],qs[_0x6b84('0x38')](_0x52d5be['query'][_0x6b84('0x38')]));_0x5cc0bb[_0x6b84('0x36')]=_0x5cc0bb[_0x6b84('0x36')][_0x6b84('0x49')]?_0x5cc0bb[_0x6b84('0x36')]:_0x179be7['model'];_0x5cc0bb[_0x6b84('0x3b')]=qs[_0x6b84('0x3c')](_0x52d5be[_0x6b84('0x33')][_0x6b84('0x3c')]);_0x5cc0bb[_0x6b84('0x3d')]=qs[_0x6b84('0x35')](_['pick'](_0x52d5be[_0x6b84('0x33')],_0x179be7[_0x6b84('0x35')]));if(_0x52d5be[_0x6b84('0x33')]['filter']){_0x5cc0bb[_0x6b84('0x3d')]=_[_0x6b84('0x3f')](_0x5cc0bb['where'],{'$or':_[_0x6b84('0x2e')](_0x5cc0bb[_0x6b84('0x36')],function(_0x3ccda5){var _0x11e39d={};_0x11e39d[_0x3ccda5]={'$like':'%'+_0x52d5be[_0x6b84('0x33')][_0x6b84('0x3e')]+'%'};return _0x11e39d;})});}_0x5cc0bb=_[_0x6b84('0x3f')]({},_0x5cc0bb,_0x52d5be['options']);return _0x1b907e['getSubjects'](_0x5cc0bb);}})[_0x6b84('0x27')](function(_0x31c46b){if(_0x31c46b){_0x3c566a=_0x31c46b[_0x6b84('0x49')];if(!_0x52d5be['query'][_0x6b84('0x39')]('nolimit')){_0x5cc0bb[_0x6b84('0x20')]=qs[_0x6b84('0x20')](_0x52d5be['query'][_0x6b84('0x20')]);_0x5cc0bb[_0x6b84('0x1d')]=qs[_0x6b84('0x1d')](_0x52d5be[_0x6b84('0x33')]['offset']);}return _0x1b907e[_0x6b84('0x51')](_0x5cc0bb);}})[_0x6b84('0x27')](function(_0x268f74){if(_0x268f74){return _0x268f74?{'count':_0x3c566a,'rows':_0x268f74}:null;}})[_0x6b84('0x27')](respondWithResult(_0x20ee32,null))[_0x6b84('0x47')](handleError(_0x20ee32,null));};exports[_0x6b84('0x52')]=function(_0x46ff0f,_0x21674f,_0x3d9e63){var _0x14103a={};var _0xe3775b={};var _0x4ff1cc;var _0x4f77d9;return db[_0x6b84('0x44')]['findOne']({'where':{'id':_0x46ff0f['params']['id']}})[_0x6b84('0x27')](handleEntityNotFound(_0x21674f,null))[_0x6b84('0x27')](function(_0x48eb71){if(_0x48eb71){_0x4ff1cc=_0x48eb71;_0xe3775b[_0x6b84('0x32')]=_[_0x6b84('0x34')](db[_0x6b84('0x4f')]['rawAttributes']);_0xe3775b['query']=_[_0x6b84('0x34')](_0x46ff0f[_0x6b84('0x33')]);_0xe3775b['filters']=_[_0x6b84('0x37')](_0xe3775b[_0x6b84('0x32')],_0xe3775b[_0x6b84('0x33')]);_0x14103a[_0x6b84('0x36')]=_['intersection'](_0xe3775b[_0x6b84('0x32')],qs[_0x6b84('0x38')](_0x46ff0f[_0x6b84('0x33')]['fields']));_0x14103a['attributes']=_0x14103a[_0x6b84('0x36')][_0x6b84('0x49')]?_0x14103a[_0x6b84('0x36')]:_0xe3775b[_0x6b84('0x32')];_0x14103a[_0x6b84('0x3b')]=qs[_0x6b84('0x3c')](_0x46ff0f[_0x6b84('0x33')][_0x6b84('0x3c')]);_0x14103a[_0x6b84('0x3d')]=qs['filters'](_[_0x6b84('0x50')](_0x46ff0f[_0x6b84('0x33')],_0xe3775b[_0x6b84('0x35')]));if(_0x46ff0f['query'][_0x6b84('0x3e')]){_0x14103a[_0x6b84('0x3d')]=_[_0x6b84('0x3f')](_0x14103a['where'],{'$or':_[_0x6b84('0x2e')](_0x14103a['attributes'],function(_0xd72b3c){var _0x3d35cf={};_0x3d35cf[_0xd72b3c]={'$like':'%'+_0x46ff0f[_0x6b84('0x33')][_0x6b84('0x3e')]+'%'};return _0x3d35cf;})});}_0x14103a=_[_0x6b84('0x3f')]({},_0x14103a,_0x46ff0f[_0x6b84('0x41')]);return _0x4ff1cc[_0x6b84('0x52')](_0x14103a);}})[_0x6b84('0x27')](function(_0x18724e){if(_0x18724e){_0x4f77d9=_0x18724e[_0x6b84('0x49')];if(!_0x46ff0f[_0x6b84('0x33')][_0x6b84('0x39')](_0x6b84('0x3a'))){_0x14103a[_0x6b84('0x20')]=qs[_0x6b84('0x20')](_0x46ff0f[_0x6b84('0x33')]['limit']);_0x14103a[_0x6b84('0x1d')]=qs['offset'](_0x46ff0f[_0x6b84('0x33')]['offset']);}return _0x4ff1cc[_0x6b84('0x52')](_0x14103a);}})[_0x6b84('0x27')](function(_0x5a1506){if(_0x5a1506){return _0x5a1506?{'count':_0x4f77d9,'rows':_0x5a1506}:null;}})[_0x6b84('0x27')](respondWithResult(_0x21674f,null))[_0x6b84('0x47')](handleError(_0x21674f,null));};