34f9cdb66e679ff636f1c56284d7fa0d3b8e41b2
[motion2.git] / server / api / voiceAgentReport / voiceAgentReport.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 _0xc89f=['create','body','params','describe','html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','send','index','VoiceAgentReport','rawAttributes','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','limit','order','where','filters','pick','filter','merge','type','key','VIRTUAL','options','includeAll','include','rows','catch','show','find'];(function(_0x55d85b,_0x4a39d0){var _0x183bb0=function(_0x30494f){while(--_0x30494f){_0x55d85b['push'](_0x55d85b['shift']());}};_0x183bb0(++_0x4a39d0);}(_0xc89f,0x96));var _0xfc89=function(_0x420a02,_0x91fee){_0x420a02=_0x420a02-0x0;var _0x46ad48=_0xc89f[_0x420a02];return _0x46ad48;};'use strict';var pdf=require(_0xfc89('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xfc89('0x1'));var zipdir=require(_0xfc89('0x2'));var jsonpatch=require(_0xfc89('0x3'));var rp=require('request-promise');var moment=require(_0xfc89('0x4'));var BPromise=require(_0xfc89('0x5'));var Mustache=require('mustache');var util=require(_0xfc89('0x6'));var path=require(_0xfc89('0x7'));var sox=require('sox');var csv=require(_0xfc89('0x8'));var ejs=require(_0xfc89('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xfc89('0xa'));var crypto=require(_0xfc89('0xb'));var jsforce=require(_0xfc89('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xfc89('0x8'));var querystring=require(_0xfc89('0xd'));var Papa=require(_0xfc89('0xe'));var Redis=require(_0xfc89('0xf'));var authService=require(_0xfc89('0x10'));var qs=require(_0xfc89('0x11'));var hardwareService=require(_0xfc89('0x12'));var logger=require(_0xfc89('0x13'))(_0xfc89('0x14'));var utils=require(_0xfc89('0x15'));var config=require(_0xfc89('0x16'));var db=require(_0xfc89('0x17'))['db'];function respondWithStatusCode(_0x1d45f4,_0x329cb0){_0x329cb0=_0x329cb0||0xcc;return function(_0x382d74){if(_0x382d74){return _0x1d45f4['sendStatus'](_0x329cb0);}return _0x1d45f4[_0xfc89('0x18')](_0x329cb0)[_0xfc89('0x19')]();};}function respondWithResult(_0x56a0fb,_0x382b0b){_0x382b0b=_0x382b0b||0xc8;return function(_0x1e4b02){if(_0x1e4b02){return _0x56a0fb[_0xfc89('0x18')](_0x382b0b)[_0xfc89('0x1a')](_0x1e4b02);}};}function respondWithFilteredResult(_0x4811dc,_0x9db918){return function(_0x4d6286){if(_0x4d6286){var _0x263832=_0x4d6286[_0xfc89('0x1b')],_0x3ccc95=_0x9db918[_0xfc89('0x1c')],_0x1ca04d=_0x9db918['offset']+_0x9db918['limit'],_0x5ef01e;if(_0x1ca04d>=_0x263832){_0x1ca04d=_0x263832;_0x5ef01e=0xc8;}else{_0x5ef01e=0xce;}_0x4811dc[_0xfc89('0x18')](_0x5ef01e);return _0x4811dc[_0xfc89('0x1d')](_0xfc89('0x1e'),_0x3ccc95+'-'+_0x1ca04d+'/'+_0x263832)['json'](_0x4d6286);}return null;};}function patchUpdates(_0x1ee097){return function(_0x53f3a0){try{jsonpatch[_0xfc89('0x1f')](_0x53f3a0,_0x1ee097,!![]);}catch(_0x10033e){return BPromise[_0xfc89('0x20')](_0x10033e);}return _0x53f3a0[_0xfc89('0x21')]();};}function saveUpdates(_0x35f641,_0x163dba){return function(_0x35ffb3){if(_0x35ffb3){return _0x35ffb3[_0xfc89('0x22')](_0x35f641)[_0xfc89('0x23')](function(_0x1a9334){return _0x1a9334;});}return null;};}function removeEntity(_0xaba2bd,_0x2d0eed){return function(_0x5108fb){if(_0x5108fb){return _0x5108fb[_0xfc89('0x24')]()[_0xfc89('0x23')](function(){_0xaba2bd[_0xfc89('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x17ad60,_0x12cb72){return function(_0x4a71f8){if(!_0x4a71f8){_0x17ad60[_0xfc89('0x25')](0x194);}return _0x4a71f8;};}function handleError(_0x5846c1,_0x4b3cdf){_0x4b3cdf=_0x4b3cdf||0x1f4;return function(_0x5490da){logger[_0xfc89('0x26')](_0x5490da[_0xfc89('0x27')]);if(_0x5490da['name']){delete _0x5490da['name'];}_0x5846c1[_0xfc89('0x18')](_0x4b3cdf)[_0xfc89('0x28')](_0x5490da);};}exports[_0xfc89('0x29')]=function(_0x1e6d80,_0x2a831b){var _0x2aa4f4={},_0x1f705b={},_0xc456e6={'count':0x0,'rows':[]};var _0x5ac400=db[_0xfc89('0x2a')][_0xfc89('0x2b')];_0x1f705b[_0xfc89('0x2c')]=_['keys'](_0x5ac400);_0x1f705b[_0xfc89('0x2d')]=_[_0xfc89('0x2e')](_0x1e6d80[_0xfc89('0x2d')]);_0x1f705b['filters']=_['intersection'](_0x1f705b['model'],_0x1f705b[_0xfc89('0x2d')]);_0x2aa4f4[_0xfc89('0x2f')]=_[_0xfc89('0x30')](_0x1f705b[_0xfc89('0x2c')],qs[_0xfc89('0x31')](_0x1e6d80[_0xfc89('0x2d')][_0xfc89('0x31')]));_0x2aa4f4[_0xfc89('0x2f')]=_0x2aa4f4[_0xfc89('0x2f')][_0xfc89('0x32')]?_0x2aa4f4[_0xfc89('0x2f')]:_0x1f705b[_0xfc89('0x2c')];if(!_0x1e6d80[_0xfc89('0x2d')][_0xfc89('0x33')]('nolimit')){_0x2aa4f4['limit']=qs[_0xfc89('0x34')](_0x1e6d80['query'][_0xfc89('0x34')]);_0x2aa4f4[_0xfc89('0x1c')]=qs['offset'](_0x1e6d80[_0xfc89('0x2d')][_0xfc89('0x1c')]);}_0x2aa4f4[_0xfc89('0x35')]=qs['sort'](_0x1e6d80[_0xfc89('0x2d')]['sort']);_0x2aa4f4[_0xfc89('0x36')]=qs[_0xfc89('0x37')](_[_0xfc89('0x38')](_0x1e6d80[_0xfc89('0x2d')],_0x1f705b[_0xfc89('0x37')]));if(_0x1e6d80['query'][_0xfc89('0x39')]){_0x2aa4f4[_0xfc89('0x36')]=_[_0xfc89('0x3a')](_0x2aa4f4[_0xfc89('0x36')],{'$or':_['map'](_0x5ac400,function(_0x193733){if(_0x193733[_0xfc89('0x3b')][_0xfc89('0x3c')]!==_0xfc89('0x3d')){var _0x2f92e8={};_0x2f92e8[_0x193733['field']]={'$like':'%'+_0x1e6d80[_0xfc89('0x2d')][_0xfc89('0x39')]+'%'};return _0x2f92e8;}})});}_0x2aa4f4=_[_0xfc89('0x3a')]({},_0x2aa4f4,_0x1e6d80[_0xfc89('0x3e')]);var _0x1202f6={'where':_0x2aa4f4[_0xfc89('0x36')]};return db[_0xfc89('0x2a')][_0xfc89('0x1b')](_0x1202f6)[_0xfc89('0x23')](function(_0x1c68a4){_0xc456e6[_0xfc89('0x1b')]=_0x1c68a4;if(_0x1e6d80[_0xfc89('0x2d')][_0xfc89('0x3f')]){_0x2aa4f4[_0xfc89('0x40')]=[{'all':!![]}];}return db['VoiceAgentReport']['findAll'](_0x2aa4f4);})[_0xfc89('0x23')](function(_0x166985){_0xc456e6[_0xfc89('0x41')]=_0x166985;return _0xc456e6;})[_0xfc89('0x23')](respondWithFilteredResult(_0x2a831b,_0x2aa4f4))[_0xfc89('0x42')](handleError(_0x2a831b,null));};exports[_0xfc89('0x43')]=function(_0x1ac234,_0x197f3d){var _0x49030c={'raw':![],'where':{'id':_0x1ac234['params']['id']}},_0x43bdc4={};_0x43bdc4[_0xfc89('0x2c')]=_[_0xfc89('0x2e')](db['VoiceAgentReport']['rawAttributes']);_0x43bdc4[_0xfc89('0x2d')]=_['keys'](_0x1ac234[_0xfc89('0x2d')]);_0x43bdc4[_0xfc89('0x37')]=_[_0xfc89('0x30')](_0x43bdc4[_0xfc89('0x2c')],_0x43bdc4['query']);_0x49030c['attributes']=_[_0xfc89('0x30')](_0x43bdc4['model'],qs[_0xfc89('0x31')](_0x1ac234[_0xfc89('0x2d')]['fields']));_0x49030c['attributes']=_0x49030c[_0xfc89('0x2f')]['length']?_0x49030c[_0xfc89('0x2f')]:_0x43bdc4[_0xfc89('0x2c')];if(_0x1ac234[_0xfc89('0x2d')][_0xfc89('0x3f')]){_0x49030c[_0xfc89('0x40')]=[{'all':!![]}];}_0x49030c=_[_0xfc89('0x3a')]({},_0x49030c,_0x1ac234[_0xfc89('0x3e')]);return db['VoiceAgentReport'][_0xfc89('0x44')](_0x49030c)[_0xfc89('0x23')](handleEntityNotFound(_0x197f3d,null))[_0xfc89('0x23')](respondWithResult(_0x197f3d,null))[_0xfc89('0x42')](handleError(_0x197f3d,null));};exports[_0xfc89('0x45')]=function(_0x3053d7,_0x5b09b4){return db[_0xfc89('0x2a')]['create'](_0x3053d7[_0xfc89('0x46')],{})[_0xfc89('0x23')](respondWithResult(_0x5b09b4,0xc9))[_0xfc89('0x42')](handleError(_0x5b09b4,null));};exports[_0xfc89('0x22')]=function(_0x5d7e68,_0xe9480c){if(_0x5d7e68['body']['id']){delete _0x5d7e68[_0xfc89('0x46')]['id'];}return db[_0xfc89('0x2a')][_0xfc89('0x44')]({'where':{'id':_0x5d7e68[_0xfc89('0x47')]['id']}})[_0xfc89('0x23')](handleEntityNotFound(_0xe9480c,null))[_0xfc89('0x23')](saveUpdates(_0x5d7e68[_0xfc89('0x46')],null))['then'](respondWithResult(_0xe9480c,null))[_0xfc89('0x42')](handleError(_0xe9480c,null));};exports[_0xfc89('0x24')]=function(_0x4c82d4,_0x397e53){return db[_0xfc89('0x2a')]['find']({'where':{'id':_0x4c82d4['params']['id']}})[_0xfc89('0x23')](handleEntityNotFound(_0x397e53,null))[_0xfc89('0x23')](removeEntity(_0x397e53,null))[_0xfc89('0x42')](handleError(_0x397e53,null));};exports[_0xfc89('0x48')]=function(_0x38b45b,_0x1de5ae){return db[_0xfc89('0x2a')]['describe']()[_0xfc89('0x23')](respondWithResult(_0x1de5ae,null))[_0xfc89('0x42')](handleError(_0x1de5ae,null));};