2b034cd0f18bad76ef67aaab6ba1a7df1b00c12e
[motion2.git] / server / api / voiceDialReport / voiceDialReport.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 _0x4bf6=['json','offset','undefined','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','VoiceDialReport','rawAttributes','type','key','model','query','keys','filters','attributes','intersection','fields','length','nolimit','limit','order','sort','where','merge','VIRTUAL','filter','options','count','includeAll','include','findAll','rows','catch','show','params','find','create','body','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end'];(function(_0x2910da,_0xf00c37){var _0x5453c5=function(_0x2713a7){while(--_0x2713a7){_0x2910da['push'](_0x2910da['shift']());}};_0x5453c5(++_0xf00c37);}(_0x4bf6,0x1a8));var _0x64bf=function(_0xe90f41,_0x1c97a5){_0xe90f41=_0xe90f41-0x0;var _0x26cf7f=_0x4bf6[_0xe90f41];return _0x26cf7f;};'use strict';var emlformat=require(_0x64bf('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x64bf('0x1'));var jsonpatch=require(_0x64bf('0x2'));var rp=require(_0x64bf('0x3'));var moment=require('moment');var BPromise=require(_0x64bf('0x4'));var Mustache=require(_0x64bf('0x5'));var util=require('util');var path=require(_0x64bf('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x64bf('0x7'));var _=require(_0x64bf('0x8'));var squel=require(_0x64bf('0x9'));var crypto=require(_0x64bf('0xa'));var jsforce=require(_0x64bf('0xb'));var deskjs=require(_0x64bf('0xc'));var toCsv=require('to-csv');var querystring=require(_0x64bf('0xd'));var Papa=require('papaparse');var Redis=require(_0x64bf('0xe'));var authService=require(_0x64bf('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x64bf('0x10'));var hardwareService=require(_0x64bf('0x11'));var logger=require('../../config/logger')(_0x64bf('0x12'));var utils=require(_0x64bf('0x13'));var config=require(_0x64bf('0x14'));var licenseUtil=require(_0x64bf('0x15'));var db=require(_0x64bf('0x16'))['db'];function respondWithStatusCode(_0x484847,_0x4ee4cc){_0x4ee4cc=_0x4ee4cc||0xcc;return function(_0x5ed1d7){if(_0x5ed1d7){return _0x484847[_0x64bf('0x17')](_0x4ee4cc);}return _0x484847[_0x64bf('0x18')](_0x4ee4cc)[_0x64bf('0x19')]();};}function respondWithResult(_0x521699,_0x119077){_0x119077=_0x119077||0xc8;return function(_0x2388f6){if(_0x2388f6){return _0x521699[_0x64bf('0x18')](_0x119077)[_0x64bf('0x1a')](_0x2388f6);}};}function respondWithFilteredResult(_0x4812a1,_0xbef71b){return function(_0x4a0920){if(_0x4a0920){var _0x163697=typeof _0xbef71b[_0x64bf('0x1b')]===_0x64bf('0x1c')&&typeof _0xbef71b['limit']==='undefined';var _0x575399=_0x4a0920['count'];var _0x2a9c31=_0x163697?0x0:_0xbef71b['offset'];var _0x109367=_0x163697?_0x4a0920['count']:_0xbef71b[_0x64bf('0x1b')]+_0xbef71b['limit'];var _0x3699c5;if(_0x109367>=_0x575399){_0x109367=_0x575399;_0x3699c5=0xc8;}else{_0x3699c5=0xce;}_0x4812a1[_0x64bf('0x18')](_0x3699c5);return _0x4812a1['set'](_0x64bf('0x1d'),_0x2a9c31+'-'+_0x109367+'/'+_0x575399)[_0x64bf('0x1a')](_0x4a0920);}return null;};}function patchUpdates(_0x5f5610){return function(_0x369fea){try{jsonpatch[_0x64bf('0x1e')](_0x369fea,_0x5f5610,!![]);}catch(_0x25590f){return BPromise[_0x64bf('0x1f')](_0x25590f);}return _0x369fea[_0x64bf('0x20')]();};}function saveUpdates(_0x503d54,_0x38d5fb){return function(_0x36327a){if(_0x36327a){return _0x36327a[_0x64bf('0x21')](_0x503d54)[_0x64bf('0x22')](function(_0x104498){return _0x104498;});}return null;};}function removeEntity(_0x5c46a3,_0x3b3bc9){return function(_0x1de2d2){if(_0x1de2d2){return _0x1de2d2[_0x64bf('0x23')]()[_0x64bf('0x22')](function(){_0x5c46a3[_0x64bf('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x15dd0d,_0x4fc75d){return function(_0x5bf225){if(!_0x5bf225){_0x15dd0d[_0x64bf('0x17')](0x194);}return _0x5bf225;};}function handleError(_0x70719d,_0x5a753f){_0x5a753f=_0x5a753f||0x1f4;return function(_0x4aa69f){logger[_0x64bf('0x24')](_0x4aa69f[_0x64bf('0x25')]);if(_0x4aa69f[_0x64bf('0x26')]){delete _0x4aa69f[_0x64bf('0x26')];}_0x70719d[_0x64bf('0x18')](_0x5a753f)[_0x64bf('0x27')](_0x4aa69f);};}exports[_0x64bf('0x28')]=function(_0x7fc87b,_0x34121c){var _0x282da3={},_0x230e6d={},_0x251fb1={'count':0x0,'rows':[]};var _0x36e102=_[_0x64bf('0x29')](db[_0x64bf('0x2a')][_0x64bf('0x2b')],function(_0x546327){return{'name':_0x546327['fieldName'],'type':_0x546327[_0x64bf('0x2c')][_0x64bf('0x2d')]};});_0x230e6d[_0x64bf('0x2e')]=_['map'](_0x36e102,_0x64bf('0x26'));_0x230e6d[_0x64bf('0x2f')]=_[_0x64bf('0x30')](_0x7fc87b[_0x64bf('0x2f')]);_0x230e6d[_0x64bf('0x31')]=_['intersection'](_0x230e6d[_0x64bf('0x2e')],_0x230e6d[_0x64bf('0x2f')]);_0x282da3[_0x64bf('0x32')]=_[_0x64bf('0x33')](_0x230e6d[_0x64bf('0x2e')],qs[_0x64bf('0x34')](_0x7fc87b[_0x64bf('0x2f')]['fields']));_0x282da3[_0x64bf('0x32')]=_0x282da3['attributes'][_0x64bf('0x35')]?_0x282da3[_0x64bf('0x32')]:_0x230e6d[_0x64bf('0x2e')];if(!_0x7fc87b[_0x64bf('0x2f')]['hasOwnProperty'](_0x64bf('0x36'))){_0x282da3['limit']=qs[_0x64bf('0x37')](_0x7fc87b[_0x64bf('0x2f')][_0x64bf('0x37')]);_0x282da3[_0x64bf('0x1b')]=qs[_0x64bf('0x1b')](_0x7fc87b[_0x64bf('0x2f')][_0x64bf('0x1b')]);}_0x282da3[_0x64bf('0x38')]=qs[_0x64bf('0x39')](_0x7fc87b['query'][_0x64bf('0x39')]);_0x282da3['where']=qs[_0x64bf('0x31')](_['pick'](_0x7fc87b[_0x64bf('0x2f')],_0x230e6d[_0x64bf('0x31')]),_0x36e102);if(_0x7fc87b[_0x64bf('0x2f')]['filter']){_0x282da3[_0x64bf('0x3a')]=_[_0x64bf('0x3b')](_0x282da3[_0x64bf('0x3a')],{'$or':_[_0x64bf('0x29')](_0x36e102,function(_0x53df0d){if(_0x53df0d[_0x64bf('0x2c')]!==_0x64bf('0x3c')){var _0x10ac09={};_0x10ac09[_0x53df0d['name']]={'$like':'%'+_0x7fc87b[_0x64bf('0x2f')][_0x64bf('0x3d')]+'%'};return _0x10ac09;}})});}_0x282da3=_[_0x64bf('0x3b')]({},_0x282da3,_0x7fc87b[_0x64bf('0x3e')]);var _0x268f79={'where':_0x282da3[_0x64bf('0x3a')]};return db[_0x64bf('0x2a')][_0x64bf('0x3f')](_0x268f79)[_0x64bf('0x22')](function(_0x24f422){_0x251fb1[_0x64bf('0x3f')]=_0x24f422;if(_0x7fc87b['query'][_0x64bf('0x40')]){_0x282da3[_0x64bf('0x41')]=[{'all':!![]}];}return db[_0x64bf('0x2a')][_0x64bf('0x42')](_0x282da3);})['then'](function(_0x4e522e){_0x251fb1[_0x64bf('0x43')]=_0x4e522e;return _0x251fb1;})[_0x64bf('0x22')](respondWithFilteredResult(_0x34121c,_0x282da3))[_0x64bf('0x44')](handleError(_0x34121c,null));};exports[_0x64bf('0x45')]=function(_0xffff49,_0x202b21){var _0x3ea9d3={'raw':!![],'where':{'id':_0xffff49[_0x64bf('0x46')]['id']}},_0x414608={};_0x414608[_0x64bf('0x2e')]=_['keys'](db[_0x64bf('0x2a')][_0x64bf('0x2b')]);_0x414608[_0x64bf('0x2f')]=_['keys'](_0xffff49['query']);_0x414608['filters']=_[_0x64bf('0x33')](_0x414608[_0x64bf('0x2e')],_0x414608[_0x64bf('0x2f')]);_0x3ea9d3['attributes']=_[_0x64bf('0x33')](_0x414608['model'],qs[_0x64bf('0x34')](_0xffff49[_0x64bf('0x2f')][_0x64bf('0x34')]));_0x3ea9d3[_0x64bf('0x32')]=_0x3ea9d3['attributes'][_0x64bf('0x35')]?_0x3ea9d3['attributes']:_0x414608[_0x64bf('0x2e')];if(_0xffff49[_0x64bf('0x2f')]['includeAll']){_0x3ea9d3[_0x64bf('0x41')]=[{'all':!![]}];}_0x3ea9d3=_['merge']({},_0x3ea9d3,_0xffff49[_0x64bf('0x3e')]);return db['VoiceDialReport'][_0x64bf('0x47')](_0x3ea9d3)[_0x64bf('0x22')](handleEntityNotFound(_0x202b21,null))['then'](respondWithResult(_0x202b21,null))[_0x64bf('0x44')](handleError(_0x202b21,null));};exports[_0x64bf('0x48')]=function(_0x20c63d,_0x2d648e){return db[_0x64bf('0x2a')][_0x64bf('0x48')](_0x20c63d[_0x64bf('0x49')],{})[_0x64bf('0x22')](respondWithResult(_0x2d648e,0xc9))[_0x64bf('0x44')](handleError(_0x2d648e,null));};exports[_0x64bf('0x21')]=function(_0x4fc463,_0x3864c5){if(_0x4fc463[_0x64bf('0x49')]['id']){delete _0x4fc463[_0x64bf('0x49')]['id'];}return db['VoiceDialReport']['find']({'where':{'id':_0x4fc463[_0x64bf('0x46')]['id']}})[_0x64bf('0x22')](handleEntityNotFound(_0x3864c5,null))['then'](saveUpdates(_0x4fc463[_0x64bf('0x49')],null))[_0x64bf('0x22')](respondWithResult(_0x3864c5,null))['catch'](handleError(_0x3864c5,null));};exports['destroy']=function(_0x370642,_0x3e8147){return db[_0x64bf('0x2a')]['find']({'where':{'id':_0x370642['params']['id']}})[_0x64bf('0x22')](handleEntityNotFound(_0x3e8147,null))['then'](removeEntity(_0x3e8147,null))[_0x64bf('0x44')](handleError(_0x3e8147,null));};exports[_0x64bf('0x4a')]=function(_0x26cf60,_0x5b59b7){return db[_0x64bf('0x2a')][_0x64bf('0x4a')]()[_0x64bf('0x22')](respondWithResult(_0x5b59b7,null))[_0x64bf('0x44')](handleError(_0x5b59b7,null));};