8cbd2d6bb2b7f9bf55f8159bafd0d305a3a64bc7
[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 _0x3ff4=['send','VoiceAgentReport','fieldName','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','merge','type','VIRTUAL','filter','options','includeAll','findAll','rows','params','rawAttributes','find','catch','create','body','destroy','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','status','end','json','count','offset','limit','set','Content-Range','apply','reject','then','sendStatus','stack','name'];(function(_0x122096,_0x60c295){var _0x3d1966=function(_0x3d569e){while(--_0x3d569e){_0x122096['push'](_0x122096['shift']());}};_0x3d1966(++_0x60c295);}(_0x3ff4,0xb5));var _0x43ff=function(_0x1da527,_0x2dc953){_0x1da527=_0x1da527-0x0;var _0x40fc7c=_0x3ff4[_0x1da527];return _0x40fc7c;};'use strict';var pdf=require(_0x43ff('0x0'));var emlformat=require(_0x43ff('0x1'));var rimraf=require(_0x43ff('0x2'));var zipdir=require(_0x43ff('0x3'));var jsonpatch=require(_0x43ff('0x4'));var rp=require(_0x43ff('0x5'));var moment=require(_0x43ff('0x6'));var BPromise=require(_0x43ff('0x7'));var Mustache=require(_0x43ff('0x8'));var util=require(_0x43ff('0x9'));var path=require(_0x43ff('0xa'));var sox=require('sox');var csv=require(_0x43ff('0xb'));var ejs=require(_0x43ff('0xc'));var fs=require('fs');var _=require(_0x43ff('0xd'));var squel=require(_0x43ff('0xe'));var crypto=require(_0x43ff('0xf'));var jsforce=require(_0x43ff('0x10'));var deskjs=require(_0x43ff('0x11'));var toCsv=require(_0x43ff('0xb'));var querystring=require(_0x43ff('0x12'));var Papa=require(_0x43ff('0x13'));var Redis=require('ioredis');var authService=require(_0x43ff('0x14'));var qs=require(_0x43ff('0x15'));var as=require(_0x43ff('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x43ff('0x17'))('api');var utils=require(_0x43ff('0x18'));var config=require(_0x43ff('0x19'));var db=require(_0x43ff('0x1a'))['db'];function respondWithStatusCode(_0x265ed5,_0x1cfeaf){_0x1cfeaf=_0x1cfeaf||0xcc;return function(_0x4c9167){if(_0x4c9167){return _0x265ed5['sendStatus'](_0x1cfeaf);}return _0x265ed5[_0x43ff('0x1b')](_0x1cfeaf)[_0x43ff('0x1c')]();};}function respondWithResult(_0x24888d,_0x33fb0a){_0x33fb0a=_0x33fb0a||0xc8;return function(_0x55570a){if(_0x55570a){return _0x24888d[_0x43ff('0x1b')](_0x33fb0a)[_0x43ff('0x1d')](_0x55570a);}};}function respondWithFilteredResult(_0xd68b04,_0x122cb6){return function(_0x378c3d){if(_0x378c3d){var _0x362d39=_0x378c3d[_0x43ff('0x1e')],_0x203181=_0x122cb6['offset'],_0x11439d=_0x122cb6[_0x43ff('0x1f')]+_0x122cb6[_0x43ff('0x20')],_0x182d74;if(_0x11439d>=_0x362d39){_0x11439d=_0x362d39;_0x182d74=0xc8;}else{_0x182d74=0xce;}_0xd68b04['status'](_0x182d74);return _0xd68b04[_0x43ff('0x21')](_0x43ff('0x22'),_0x203181+'-'+_0x11439d+'/'+_0x362d39)[_0x43ff('0x1d')](_0x378c3d);}return null;};}function patchUpdates(_0x4d18b7){return function(_0x2b3e37){try{jsonpatch[_0x43ff('0x23')](_0x2b3e37,_0x4d18b7,!![]);}catch(_0xd3314f){return BPromise[_0x43ff('0x24')](_0xd3314f);}return _0x2b3e37['save']();};}function saveUpdates(_0x200022,_0x42df46){return function(_0x145b57){if(_0x145b57){return _0x145b57['update'](_0x200022)[_0x43ff('0x25')](function(_0x504be9){return _0x504be9;});}return null;};}function removeEntity(_0x4c42df,_0x3124fe){return function(_0x3b45b6){if(_0x3b45b6){return _0x3b45b6['destroy']()[_0x43ff('0x25')](function(){_0x4c42df[_0x43ff('0x1b')](0xcc)[_0x43ff('0x1c')]();});}};}function handleEntityNotFound(_0x256f19,_0x3e39f3){return function(_0x817a19){if(!_0x817a19){_0x256f19[_0x43ff('0x26')](0x194);}return _0x817a19;};}function handleError(_0x228452,_0x5f0565){_0x5f0565=_0x5f0565||0x1f4;return function(_0x3a5e6f){logger['error'](_0x3a5e6f[_0x43ff('0x27')]);if(_0x3a5e6f[_0x43ff('0x28')]){delete _0x3a5e6f[_0x43ff('0x28')];}_0x228452['status'](_0x5f0565)[_0x43ff('0x29')](_0x3a5e6f);};}exports['index']=function(_0x16ef20,_0x215ea0){var _0x4d2912={},_0x3debbc={},_0x9c79bc={'count':0x0,'rows':[]};var _0x448e8a=_['map'](db[_0x43ff('0x2a')]['rawAttributes'],function(_0x5cd271){return{'name':_0x5cd271[_0x43ff('0x2b')],'type':_0x5cd271['type'][_0x43ff('0x2c')]};});_0x3debbc[_0x43ff('0x2d')]=_[_0x43ff('0x2e')](_0x448e8a,_0x43ff('0x28'));_0x3debbc[_0x43ff('0x2f')]=_[_0x43ff('0x30')](_0x16ef20[_0x43ff('0x2f')]);_0x3debbc[_0x43ff('0x31')]=_[_0x43ff('0x32')](_0x3debbc[_0x43ff('0x2d')],_0x3debbc['query']);_0x4d2912[_0x43ff('0x33')]=_[_0x43ff('0x32')](_0x3debbc[_0x43ff('0x2d')],qs[_0x43ff('0x34')](_0x16ef20[_0x43ff('0x2f')][_0x43ff('0x34')]));_0x4d2912[_0x43ff('0x33')]=_0x4d2912[_0x43ff('0x33')][_0x43ff('0x35')]?_0x4d2912[_0x43ff('0x33')]:_0x3debbc[_0x43ff('0x2d')];if(!_0x16ef20[_0x43ff('0x2f')][_0x43ff('0x36')](_0x43ff('0x37'))){_0x4d2912[_0x43ff('0x20')]=qs[_0x43ff('0x20')](_0x16ef20[_0x43ff('0x2f')]['limit']);_0x4d2912[_0x43ff('0x1f')]=qs['offset'](_0x16ef20['query'][_0x43ff('0x1f')]);}_0x4d2912['order']=qs[_0x43ff('0x38')](_0x16ef20[_0x43ff('0x2f')][_0x43ff('0x38')]);_0x4d2912['where']=qs[_0x43ff('0x31')](_[_0x43ff('0x39')](_0x16ef20[_0x43ff('0x2f')],_0x3debbc[_0x43ff('0x31')]),_0x448e8a);if(_0x16ef20[_0x43ff('0x2f')]['filter']){_0x4d2912['where']=_[_0x43ff('0x3a')](_0x4d2912['where'],{'$or':_[_0x43ff('0x2e')](_0x448e8a,function(_0x158630){if(_0x158630[_0x43ff('0x3b')]!==_0x43ff('0x3c')){var _0x35cee1={};_0x35cee1[_0x158630[_0x43ff('0x28')]]={'$like':'%'+_0x16ef20[_0x43ff('0x2f')][_0x43ff('0x3d')]+'%'};return _0x35cee1;}})});}_0x4d2912=_['merge']({},_0x4d2912,_0x16ef20[_0x43ff('0x3e')]);var _0x23844f={'where':_0x4d2912['where']};return db['VoiceAgentReport']['count'](_0x23844f)[_0x43ff('0x25')](function(_0x3818b2){_0x9c79bc[_0x43ff('0x1e')]=_0x3818b2;if(_0x16ef20[_0x43ff('0x2f')][_0x43ff('0x3f')]){_0x4d2912['include']=[{'all':!![]}];}return db[_0x43ff('0x2a')][_0x43ff('0x40')](_0x4d2912);})['then'](function(_0x3bfb33){_0x9c79bc[_0x43ff('0x41')]=_0x3bfb33;return _0x9c79bc;})[_0x43ff('0x25')](respondWithFilteredResult(_0x215ea0,_0x4d2912))['catch'](handleError(_0x215ea0,null));};exports['show']=function(_0x261d4f,_0x176339){var _0x377e10={'raw':![],'where':{'id':_0x261d4f[_0x43ff('0x42')]['id']}},_0x1a01aa={};_0x1a01aa[_0x43ff('0x2d')]=_[_0x43ff('0x30')](db[_0x43ff('0x2a')][_0x43ff('0x43')]);_0x1a01aa[_0x43ff('0x2f')]=_[_0x43ff('0x30')](_0x261d4f[_0x43ff('0x2f')]);_0x1a01aa[_0x43ff('0x31')]=_['intersection'](_0x1a01aa[_0x43ff('0x2d')],_0x1a01aa[_0x43ff('0x2f')]);_0x377e10['attributes']=_['intersection'](_0x1a01aa[_0x43ff('0x2d')],qs[_0x43ff('0x34')](_0x261d4f[_0x43ff('0x2f')]['fields']));_0x377e10[_0x43ff('0x33')]=_0x377e10[_0x43ff('0x33')]['length']?_0x377e10[_0x43ff('0x33')]:_0x1a01aa[_0x43ff('0x2d')];if(_0x261d4f['query'][_0x43ff('0x3f')]){_0x377e10['include']=[{'all':!![]}];}_0x377e10=_['merge']({},_0x377e10,_0x261d4f[_0x43ff('0x3e')]);return db[_0x43ff('0x2a')][_0x43ff('0x44')](_0x377e10)[_0x43ff('0x25')](handleEntityNotFound(_0x176339,null))[_0x43ff('0x25')](respondWithResult(_0x176339,null))[_0x43ff('0x45')](handleError(_0x176339,null));};exports[_0x43ff('0x46')]=function(_0x23a974,_0x1b7c37){return db[_0x43ff('0x2a')][_0x43ff('0x46')](_0x23a974[_0x43ff('0x47')],{})['then'](respondWithResult(_0x1b7c37,0xc9))['catch'](handleError(_0x1b7c37,null));};exports['update']=function(_0x20c033,_0x3d5865){if(_0x20c033[_0x43ff('0x47')]['id']){delete _0x20c033[_0x43ff('0x47')]['id'];}return db[_0x43ff('0x2a')][_0x43ff('0x44')]({'where':{'id':_0x20c033['params']['id']}})[_0x43ff('0x25')](handleEntityNotFound(_0x3d5865,null))['then'](saveUpdates(_0x20c033[_0x43ff('0x47')],null))[_0x43ff('0x25')](respondWithResult(_0x3d5865,null))[_0x43ff('0x45')](handleError(_0x3d5865,null));};exports[_0x43ff('0x48')]=function(_0x4b9fe7,_0x15ccf6){return db[_0x43ff('0x2a')][_0x43ff('0x44')]({'where':{'id':_0x4b9fe7[_0x43ff('0x42')]['id']}})['then'](handleEntityNotFound(_0x15ccf6,null))[_0x43ff('0x25')](removeEntity(_0x15ccf6,null))['catch'](handleError(_0x15ccf6,null));};exports[_0x43ff('0x49')]=function(_0xb60a17,_0x49441b){return db['VoiceAgentReport'][_0x43ff('0x49')]()['then'](respondWithResult(_0x49441b,null))['catch'](handleError(_0x49441b,null));};