b7d98c98c11a21fd37c44b7a4ea08bf2a850569f
[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 _0x8b2e=['find','create','body','catch','describe','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','sendStatus','status','json','offset','limit','undefined','count','Content-Range','apply','reject','save','update','then','destroy','end','error','send','index','map','VoiceDialReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','order','sort','pick','where','VIRTUAL','name','filter','merge','includeAll','include','show','params'];(function(_0x4f43e8,_0xbc8cb6){var _0x2a483c=function(_0x5cbf6c){while(--_0x5cbf6c){_0x4f43e8['push'](_0x4f43e8['shift']());}};_0x2a483c(++_0xbc8cb6);}(_0x8b2e,0x163));var _0xe8b2=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x8b2e[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xe8b2('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xe8b2('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe8b2('0x2'));var moment=require(_0xe8b2('0x3'));var BPromise=require(_0xe8b2('0x4'));var Mustache=require(_0xe8b2('0x5'));var util=require(_0xe8b2('0x6'));var path=require(_0xe8b2('0x7'));var sox=require(_0xe8b2('0x8'));var csv=require(_0xe8b2('0x9'));var ejs=require(_0xe8b2('0xa'));var fs=require('fs');var fs_extra=require(_0xe8b2('0xb'));var _=require(_0xe8b2('0xc'));var squel=require(_0xe8b2('0xd'));var crypto=require('crypto');var jsforce=require(_0xe8b2('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xe8b2('0x9'));var querystring=require('querystring');var Papa=require(_0xe8b2('0xf'));var Redis=require(_0xe8b2('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xe8b2('0x11'));var hardwareService=require(_0xe8b2('0x12'));var logger=require('../../config/logger')(_0xe8b2('0x13'));var utils=require('../../config/utils');var config=require(_0xe8b2('0x14'));var licenseUtil=require(_0xe8b2('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x28e667,_0x4ca674){_0x4ca674=_0x4ca674||0xcc;return function(_0x57cdae){if(_0x57cdae){return _0x28e667[_0xe8b2('0x16')](_0x4ca674);}return _0x28e667[_0xe8b2('0x17')](_0x4ca674)['end']();};}function respondWithResult(_0x1ccb0d,_0x32f6dd){_0x32f6dd=_0x32f6dd||0xc8;return function(_0x4b58a0){if(_0x4b58a0){return _0x1ccb0d[_0xe8b2('0x17')](_0x32f6dd)[_0xe8b2('0x18')](_0x4b58a0);}};}function respondWithFilteredResult(_0x676555,_0x305482){return function(_0x1f0269){if(_0x1f0269){var _0x38b4b4=typeof _0x305482[_0xe8b2('0x19')]==='undefined'&&typeof _0x305482[_0xe8b2('0x1a')]===_0xe8b2('0x1b');var _0x3c1ccd=_0x1f0269[_0xe8b2('0x1c')];var _0x344d41=_0x38b4b4?0x0:_0x305482[_0xe8b2('0x19')];var _0xfebb1a=_0x38b4b4?_0x1f0269[_0xe8b2('0x1c')]:_0x305482[_0xe8b2('0x19')]+_0x305482['limit'];var _0x33e7f5;if(_0xfebb1a>=_0x3c1ccd){_0xfebb1a=_0x3c1ccd;_0x33e7f5=0xc8;}else{_0x33e7f5=0xce;}_0x676555[_0xe8b2('0x17')](_0x33e7f5);return _0x676555['set'](_0xe8b2('0x1d'),_0x344d41+'-'+_0xfebb1a+'/'+_0x3c1ccd)[_0xe8b2('0x18')](_0x1f0269);}return null;};}function patchUpdates(_0x2b9a71){return function(_0x443a54){try{jsonpatch[_0xe8b2('0x1e')](_0x443a54,_0x2b9a71,!![]);}catch(_0x14058f){return BPromise[_0xe8b2('0x1f')](_0x14058f);}return _0x443a54[_0xe8b2('0x20')]();};}function saveUpdates(_0x1ca666,_0x4b3766){return function(_0x2da6e2){if(_0x2da6e2){return _0x2da6e2[_0xe8b2('0x21')](_0x1ca666)[_0xe8b2('0x22')](function(_0x473bc2){return _0x473bc2;});}return null;};}function removeEntity(_0x44ac78,_0x141264){return function(_0x27d8dd){if(_0x27d8dd){return _0x27d8dd[_0xe8b2('0x23')]()[_0xe8b2('0x22')](function(){_0x44ac78[_0xe8b2('0x17')](0xcc)[_0xe8b2('0x24')]();});}};}function handleEntityNotFound(_0x42c65b,_0x5e6a0c){return function(_0x25dfe0){if(!_0x25dfe0){_0x42c65b[_0xe8b2('0x16')](0x194);}return _0x25dfe0;};}function handleError(_0x1e2b69,_0x5db476){_0x5db476=_0x5db476||0x1f4;return function(_0x14141d){logger[_0xe8b2('0x25')](_0x14141d['stack']);if(_0x14141d['name']){delete _0x14141d['name'];}_0x1e2b69[_0xe8b2('0x17')](_0x5db476)[_0xe8b2('0x26')](_0x14141d);};}exports[_0xe8b2('0x27')]=function(_0xab0587,_0x22ba99){var _0x246ef6={},_0x5cbb4a={},_0x4d463b={'count':0x0,'rows':[]};var _0x11fdb5=_[_0xe8b2('0x28')](db[_0xe8b2('0x29')][_0xe8b2('0x2a')],function(_0x1ff071){return{'name':_0x1ff071[_0xe8b2('0x2b')],'type':_0x1ff071[_0xe8b2('0x2c')]['key']};});_0x5cbb4a[_0xe8b2('0x2d')]=_[_0xe8b2('0x28')](_0x11fdb5,'name');_0x5cbb4a[_0xe8b2('0x2e')]=_[_0xe8b2('0x2f')](_0xab0587[_0xe8b2('0x2e')]);_0x5cbb4a[_0xe8b2('0x30')]=_[_0xe8b2('0x31')](_0x5cbb4a[_0xe8b2('0x2d')],_0x5cbb4a[_0xe8b2('0x2e')]);_0x246ef6[_0xe8b2('0x32')]=_[_0xe8b2('0x31')](_0x5cbb4a[_0xe8b2('0x2d')],qs[_0xe8b2('0x33')](_0xab0587['query']['fields']));_0x246ef6['attributes']=_0x246ef6[_0xe8b2('0x32')][_0xe8b2('0x34')]?_0x246ef6['attributes']:_0x5cbb4a[_0xe8b2('0x2d')];if(!_0xab0587[_0xe8b2('0x2e')]['hasOwnProperty']('nolimit')){_0x246ef6[_0xe8b2('0x1a')]=qs[_0xe8b2('0x1a')](_0xab0587[_0xe8b2('0x2e')][_0xe8b2('0x1a')]);_0x246ef6[_0xe8b2('0x19')]=qs[_0xe8b2('0x19')](_0xab0587[_0xe8b2('0x2e')][_0xe8b2('0x19')]);}_0x246ef6[_0xe8b2('0x35')]=qs[_0xe8b2('0x36')](_0xab0587[_0xe8b2('0x2e')][_0xe8b2('0x36')]);_0x246ef6['where']=qs['filters'](_[_0xe8b2('0x37')](_0xab0587['query'],_0x5cbb4a[_0xe8b2('0x30')]),_0x11fdb5);if(_0xab0587[_0xe8b2('0x2e')]['filter']){_0x246ef6['where']=_['merge'](_0x246ef6[_0xe8b2('0x38')],{'$or':_['map'](_0x11fdb5,function(_0x174fd9){if(_0x174fd9[_0xe8b2('0x2c')]!==_0xe8b2('0x39')){var _0x43145b={};_0x43145b[_0x174fd9[_0xe8b2('0x3a')]]={'$like':'%'+_0xab0587[_0xe8b2('0x2e')][_0xe8b2('0x3b')]+'%'};return _0x43145b;}})});}_0x246ef6=_[_0xe8b2('0x3c')]({},_0x246ef6,_0xab0587['options']);var _0x2c4e30={'where':_0x246ef6[_0xe8b2('0x38')]};return db['VoiceDialReport'][_0xe8b2('0x1c')](_0x2c4e30)['then'](function(_0x35759b){_0x4d463b[_0xe8b2('0x1c')]=_0x35759b;if(_0xab0587[_0xe8b2('0x2e')][_0xe8b2('0x3d')]){_0x246ef6[_0xe8b2('0x3e')]=[{'all':!![]}];}return db[_0xe8b2('0x29')]['findAll'](_0x246ef6);})[_0xe8b2('0x22')](function(_0x3a5114){_0x4d463b['rows']=_0x3a5114;return _0x4d463b;})[_0xe8b2('0x22')](respondWithFilteredResult(_0x22ba99,_0x246ef6))['catch'](handleError(_0x22ba99,null));};exports[_0xe8b2('0x3f')]=function(_0x2f7723,_0x281bfc){var _0x551989={'raw':!![],'where':{'id':_0x2f7723[_0xe8b2('0x40')]['id']}},_0x5707ff={};_0x5707ff[_0xe8b2('0x2d')]=_[_0xe8b2('0x2f')](db['VoiceDialReport'][_0xe8b2('0x2a')]);_0x5707ff[_0xe8b2('0x2e')]=_['keys'](_0x2f7723['query']);_0x5707ff[_0xe8b2('0x30')]=_[_0xe8b2('0x31')](_0x5707ff['model'],_0x5707ff[_0xe8b2('0x2e')]);_0x551989[_0xe8b2('0x32')]=_[_0xe8b2('0x31')](_0x5707ff[_0xe8b2('0x2d')],qs['fields'](_0x2f7723[_0xe8b2('0x2e')][_0xe8b2('0x33')]));_0x551989[_0xe8b2('0x32')]=_0x551989['attributes'][_0xe8b2('0x34')]?_0x551989[_0xe8b2('0x32')]:_0x5707ff['model'];if(_0x2f7723[_0xe8b2('0x2e')]['includeAll']){_0x551989[_0xe8b2('0x3e')]=[{'all':!![]}];}_0x551989=_[_0xe8b2('0x3c')]({},_0x551989,_0x2f7723['options']);return db[_0xe8b2('0x29')][_0xe8b2('0x41')](_0x551989)['then'](handleEntityNotFound(_0x281bfc,null))[_0xe8b2('0x22')](respondWithResult(_0x281bfc,null))['catch'](handleError(_0x281bfc,null));};exports[_0xe8b2('0x42')]=function(_0x28f626,_0x36c604){return db[_0xe8b2('0x29')][_0xe8b2('0x42')](_0x28f626[_0xe8b2('0x43')],{})[_0xe8b2('0x22')](respondWithResult(_0x36c604,0xc9))[_0xe8b2('0x44')](handleError(_0x36c604,null));};exports[_0xe8b2('0x21')]=function(_0x57e4cb,_0x1703ab){if(_0x57e4cb['body']['id']){delete _0x57e4cb[_0xe8b2('0x43')]['id'];}return db[_0xe8b2('0x29')][_0xe8b2('0x41')]({'where':{'id':_0x57e4cb[_0xe8b2('0x40')]['id']}})[_0xe8b2('0x22')](handleEntityNotFound(_0x1703ab,null))[_0xe8b2('0x22')](saveUpdates(_0x57e4cb[_0xe8b2('0x43')],null))['then'](respondWithResult(_0x1703ab,null))['catch'](handleError(_0x1703ab,null));};exports[_0xe8b2('0x23')]=function(_0x119d99,_0x27d182){return db[_0xe8b2('0x29')]['find']({'where':{'id':_0x119d99[_0xe8b2('0x40')]['id']}})[_0xe8b2('0x22')](handleEntityNotFound(_0x27d182,null))[_0xe8b2('0x22')](removeEntity(_0x27d182,null))[_0xe8b2('0x44')](handleError(_0x27d182,null));};exports['describe']=function(_0x44138c,_0x1202e0){return db[_0xe8b2('0x29')][_0xe8b2('0x45')]()['then'](respondWithResult(_0x1202e0,null))[_0xe8b2('0x44')](handleError(_0x1202e0,null));};