Built motion from commit 994c64e1.|2.6.1
[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 _0x0b9f=['name','send','index','map','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','VoiceDialReport','count','include','findAll','rows','catch','show','params','rawAttributes','includeAll','create','body','find','describe','rimraf','fast-json-patch','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','limit','json','apply','reject','save','update','then','destroy','error','stack'];(function(_0x20f8f1,_0x3fb8fa){var _0xdec9ce=function(_0x4f8964){while(--_0x4f8964){_0x20f8f1['push'](_0x20f8f1['shift']());}};_0xdec9ce(++_0x3fb8fa);}(_0x0b9f,0x106));var _0xf0b9=function(_0x2db6d4,_0x294c9e){_0x2db6d4=_0x2db6d4-0x0;var _0xd947fa=_0x0b9f[_0x2db6d4];return _0xd947fa;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf0b9('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf0b9('0x1'));var rp=require('request-promise');var moment=require(_0xf0b9('0x2'));var BPromise=require(_0xf0b9('0x3'));var Mustache=require(_0xf0b9('0x4'));var util=require('util');var path=require('path');var sox=require(_0xf0b9('0x5'));var csv=require(_0xf0b9('0x6'));var ejs=require(_0xf0b9('0x7'));var fs=require('fs');var fs_extra=require(_0xf0b9('0x8'));var _=require(_0xf0b9('0x9'));var squel=require(_0xf0b9('0xa'));var crypto=require(_0xf0b9('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf0b9('0xc'));var toCsv=require(_0xf0b9('0x6'));var querystring=require(_0xf0b9('0xd'));var Papa=require(_0xf0b9('0xe'));var Redis=require(_0xf0b9('0xf'));var authService=require(_0xf0b9('0x10'));var qs=require(_0xf0b9('0x11'));var as=require(_0xf0b9('0x12'));var hardwareService=require(_0xf0b9('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xf0b9('0x14'));var config=require(_0xf0b9('0x15'));var licenseUtil=require(_0xf0b9('0x16'));var db=require(_0xf0b9('0x17'))['db'];function respondWithStatusCode(_0x2ac343,_0x4a3e47){_0x4a3e47=_0x4a3e47||0xcc;return function(_0x11eb4d){if(_0x11eb4d){return _0x2ac343[_0xf0b9('0x18')](_0x4a3e47);}return _0x2ac343[_0xf0b9('0x19')](_0x4a3e47)[_0xf0b9('0x1a')]();};}function respondWithResult(_0x1ffedd,_0x5b07e6){_0x5b07e6=_0x5b07e6||0xc8;return function(_0x2e30df){if(_0x2e30df){return _0x1ffedd[_0xf0b9('0x19')](_0x5b07e6)['json'](_0x2e30df);}};}function respondWithFilteredResult(_0x48a710,_0x5866ce){return function(_0x505434){if(_0x505434){var _0x5598ac=typeof _0x5866ce[_0xf0b9('0x1b')]==='undefined'&&typeof _0x5866ce['limit']==='undefined';var _0x133543=_0x505434['count'];var _0x251ded=_0x5598ac?0x0:_0x5866ce['offset'];var _0x41fdd6=_0x5598ac?_0x505434['count']:_0x5866ce[_0xf0b9('0x1b')]+_0x5866ce[_0xf0b9('0x1c')];var _0x1dca8c;if(_0x41fdd6>=_0x133543){_0x41fdd6=_0x133543;_0x1dca8c=0xc8;}else{_0x1dca8c=0xce;}_0x48a710[_0xf0b9('0x19')](_0x1dca8c);return _0x48a710['set']('Content-Range',_0x251ded+'-'+_0x41fdd6+'/'+_0x133543)[_0xf0b9('0x1d')](_0x505434);}return null;};}function patchUpdates(_0x26cf8e){return function(_0x21e275){try{jsonpatch[_0xf0b9('0x1e')](_0x21e275,_0x26cf8e,!![]);}catch(_0x1d37d2){return BPromise[_0xf0b9('0x1f')](_0x1d37d2);}return _0x21e275[_0xf0b9('0x20')]();};}function saveUpdates(_0x39d19b,_0x38c6c5){return function(_0x45a41e){if(_0x45a41e){return _0x45a41e[_0xf0b9('0x21')](_0x39d19b)[_0xf0b9('0x22')](function(_0x2dbb07){return _0x2dbb07;});}return null;};}function removeEntity(_0x5c4a79,_0x27bc8b){return function(_0x205e02){if(_0x205e02){return _0x205e02[_0xf0b9('0x23')]()[_0xf0b9('0x22')](function(){_0x5c4a79[_0xf0b9('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x28eb6f,_0x361ae7){return function(_0x3ac90e){if(!_0x3ac90e){_0x28eb6f['sendStatus'](0x194);}return _0x3ac90e;};}function handleError(_0x44d21d,_0x3891e4){_0x3891e4=_0x3891e4||0x1f4;return function(_0x5cc983){logger[_0xf0b9('0x24')](_0x5cc983[_0xf0b9('0x25')]);if(_0x5cc983[_0xf0b9('0x26')]){delete _0x5cc983[_0xf0b9('0x26')];}_0x44d21d[_0xf0b9('0x19')](_0x3891e4)[_0xf0b9('0x27')](_0x5cc983);};}exports[_0xf0b9('0x28')]=function(_0x4a1528,_0xf6eaae){var _0x5c1d12={},_0x4e87c3={},_0x2565e9={'count':0x0,'rows':[]};var _0xc6b2be=_[_0xf0b9('0x29')](db['VoiceDialReport']['rawAttributes'],function(_0x51ad59){return{'name':_0x51ad59['fieldName'],'type':_0x51ad59[_0xf0b9('0x2a')]['key']};});_0x4e87c3[_0xf0b9('0x2b')]=_[_0xf0b9('0x29')](_0xc6b2be,_0xf0b9('0x26'));_0x4e87c3[_0xf0b9('0x2c')]=_[_0xf0b9('0x2d')](_0x4a1528['query']);_0x4e87c3[_0xf0b9('0x2e')]=_[_0xf0b9('0x2f')](_0x4e87c3['model'],_0x4e87c3[_0xf0b9('0x2c')]);_0x5c1d12[_0xf0b9('0x30')]=_[_0xf0b9('0x2f')](_0x4e87c3[_0xf0b9('0x2b')],qs['fields'](_0x4a1528[_0xf0b9('0x2c')][_0xf0b9('0x31')]));_0x5c1d12[_0xf0b9('0x30')]=_0x5c1d12['attributes'][_0xf0b9('0x32')]?_0x5c1d12[_0xf0b9('0x30')]:_0x4e87c3[_0xf0b9('0x2b')];if(!_0x4a1528[_0xf0b9('0x2c')][_0xf0b9('0x33')](_0xf0b9('0x34'))){_0x5c1d12['limit']=qs[_0xf0b9('0x1c')](_0x4a1528[_0xf0b9('0x2c')]['limit']);_0x5c1d12[_0xf0b9('0x1b')]=qs[_0xf0b9('0x1b')](_0x4a1528['query'][_0xf0b9('0x1b')]);}_0x5c1d12[_0xf0b9('0x35')]=qs['sort'](_0x4a1528['query'][_0xf0b9('0x36')]);_0x5c1d12[_0xf0b9('0x37')]=qs[_0xf0b9('0x2e')](_[_0xf0b9('0x38')](_0x4a1528[_0xf0b9('0x2c')],_0x4e87c3[_0xf0b9('0x2e')]),_0xc6b2be);if(_0x4a1528['query'][_0xf0b9('0x39')]){_0x5c1d12[_0xf0b9('0x37')]=_[_0xf0b9('0x3a')](_0x5c1d12['where'],{'$or':_[_0xf0b9('0x29')](_0xc6b2be,function(_0xa2f8ab){if(_0xa2f8ab[_0xf0b9('0x2a')]!==_0xf0b9('0x3b')){var _0x42e595={};_0x42e595[_0xa2f8ab['name']]={'$like':'%'+_0x4a1528[_0xf0b9('0x2c')]['filter']+'%'};return _0x42e595;}})});}_0x5c1d12=_[_0xf0b9('0x3a')]({},_0x5c1d12,_0x4a1528[_0xf0b9('0x3c')]);var _0x45b857={'where':_0x5c1d12[_0xf0b9('0x37')]};return db[_0xf0b9('0x3d')]['count'](_0x45b857)[_0xf0b9('0x22')](function(_0x597c23){_0x2565e9[_0xf0b9('0x3e')]=_0x597c23;if(_0x4a1528[_0xf0b9('0x2c')]['includeAll']){_0x5c1d12[_0xf0b9('0x3f')]=[{'all':!![]}];}return db[_0xf0b9('0x3d')][_0xf0b9('0x40')](_0x5c1d12);})['then'](function(_0x4baa83){_0x2565e9[_0xf0b9('0x41')]=_0x4baa83;return _0x2565e9;})[_0xf0b9('0x22')](respondWithFilteredResult(_0xf6eaae,_0x5c1d12))[_0xf0b9('0x42')](handleError(_0xf6eaae,null));};exports[_0xf0b9('0x43')]=function(_0x1bcbec,_0x4dd28a){var _0x586693={'raw':!![],'where':{'id':_0x1bcbec[_0xf0b9('0x44')]['id']}},_0x3fec25={};_0x3fec25[_0xf0b9('0x2b')]=_[_0xf0b9('0x2d')](db[_0xf0b9('0x3d')][_0xf0b9('0x45')]);_0x3fec25[_0xf0b9('0x2c')]=_[_0xf0b9('0x2d')](_0x1bcbec[_0xf0b9('0x2c')]);_0x3fec25[_0xf0b9('0x2e')]=_[_0xf0b9('0x2f')](_0x3fec25['model'],_0x3fec25[_0xf0b9('0x2c')]);_0x586693[_0xf0b9('0x30')]=_[_0xf0b9('0x2f')](_0x3fec25['model'],qs[_0xf0b9('0x31')](_0x1bcbec[_0xf0b9('0x2c')][_0xf0b9('0x31')]));_0x586693[_0xf0b9('0x30')]=_0x586693['attributes'][_0xf0b9('0x32')]?_0x586693[_0xf0b9('0x30')]:_0x3fec25[_0xf0b9('0x2b')];if(_0x1bcbec[_0xf0b9('0x2c')][_0xf0b9('0x46')]){_0x586693[_0xf0b9('0x3f')]=[{'all':!![]}];}_0x586693=_[_0xf0b9('0x3a')]({},_0x586693,_0x1bcbec['options']);return db[_0xf0b9('0x3d')]['find'](_0x586693)[_0xf0b9('0x22')](handleEntityNotFound(_0x4dd28a,null))['then'](respondWithResult(_0x4dd28a,null))[_0xf0b9('0x42')](handleError(_0x4dd28a,null));};exports[_0xf0b9('0x47')]=function(_0x320ffe,_0xbbce85){return db[_0xf0b9('0x3d')][_0xf0b9('0x47')](_0x320ffe[_0xf0b9('0x48')],{})[_0xf0b9('0x22')](respondWithResult(_0xbbce85,0xc9))[_0xf0b9('0x42')](handleError(_0xbbce85,null));};exports[_0xf0b9('0x21')]=function(_0x577d99,_0xd5e590){if(_0x577d99['body']['id']){delete _0x577d99[_0xf0b9('0x48')]['id'];}return db[_0xf0b9('0x3d')][_0xf0b9('0x49')]({'where':{'id':_0x577d99[_0xf0b9('0x44')]['id']}})['then'](handleEntityNotFound(_0xd5e590,null))[_0xf0b9('0x22')](saveUpdates(_0x577d99[_0xf0b9('0x48')],null))[_0xf0b9('0x22')](respondWithResult(_0xd5e590,null))[_0xf0b9('0x42')](handleError(_0xd5e590,null));};exports[_0xf0b9('0x23')]=function(_0x1afc7e,_0x176dd0){return db['VoiceDialReport'][_0xf0b9('0x49')]({'where':{'id':_0x1afc7e['params']['id']}})['then'](handleEntityNotFound(_0x176dd0,null))[_0xf0b9('0x22')](removeEntity(_0x176dd0,null))['catch'](handleError(_0x176dd0,null));};exports[_0xf0b9('0x4a')]=function(_0x3bf21f,_0x3d9077){return db[_0xf0b9('0x3d')]['describe']()[_0xf0b9('0x22')](respondWithResult(_0x3d9077,null))[_0xf0b9('0x42')](handleError(_0x3d9077,null));};