Built motion from commit da617fac.|2.6.6
[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 _0xf453=['../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','status','offset','limit','set','json','reject','save','update','then','end','sendStatus','error','stack','name','send','index','ServicenowConfiguration','rawAttributes','fieldName','key','map','query','keys','intersection','model','fields','attributes','length','hasOwnProperty','sort','filters','filter','where','merge','type','VIRTUAL','options','count','findAll','rows','catch','params','include','create','body','find','destroy','getFields','pick','nolimit','getSubjects','ServicenowField','getDescriptions','findOne','order','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','fs-extra','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x2b4411,_0x2625ed){var _0x8e41ef=function(_0x2aa8c1){while(--_0x2aa8c1){_0x2b4411['push'](_0x2b4411['shift']());}};_0x8e41ef(++_0x2625ed);}(_0xf453,0xda));var _0x3f45=function(_0x27f973,_0x58596f){_0x27f973=_0x27f973-0x0;var _0x255e5d=_0xf453[_0x27f973];return _0x255e5d;};'use strict';var emlformat=require(_0x3f45('0x0'));var rimraf=require(_0x3f45('0x1'));var zipdir=require(_0x3f45('0x2'));var jsonpatch=require(_0x3f45('0x3'));var rp=require(_0x3f45('0x4'));var moment=require(_0x3f45('0x5'));var BPromise=require(_0x3f45('0x6'));var Mustache=require(_0x3f45('0x7'));var util=require('util');var path=require(_0x3f45('0x8'));var sox=require(_0x3f45('0x9'));var csv=require(_0x3f45('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3f45('0xb'));var _=require('lodash');var squel=require(_0x3f45('0xc'));var crypto=require('crypto');var jsforce=require(_0x3f45('0xd'));var deskjs=require(_0x3f45('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x3f45('0xf'));var Redis=require(_0x3f45('0x10'));var authService=require(_0x3f45('0x11'));var qs=require(_0x3f45('0x12'));var as=require(_0x3f45('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3f45('0x14'));var utils=require(_0x3f45('0x15'));var config=require(_0x3f45('0x16'));var licenseUtil=require(_0x3f45('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x18296b,_0x57172b){_0x57172b=_0x57172b||0xcc;return function(_0x1e15d4){if(_0x1e15d4){return _0x18296b['sendStatus'](_0x57172b);}return _0x18296b[_0x3f45('0x18')](_0x57172b)['end']();};}function respondWithResult(_0x5e9151,_0x405ecd){_0x405ecd=_0x405ecd||0xc8;return function(_0x3634fd){if(_0x3634fd){return _0x5e9151[_0x3f45('0x18')](_0x405ecd)['json'](_0x3634fd);}};}function respondWithFilteredResult(_0x571ff2,_0x2e8d28){return function(_0x42e823){if(_0x42e823){var _0x3fe138=typeof _0x2e8d28[_0x3f45('0x19')]==='undefined'&&typeof _0x2e8d28['limit']==='undefined';var _0x32c3d2=_0x42e823['count'];var _0x17e978=_0x3fe138?0x0:_0x2e8d28[_0x3f45('0x19')];var _0x24521b=_0x3fe138?_0x42e823['count']:_0x2e8d28[_0x3f45('0x19')]+_0x2e8d28[_0x3f45('0x1a')];var _0x88b366;if(_0x24521b>=_0x32c3d2){_0x24521b=_0x32c3d2;_0x88b366=0xc8;}else{_0x88b366=0xce;}_0x571ff2[_0x3f45('0x18')](_0x88b366);return _0x571ff2[_0x3f45('0x1b')]('Content-Range',_0x17e978+'-'+_0x24521b+'/'+_0x32c3d2)[_0x3f45('0x1c')](_0x42e823);}return null;};}function patchUpdates(_0x265705){return function(_0x563864){try{jsonpatch['apply'](_0x563864,_0x265705,!![]);}catch(_0x388164){return BPromise[_0x3f45('0x1d')](_0x388164);}return _0x563864[_0x3f45('0x1e')]();};}function saveUpdates(_0x213d23,_0x3b5255){return function(_0x495714){if(_0x495714){return _0x495714[_0x3f45('0x1f')](_0x213d23)[_0x3f45('0x20')](function(_0x199c2a){return _0x199c2a;});}return null;};}function removeEntity(_0x1c6585,_0x1cef58){return function(_0x11a4b1){if(_0x11a4b1){return _0x11a4b1['destroy']()['then'](function(){_0x1c6585[_0x3f45('0x18')](0xcc)[_0x3f45('0x21')]();});}};}function handleEntityNotFound(_0x56031e,_0x4e410f){return function(_0x319fd7){if(!_0x319fd7){_0x56031e[_0x3f45('0x22')](0x194);}return _0x319fd7;};}function handleError(_0x4481f3,_0x3d77a3){_0x3d77a3=_0x3d77a3||0x1f4;return function(_0x35fd99){logger[_0x3f45('0x23')](_0x35fd99[_0x3f45('0x24')]);if(_0x35fd99[_0x3f45('0x25')]){delete _0x35fd99[_0x3f45('0x25')];}_0x4481f3['status'](_0x3d77a3)[_0x3f45('0x26')](_0x35fd99);};}exports[_0x3f45('0x27')]=function(_0x31295a,_0x35dc4b){var _0x473b07={},_0x58a435={},_0x3664b8={'count':0x0,'rows':[]};var _0x2ee80f=_['map'](db[_0x3f45('0x28')][_0x3f45('0x29')],function(_0x3ad446){return{'name':_0x3ad446[_0x3f45('0x2a')],'type':_0x3ad446['type'][_0x3f45('0x2b')]};});_0x58a435['model']=_[_0x3f45('0x2c')](_0x2ee80f,_0x3f45('0x25'));_0x58a435[_0x3f45('0x2d')]=_[_0x3f45('0x2e')](_0x31295a[_0x3f45('0x2d')]);_0x58a435['filters']=_[_0x3f45('0x2f')](_0x58a435[_0x3f45('0x30')],_0x58a435[_0x3f45('0x2d')]);_0x473b07['attributes']=_['intersection'](_0x58a435[_0x3f45('0x30')],qs[_0x3f45('0x31')](_0x31295a[_0x3f45('0x2d')][_0x3f45('0x31')]));_0x473b07[_0x3f45('0x32')]=_0x473b07[_0x3f45('0x32')][_0x3f45('0x33')]?_0x473b07[_0x3f45('0x32')]:_0x58a435[_0x3f45('0x30')];if(!_0x31295a[_0x3f45('0x2d')][_0x3f45('0x34')]('nolimit')){_0x473b07[_0x3f45('0x1a')]=qs['limit'](_0x31295a['query'][_0x3f45('0x1a')]);_0x473b07[_0x3f45('0x19')]=qs['offset'](_0x31295a[_0x3f45('0x2d')][_0x3f45('0x19')]);}_0x473b07['order']=qs[_0x3f45('0x35')](_0x31295a['query'][_0x3f45('0x35')]);_0x473b07['where']=qs[_0x3f45('0x36')](_['pick'](_0x31295a[_0x3f45('0x2d')],_0x58a435[_0x3f45('0x36')]),_0x2ee80f);if(_0x31295a[_0x3f45('0x2d')][_0x3f45('0x37')]){_0x473b07[_0x3f45('0x38')]=_[_0x3f45('0x39')](_0x473b07[_0x3f45('0x38')],{'$or':_[_0x3f45('0x2c')](_0x2ee80f,function(_0x503068){if(_0x503068[_0x3f45('0x3a')]!==_0x3f45('0x3b')){var _0x268d32={};_0x268d32[_0x503068[_0x3f45('0x25')]]={'$like':'%'+_0x31295a[_0x3f45('0x2d')][_0x3f45('0x37')]+'%'};return _0x268d32;}})});}_0x473b07=_['merge']({},_0x473b07,_0x31295a[_0x3f45('0x3c')]);var _0x4efd4d={'where':_0x473b07['where']};return db[_0x3f45('0x28')][_0x3f45('0x3d')](_0x4efd4d)[_0x3f45('0x20')](function(_0xa3b854){_0x3664b8[_0x3f45('0x3d')]=_0xa3b854;if(_0x31295a[_0x3f45('0x2d')]['includeAll']){_0x473b07['include']=[{'all':!![]}];}return db[_0x3f45('0x28')][_0x3f45('0x3e')](_0x473b07);})[_0x3f45('0x20')](function(_0x543bd7){_0x3664b8[_0x3f45('0x3f')]=_0x543bd7;return _0x3664b8;})[_0x3f45('0x20')](respondWithFilteredResult(_0x35dc4b,_0x473b07))[_0x3f45('0x40')](handleError(_0x35dc4b,null));};exports['show']=function(_0x38bf88,_0x1679d0){var _0x46aea0={'raw':![],'where':{'id':_0x38bf88[_0x3f45('0x41')]['id']}},_0x314a64={};_0x314a64['model']=_['keys'](db['ServicenowConfiguration'][_0x3f45('0x29')]);_0x314a64[_0x3f45('0x2d')]=_[_0x3f45('0x2e')](_0x38bf88[_0x3f45('0x2d')]);_0x314a64[_0x3f45('0x36')]=_[_0x3f45('0x2f')](_0x314a64[_0x3f45('0x30')],_0x314a64['query']);_0x46aea0['attributes']=_[_0x3f45('0x2f')](_0x314a64[_0x3f45('0x30')],qs[_0x3f45('0x31')](_0x38bf88['query'][_0x3f45('0x31')]));_0x46aea0[_0x3f45('0x32')]=_0x46aea0[_0x3f45('0x32')][_0x3f45('0x33')]?_0x46aea0['attributes']:_0x314a64['model'];if(_0x38bf88[_0x3f45('0x2d')]['includeAll']){_0x46aea0[_0x3f45('0x42')]=[{'all':!![]}];}_0x46aea0=_[_0x3f45('0x39')]({},_0x46aea0,_0x38bf88[_0x3f45('0x3c')]);return db[_0x3f45('0x28')]['find'](_0x46aea0)[_0x3f45('0x20')](handleEntityNotFound(_0x1679d0,null))[_0x3f45('0x20')](respondWithResult(_0x1679d0,null))[_0x3f45('0x40')](handleError(_0x1679d0,null));};exports[_0x3f45('0x43')]=function(_0x5cbac8,_0x1874fd){return db[_0x3f45('0x28')][_0x3f45('0x43')](_0x5cbac8['body'],{})[_0x3f45('0x20')](respondWithResult(_0x1874fd,0xc9))[_0x3f45('0x40')](handleError(_0x1874fd,null));};exports[_0x3f45('0x1f')]=function(_0x17b426,_0x2eae52){if(_0x17b426[_0x3f45('0x44')]['id']){delete _0x17b426[_0x3f45('0x44')]['id'];}return db[_0x3f45('0x28')][_0x3f45('0x45')]({'where':{'id':_0x17b426['params']['id']}})['then'](handleEntityNotFound(_0x2eae52,null))['then'](saveUpdates(_0x17b426[_0x3f45('0x44')],null))[_0x3f45('0x20')](respondWithResult(_0x2eae52,null))[_0x3f45('0x40')](handleError(_0x2eae52,null));};exports[_0x3f45('0x46')]=function(_0x36ccfe,_0x56ddb8){return db[_0x3f45('0x28')][_0x3f45('0x45')]({'where':{'id':_0x36ccfe['params']['id']}})['then'](handleEntityNotFound(_0x56ddb8,null))[_0x3f45('0x20')](removeEntity(_0x56ddb8,null))[_0x3f45('0x40')](handleError(_0x56ddb8,null));};exports[_0x3f45('0x47')]=function(_0x3b9c6c,_0x1d2b68,_0x44f16a){var _0x4f6574={};var _0x5494c4={};var _0x15a154;var _0x38c497;return db['ServicenowConfiguration']['findOne']({'where':{'id':_0x3b9c6c['params']['id']}})[_0x3f45('0x20')](handleEntityNotFound(_0x1d2b68,null))[_0x3f45('0x20')](function(_0x29cc53){if(_0x29cc53){_0x15a154=_0x29cc53;_0x5494c4['model']=_['keys'](db['ServicenowField'][_0x3f45('0x29')]);_0x5494c4[_0x3f45('0x2d')]=_[_0x3f45('0x2e')](_0x3b9c6c[_0x3f45('0x2d')]);_0x5494c4['filters']=_['intersection'](_0x5494c4['model'],_0x5494c4[_0x3f45('0x2d')]);_0x4f6574[_0x3f45('0x32')]=_[_0x3f45('0x2f')](_0x5494c4[_0x3f45('0x30')],qs[_0x3f45('0x31')](_0x3b9c6c[_0x3f45('0x2d')]['fields']));_0x4f6574[_0x3f45('0x32')]=_0x4f6574[_0x3f45('0x32')][_0x3f45('0x33')]?_0x4f6574['attributes']:_0x5494c4[_0x3f45('0x30')];_0x4f6574['order']=qs[_0x3f45('0x35')](_0x3b9c6c[_0x3f45('0x2d')][_0x3f45('0x35')]);_0x4f6574['where']=qs['filters'](_[_0x3f45('0x48')](_0x3b9c6c[_0x3f45('0x2d')],_0x5494c4[_0x3f45('0x36')]));if(_0x3b9c6c[_0x3f45('0x2d')][_0x3f45('0x37')]){_0x4f6574['where']=_[_0x3f45('0x39')](_0x4f6574[_0x3f45('0x38')],{'$or':_[_0x3f45('0x2c')](_0x4f6574['attributes'],function(_0x5cf974){var _0x2e77f2={};_0x2e77f2[_0x5cf974]={'$like':'%'+_0x3b9c6c[_0x3f45('0x2d')][_0x3f45('0x37')]+'%'};return _0x2e77f2;})});}_0x4f6574=_['merge']({},_0x4f6574,_0x3b9c6c[_0x3f45('0x3c')]);return _0x15a154[_0x3f45('0x47')](_0x4f6574);}})[_0x3f45('0x20')](function(_0x2698ed){if(_0x2698ed){_0x38c497=_0x2698ed[_0x3f45('0x33')];if(!_0x3b9c6c[_0x3f45('0x2d')][_0x3f45('0x34')](_0x3f45('0x49'))){_0x4f6574['limit']=qs[_0x3f45('0x1a')](_0x3b9c6c['query']['limit']);_0x4f6574['offset']=qs['offset'](_0x3b9c6c[_0x3f45('0x2d')]['offset']);}return _0x15a154[_0x3f45('0x47')](_0x4f6574);}})[_0x3f45('0x20')](function(_0x488bc4){if(_0x488bc4){return _0x488bc4?{'count':_0x38c497,'rows':_0x488bc4}:null;}})[_0x3f45('0x20')](respondWithResult(_0x1d2b68,null))[_0x3f45('0x40')](handleError(_0x1d2b68,null));};exports[_0x3f45('0x4a')]=function(_0x7877b4,_0x320d77,_0x2b2b11){var _0x359693={};var _0xd865a8={};var _0x4158e9;var _0x333245;return db[_0x3f45('0x28')]['findOne']({'where':{'id':_0x7877b4[_0x3f45('0x41')]['id']}})[_0x3f45('0x20')](handleEntityNotFound(_0x320d77,null))[_0x3f45('0x20')](function(_0x3c0043){if(_0x3c0043){_0x4158e9=_0x3c0043;_0xd865a8[_0x3f45('0x30')]=_[_0x3f45('0x2e')](db[_0x3f45('0x4b')][_0x3f45('0x29')]);_0xd865a8[_0x3f45('0x2d')]=_['keys'](_0x7877b4[_0x3f45('0x2d')]);_0xd865a8[_0x3f45('0x36')]=_[_0x3f45('0x2f')](_0xd865a8['model'],_0xd865a8[_0x3f45('0x2d')]);_0x359693[_0x3f45('0x32')]=_[_0x3f45('0x2f')](_0xd865a8['model'],qs['fields'](_0x7877b4['query'][_0x3f45('0x31')]));_0x359693[_0x3f45('0x32')]=_0x359693[_0x3f45('0x32')][_0x3f45('0x33')]?_0x359693[_0x3f45('0x32')]:_0xd865a8[_0x3f45('0x30')];_0x359693['order']=qs[_0x3f45('0x35')](_0x7877b4[_0x3f45('0x2d')][_0x3f45('0x35')]);_0x359693['where']=qs[_0x3f45('0x36')](_[_0x3f45('0x48')](_0x7877b4[_0x3f45('0x2d')],_0xd865a8[_0x3f45('0x36')]));if(_0x7877b4['query'][_0x3f45('0x37')]){_0x359693['where']=_['merge'](_0x359693[_0x3f45('0x38')],{'$or':_[_0x3f45('0x2c')](_0x359693[_0x3f45('0x32')],function(_0x531541){var _0x5965ca={};_0x5965ca[_0x531541]={'$like':'%'+_0x7877b4[_0x3f45('0x2d')][_0x3f45('0x37')]+'%'};return _0x5965ca;})});}_0x359693=_[_0x3f45('0x39')]({},_0x359693,_0x7877b4[_0x3f45('0x3c')]);return _0x4158e9[_0x3f45('0x4a')](_0x359693);}})[_0x3f45('0x20')](function(_0x5d6f1a){if(_0x5d6f1a){_0x333245=_0x5d6f1a[_0x3f45('0x33')];if(!_0x7877b4[_0x3f45('0x2d')]['hasOwnProperty'](_0x3f45('0x49'))){_0x359693[_0x3f45('0x1a')]=qs['limit'](_0x7877b4['query'][_0x3f45('0x1a')]);_0x359693['offset']=qs[_0x3f45('0x19')](_0x7877b4[_0x3f45('0x2d')][_0x3f45('0x19')]);}return _0x4158e9[_0x3f45('0x4a')](_0x359693);}})['then'](function(_0x57d14a){if(_0x57d14a){return _0x57d14a?{'count':_0x333245,'rows':_0x57d14a}:null;}})[_0x3f45('0x20')](respondWithResult(_0x320d77,null))[_0x3f45('0x40')](handleError(_0x320d77,null));};exports[_0x3f45('0x4c')]=function(_0x2cb15e,_0x270dd2,_0x3236e4){var _0x5713d8={};var _0x581344={};var _0x5b4400;var _0x34e169;return db['ServicenowConfiguration'][_0x3f45('0x4d')]({'where':{'id':_0x2cb15e['params']['id']}})['then'](handleEntityNotFound(_0x270dd2,null))[_0x3f45('0x20')](function(_0x29b6b8){if(_0x29b6b8){_0x5b4400=_0x29b6b8;_0x581344[_0x3f45('0x30')]=_['keys'](db[_0x3f45('0x4b')][_0x3f45('0x29')]);_0x581344[_0x3f45('0x2d')]=_['keys'](_0x2cb15e['query']);_0x581344['filters']=_[_0x3f45('0x2f')](_0x581344[_0x3f45('0x30')],_0x581344[_0x3f45('0x2d')]);_0x5713d8[_0x3f45('0x32')]=_[_0x3f45('0x2f')](_0x581344['model'],qs[_0x3f45('0x31')](_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x31')]));_0x5713d8[_0x3f45('0x32')]=_0x5713d8['attributes'][_0x3f45('0x33')]?_0x5713d8['attributes']:_0x581344[_0x3f45('0x30')];_0x5713d8[_0x3f45('0x4e')]=qs[_0x3f45('0x35')](_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x35')]);_0x5713d8[_0x3f45('0x38')]=qs[_0x3f45('0x36')](_['pick'](_0x2cb15e[_0x3f45('0x2d')],_0x581344[_0x3f45('0x36')]));if(_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x37')]){_0x5713d8['where']=_[_0x3f45('0x39')](_0x5713d8[_0x3f45('0x38')],{'$or':_[_0x3f45('0x2c')](_0x5713d8['attributes'],function(_0x1c4194){var _0x1be433={};_0x1be433[_0x1c4194]={'$like':'%'+_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x37')]+'%'};return _0x1be433;})});}_0x5713d8=_['merge']({},_0x5713d8,_0x2cb15e[_0x3f45('0x3c')]);return _0x5b4400[_0x3f45('0x4c')](_0x5713d8);}})['then'](function(_0x186275){if(_0x186275){_0x34e169=_0x186275[_0x3f45('0x33')];if(!_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x34')](_0x3f45('0x49'))){_0x5713d8[_0x3f45('0x1a')]=qs[_0x3f45('0x1a')](_0x2cb15e[_0x3f45('0x2d')][_0x3f45('0x1a')]);_0x5713d8[_0x3f45('0x19')]=qs['offset'](_0x2cb15e['query'][_0x3f45('0x19')]);}return _0x5b4400['getDescriptions'](_0x5713d8);}})[_0x3f45('0x20')](function(_0x346932){if(_0x346932){return _0x346932?{'count':_0x34e169,'rows':_0x346932}:null;}})[_0x3f45('0x20')](respondWithResult(_0x270dd2,null))['catch'](handleError(_0x270dd2,null));};