76cdd0d3f2bc24c780b32f08912bf51ca81dd468
[motion2.git] / server / api / integrationReport / integrationReport.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 _0xf343=['../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','apply','reject','save','update','destroy','then','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','IntegrationReport','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment'];(function(_0x2d3711,_0x43d60d){var _0x477858=function(_0x4ffb1c){while(--_0x4ffb1c){_0x2d3711['push'](_0x2d3711['shift']());}};_0x477858(++_0x43d60d);}(_0xf343,0x128));var _0x3f34=function(_0x1d6ed3,_0x18a394){_0x1d6ed3=_0x1d6ed3-0x0;var _0x25c417=_0xf343[_0x1d6ed3];return _0x25c417;};'use strict';var emlformat=require(_0x3f34('0x0'));var rimraf=require(_0x3f34('0x1'));var zipdir=require(_0x3f34('0x2'));var jsonpatch=require(_0x3f34('0x3'));var rp=require(_0x3f34('0x4'));var moment=require('moment');var BPromise=require(_0x3f34('0x5'));var Mustache=require(_0x3f34('0x6'));var util=require(_0x3f34('0x7'));var path=require('path');var sox=require(_0x3f34('0x8'));var csv=require(_0x3f34('0x9'));var ejs=require(_0x3f34('0xa'));var fs=require('fs');var fs_extra=require(_0x3f34('0xb'));var _=require(_0x3f34('0xc'));var squel=require('squel');var crypto=require(_0x3f34('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x3f34('0xe'));var toCsv=require(_0x3f34('0x9'));var querystring=require(_0x3f34('0xf'));var Papa=require(_0x3f34('0x10'));var Redis=require(_0x3f34('0x11'));var authService=require(_0x3f34('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3f34('0x13'));var logger=require(_0x3f34('0x14'))(_0x3f34('0x15'));var utils=require(_0x3f34('0x16'));var config=require(_0x3f34('0x17'));var licenseUtil=require(_0x3f34('0x18'));var db=require(_0x3f34('0x19'))['db'];function respondWithStatusCode(_0x4664f0,_0x14b8dd){_0x14b8dd=_0x14b8dd||0xcc;return function(_0x5b60e8){if(_0x5b60e8){return _0x4664f0[_0x3f34('0x1a')](_0x14b8dd);}return _0x4664f0[_0x3f34('0x1b')](_0x14b8dd)[_0x3f34('0x1c')]();};}function respondWithResult(_0x338576,_0x55ec90){_0x55ec90=_0x55ec90||0xc8;return function(_0x125bf6){if(_0x125bf6){return _0x338576[_0x3f34('0x1b')](_0x55ec90)[_0x3f34('0x1d')](_0x125bf6);}};}function respondWithFilteredResult(_0x503328,_0xd89637){return function(_0x489984){if(_0x489984){var _0x1beded=typeof _0xd89637['offset']===_0x3f34('0x1e')&&typeof _0xd89637[_0x3f34('0x1f')]==='undefined';var _0x108b21=_0x489984['count'];var _0x341f44=_0x1beded?0x0:_0xd89637['offset'];var _0x31c589=_0x1beded?_0x489984[_0x3f34('0x20')]:_0xd89637[_0x3f34('0x21')]+_0xd89637['limit'];var _0x4c000d;if(_0x31c589>=_0x108b21){_0x31c589=_0x108b21;_0x4c000d=0xc8;}else{_0x4c000d=0xce;}_0x503328['status'](_0x4c000d);return _0x503328['set'](_0x3f34('0x22'),_0x341f44+'-'+_0x31c589+'/'+_0x108b21)['json'](_0x489984);}return null;};}function patchUpdates(_0xca93b8){return function(_0x32e005){try{jsonpatch[_0x3f34('0x23')](_0x32e005,_0xca93b8,!![]);}catch(_0x4ed59e){return BPromise[_0x3f34('0x24')](_0x4ed59e);}return _0x32e005[_0x3f34('0x25')]();};}function saveUpdates(_0x238615,_0x135212){return function(_0x128d6c){if(_0x128d6c){return _0x128d6c[_0x3f34('0x26')](_0x238615)['then'](function(_0x441792){return _0x441792;});}return null;};}function removeEntity(_0x41c88c,_0x2206e1){return function(_0x1d0b14){if(_0x1d0b14){return _0x1d0b14[_0x3f34('0x27')]()[_0x3f34('0x28')](function(){_0x41c88c[_0x3f34('0x1b')](0xcc)[_0x3f34('0x1c')]();});}};}function handleEntityNotFound(_0x3975f0,_0x14ed02){return function(_0x5e24f2){if(!_0x5e24f2){_0x3975f0[_0x3f34('0x1a')](0x194);}return _0x5e24f2;};}function handleError(_0x50a814,_0x1ad5d6){_0x1ad5d6=_0x1ad5d6||0x1f4;return function(_0x2551ff){logger[_0x3f34('0x29')](_0x2551ff[_0x3f34('0x2a')]);if(_0x2551ff[_0x3f34('0x2b')]){delete _0x2551ff[_0x3f34('0x2b')];}_0x50a814[_0x3f34('0x1b')](_0x1ad5d6)['send'](_0x2551ff);};}exports[_0x3f34('0x2c')]=function(_0x51b061,_0x3ff57b){var _0x343b1a={},_0x3c6b2f={},_0x35a6bf={'count':0x0,'rows':[]};var _0x3d0bb0=_[_0x3f34('0x2d')](db['IntegrationReport'][_0x3f34('0x2e')],function(_0x6fe30){return{'name':_0x6fe30[_0x3f34('0x2f')],'type':_0x6fe30[_0x3f34('0x30')][_0x3f34('0x31')]};});_0x3c6b2f[_0x3f34('0x32')]=_[_0x3f34('0x2d')](_0x3d0bb0,_0x3f34('0x2b'));_0x3c6b2f[_0x3f34('0x33')]=_[_0x3f34('0x34')](_0x51b061[_0x3f34('0x33')]);_0x3c6b2f[_0x3f34('0x35')]=_[_0x3f34('0x36')](_0x3c6b2f[_0x3f34('0x32')],_0x3c6b2f[_0x3f34('0x33')]);_0x343b1a[_0x3f34('0x37')]=_[_0x3f34('0x36')](_0x3c6b2f['model'],qs[_0x3f34('0x38')](_0x51b061[_0x3f34('0x33')][_0x3f34('0x38')]));_0x343b1a['attributes']=_0x343b1a['attributes'][_0x3f34('0x39')]?_0x343b1a[_0x3f34('0x37')]:_0x3c6b2f[_0x3f34('0x32')];if(!_0x51b061['query'][_0x3f34('0x3a')](_0x3f34('0x3b'))){_0x343b1a[_0x3f34('0x1f')]=qs[_0x3f34('0x1f')](_0x51b061[_0x3f34('0x33')][_0x3f34('0x1f')]);_0x343b1a[_0x3f34('0x21')]=qs[_0x3f34('0x21')](_0x51b061[_0x3f34('0x33')][_0x3f34('0x21')]);}_0x343b1a[_0x3f34('0x3c')]=qs[_0x3f34('0x3d')](_0x51b061[_0x3f34('0x33')][_0x3f34('0x3d')]);_0x343b1a['where']=qs[_0x3f34('0x35')](_[_0x3f34('0x3e')](_0x51b061[_0x3f34('0x33')],_0x3c6b2f['filters']),_0x3d0bb0);if(_0x51b061[_0x3f34('0x33')][_0x3f34('0x3f')]){_0x343b1a[_0x3f34('0x40')]=_[_0x3f34('0x41')](_0x343b1a[_0x3f34('0x40')],{'$or':_['map'](_0x3d0bb0,function(_0x2e2c3f){if(_0x2e2c3f['type']!==_0x3f34('0x42')){var _0x587f3f={};_0x587f3f[_0x2e2c3f['name']]={'$like':'%'+_0x51b061[_0x3f34('0x33')][_0x3f34('0x3f')]+'%'};return _0x587f3f;}})});}_0x343b1a=_[_0x3f34('0x41')]({},_0x343b1a,_0x51b061[_0x3f34('0x43')]);var _0xfb3c12={'where':_0x343b1a[_0x3f34('0x40')]};return db['IntegrationReport'][_0x3f34('0x20')](_0xfb3c12)[_0x3f34('0x28')](function(_0x125309){_0x35a6bf[_0x3f34('0x20')]=_0x125309;if(_0x51b061[_0x3f34('0x33')][_0x3f34('0x44')]){_0x343b1a[_0x3f34('0x45')]=[{'all':!![]}];}return db['IntegrationReport'][_0x3f34('0x46')](_0x343b1a);})[_0x3f34('0x28')](function(_0x353cb0){_0x35a6bf[_0x3f34('0x47')]=_0x353cb0;return _0x35a6bf;})[_0x3f34('0x28')](respondWithFilteredResult(_0x3ff57b,_0x343b1a))[_0x3f34('0x48')](handleError(_0x3ff57b,null));};exports[_0x3f34('0x49')]=function(_0x3f3e63,_0x3a9a44){var _0x3ff4c0={'raw':![],'where':{'id':_0x3f3e63['params']['id']}},_0x4e74be={};_0x4e74be[_0x3f34('0x32')]=_['keys'](db['IntegrationReport']['rawAttributes']);_0x4e74be[_0x3f34('0x33')]=_['keys'](_0x3f3e63[_0x3f34('0x33')]);_0x4e74be['filters']=_['intersection'](_0x4e74be[_0x3f34('0x32')],_0x4e74be['query']);_0x3ff4c0[_0x3f34('0x37')]=_[_0x3f34('0x36')](_0x4e74be['model'],qs[_0x3f34('0x38')](_0x3f3e63[_0x3f34('0x33')][_0x3f34('0x38')]));_0x3ff4c0['attributes']=_0x3ff4c0[_0x3f34('0x37')][_0x3f34('0x39')]?_0x3ff4c0[_0x3f34('0x37')]:_0x4e74be['model'];if(_0x3f3e63[_0x3f34('0x33')]['includeAll']){_0x3ff4c0[_0x3f34('0x45')]=[{'all':!![]}];}_0x3ff4c0=_[_0x3f34('0x41')]({},_0x3ff4c0,_0x3f3e63[_0x3f34('0x43')]);return db['IntegrationReport'][_0x3f34('0x4a')](_0x3ff4c0)[_0x3f34('0x28')](handleEntityNotFound(_0x3a9a44,null))[_0x3f34('0x28')](respondWithResult(_0x3a9a44,null))[_0x3f34('0x48')](handleError(_0x3a9a44,null));};exports[_0x3f34('0x4b')]=function(_0x6a292e,_0x2836af){return db[_0x3f34('0x4c')][_0x3f34('0x4b')](_0x6a292e[_0x3f34('0x4d')],{})[_0x3f34('0x28')](respondWithResult(_0x2836af,0xc9))[_0x3f34('0x48')](handleError(_0x2836af,null));};exports[_0x3f34('0x26')]=function(_0x5a45fc,_0x630bf9){if(_0x5a45fc[_0x3f34('0x4d')]['id']){delete _0x5a45fc[_0x3f34('0x4d')]['id'];}return db[_0x3f34('0x4c')][_0x3f34('0x4a')]({'where':{'id':_0x5a45fc[_0x3f34('0x4e')]['id']}})[_0x3f34('0x28')](handleEntityNotFound(_0x630bf9,null))[_0x3f34('0x28')](saveUpdates(_0x5a45fc[_0x3f34('0x4d')],null))[_0x3f34('0x28')](respondWithResult(_0x630bf9,null))[_0x3f34('0x48')](handleError(_0x630bf9,null));};exports['destroy']=function(_0x4bace1,_0x5e3293){return db[_0x3f34('0x4c')][_0x3f34('0x4a')]({'where':{'id':_0x4bace1[_0x3f34('0x4e')]['id']}})['then'](handleEntityNotFound(_0x5e3293,null))['then'](removeEntity(_0x5e3293,null))['catch'](handleError(_0x5e3293,null));};exports[_0x3f34('0x4f')]=function(_0x94f67c,_0x2b4c23){return db[_0x3f34('0x4c')][_0x3f34('0x4f')]()[_0x3f34('0x28')](respondWithResult(_0x2b4c23,null))['catch'](handleError(_0x2b4c23,null));};