3b306ab2bf4fefa2bd85150e9c97b5d948b2f155
[motion2.git] / server / api / voiceTransferReport / voiceTransferReport.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 _0xb9c3=['sendStatus','status','end','json','undefined','limit','count','offset','set','reject','save','update','then','error','name','send','index','map','rawAttributes','type','key','query','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','VoiceTransferReport','findAll','rows','catch','params','keys','find','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment'];(function(_0x2fdce0,_0x496242){var _0x36f07e=function(_0x44c8c6){while(--_0x44c8c6){_0x2fdce0['push'](_0x2fdce0['shift']());}};_0x36f07e(++_0x496242);}(_0xb9c3,0xc6));var _0x3b9c=function(_0x469592,_0x35036b){_0x469592=_0x469592-0x0;var _0xd0207=_0xb9c3[_0x469592];return _0xd0207;};'use strict';var emlformat=require(_0x3b9c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3b9c('0x1'));var jsonpatch=require(_0x3b9c('0x2'));var rp=require('request-promise');var moment=require(_0x3b9c('0x3'));var BPromise=require(_0x3b9c('0x4'));var Mustache=require(_0x3b9c('0x5'));var util=require(_0x3b9c('0x6'));var path=require(_0x3b9c('0x7'));var sox=require(_0x3b9c('0x8'));var csv=require(_0x3b9c('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3b9c('0xa'));var _=require('lodash');var squel=require(_0x3b9c('0xb'));var crypto=require(_0x3b9c('0xc'));var jsforce=require(_0x3b9c('0xd'));var deskjs=require(_0x3b9c('0xe'));var toCsv=require(_0x3b9c('0x9'));var querystring=require('querystring');var Papa=require(_0x3b9c('0xf'));var Redis=require(_0x3b9c('0x10'));var authService=require(_0x3b9c('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x3b9c('0x12'));var hardwareService=require(_0x3b9c('0x13'));var logger=require(_0x3b9c('0x14'))(_0x3b9c('0x15'));var utils=require(_0x3b9c('0x16'));var config=require(_0x3b9c('0x17'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x38f3a8,_0x3ca570){_0x3ca570=_0x3ca570||0xcc;return function(_0x3998d8){if(_0x3998d8){return _0x38f3a8[_0x3b9c('0x18')](_0x3ca570);}return _0x38f3a8[_0x3b9c('0x19')](_0x3ca570)[_0x3b9c('0x1a')]();};}function respondWithResult(_0x10d215,_0x9d623e){_0x9d623e=_0x9d623e||0xc8;return function(_0x16d5f6){if(_0x16d5f6){return _0x10d215[_0x3b9c('0x19')](_0x9d623e)[_0x3b9c('0x1b')](_0x16d5f6);}};}function respondWithFilteredResult(_0x5b445c,_0x5c87c6){return function(_0x1cd684){if(_0x1cd684){var _0x52a196=typeof _0x5c87c6['offset']===_0x3b9c('0x1c')&&typeof _0x5c87c6[_0x3b9c('0x1d')]===_0x3b9c('0x1c');var _0x56d9dc=_0x1cd684[_0x3b9c('0x1e')];var _0x1aea64=_0x52a196?0x0:_0x5c87c6[_0x3b9c('0x1f')];var _0xd4d1fa=_0x52a196?_0x1cd684[_0x3b9c('0x1e')]:_0x5c87c6[_0x3b9c('0x1f')]+_0x5c87c6['limit'];var _0x1af136;if(_0xd4d1fa>=_0x56d9dc){_0xd4d1fa=_0x56d9dc;_0x1af136=0xc8;}else{_0x1af136=0xce;}_0x5b445c['status'](_0x1af136);return _0x5b445c[_0x3b9c('0x20')]('Content-Range',_0x1aea64+'-'+_0xd4d1fa+'/'+_0x56d9dc)['json'](_0x1cd684);}return null;};}function patchUpdates(_0x4e42b4){return function(_0x5b9eb3){try{jsonpatch['apply'](_0x5b9eb3,_0x4e42b4,!![]);}catch(_0x24f094){return BPromise[_0x3b9c('0x21')](_0x24f094);}return _0x5b9eb3[_0x3b9c('0x22')]();};}function saveUpdates(_0x35c2d3,_0x4e26d4){return function(_0x311706){if(_0x311706){return _0x311706[_0x3b9c('0x23')](_0x35c2d3)[_0x3b9c('0x24')](function(_0x198e99){return _0x198e99;});}return null;};}function removeEntity(_0x59e63c,_0x51256a){return function(_0x36aaa8){if(_0x36aaa8){return _0x36aaa8['destroy']()[_0x3b9c('0x24')](function(){_0x59e63c['status'](0xcc)[_0x3b9c('0x1a')]();});}};}function handleEntityNotFound(_0x36698f,_0x9e753c){return function(_0x500fec){if(!_0x500fec){_0x36698f['sendStatus'](0x194);}return _0x500fec;};}function handleError(_0x67c70c,_0x4a5e4f){_0x4a5e4f=_0x4a5e4f||0x1f4;return function(_0x12be84){logger[_0x3b9c('0x25')](_0x12be84['stack']);if(_0x12be84[_0x3b9c('0x26')]){delete _0x12be84[_0x3b9c('0x26')];}_0x67c70c[_0x3b9c('0x19')](_0x4a5e4f)[_0x3b9c('0x27')](_0x12be84);};}exports[_0x3b9c('0x28')]=function(_0x8e14b9,_0x1246f7){var _0x1d807a={},_0x2c51a3={},_0x5404d6={'count':0x0,'rows':[]};var _0x2ddd36=_[_0x3b9c('0x29')](db['VoiceTransferReport'][_0x3b9c('0x2a')],function(_0x2ae8ca){return{'name':_0x2ae8ca['fieldName'],'type':_0x2ae8ca[_0x3b9c('0x2b')][_0x3b9c('0x2c')]};});_0x2c51a3['model']=_[_0x3b9c('0x29')](_0x2ddd36,'name');_0x2c51a3[_0x3b9c('0x2d')]=_['keys'](_0x8e14b9[_0x3b9c('0x2d')]);_0x2c51a3['filters']=_[_0x3b9c('0x2e')](_0x2c51a3[_0x3b9c('0x2f')],_0x2c51a3['query']);_0x1d807a['attributes']=_[_0x3b9c('0x2e')](_0x2c51a3[_0x3b9c('0x2f')],qs[_0x3b9c('0x30')](_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x30')]));_0x1d807a['attributes']=_0x1d807a[_0x3b9c('0x31')][_0x3b9c('0x32')]?_0x1d807a['attributes']:_0x2c51a3[_0x3b9c('0x2f')];if(!_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x33')](_0x3b9c('0x34'))){_0x1d807a[_0x3b9c('0x1d')]=qs[_0x3b9c('0x1d')](_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x1d')]);_0x1d807a[_0x3b9c('0x1f')]=qs[_0x3b9c('0x1f')](_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x1f')]);}_0x1d807a[_0x3b9c('0x35')]=qs[_0x3b9c('0x36')](_0x8e14b9['query']['sort']);_0x1d807a[_0x3b9c('0x37')]=qs['filters'](_['pick'](_0x8e14b9[_0x3b9c('0x2d')],_0x2c51a3[_0x3b9c('0x38')]),_0x2ddd36);if(_0x8e14b9['query'][_0x3b9c('0x39')]){_0x1d807a[_0x3b9c('0x37')]=_[_0x3b9c('0x3a')](_0x1d807a[_0x3b9c('0x37')],{'$or':_[_0x3b9c('0x29')](_0x2ddd36,function(_0x1fe8d5){if(_0x1fe8d5[_0x3b9c('0x2b')]!==_0x3b9c('0x3b')){var _0x4a7993={};_0x4a7993[_0x1fe8d5[_0x3b9c('0x26')]]={'$like':'%'+_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x39')]+'%'};return _0x4a7993;}})});}_0x1d807a=_[_0x3b9c('0x3a')]({},_0x1d807a,_0x8e14b9[_0x3b9c('0x3c')]);var _0x41103f={'where':_0x1d807a[_0x3b9c('0x37')]};return db['VoiceTransferReport'][_0x3b9c('0x1e')](_0x41103f)[_0x3b9c('0x24')](function(_0x5885ab){_0x5404d6[_0x3b9c('0x1e')]=_0x5885ab;if(_0x8e14b9[_0x3b9c('0x2d')][_0x3b9c('0x3d')]){_0x1d807a[_0x3b9c('0x3e')]=[{'all':!![]}];}return db[_0x3b9c('0x3f')][_0x3b9c('0x40')](_0x1d807a);})[_0x3b9c('0x24')](function(_0x59434d){_0x5404d6[_0x3b9c('0x41')]=_0x59434d;return _0x5404d6;})[_0x3b9c('0x24')](respondWithFilteredResult(_0x1246f7,_0x1d807a))[_0x3b9c('0x42')](handleError(_0x1246f7,null));};exports['show']=function(_0x4f0982,_0x5af015){var _0x548064={'raw':!![],'where':{'id':_0x4f0982[_0x3b9c('0x43')]['id']}},_0x429e42={};_0x429e42['model']=_[_0x3b9c('0x44')](db['VoiceTransferReport'][_0x3b9c('0x2a')]);_0x429e42['query']=_[_0x3b9c('0x44')](_0x4f0982[_0x3b9c('0x2d')]);_0x429e42[_0x3b9c('0x38')]=_[_0x3b9c('0x2e')](_0x429e42['model'],_0x429e42['query']);_0x548064['attributes']=_['intersection'](_0x429e42[_0x3b9c('0x2f')],qs[_0x3b9c('0x30')](_0x4f0982[_0x3b9c('0x2d')]['fields']));_0x548064[_0x3b9c('0x31')]=_0x548064[_0x3b9c('0x31')][_0x3b9c('0x32')]?_0x548064[_0x3b9c('0x31')]:_0x429e42[_0x3b9c('0x2f')];if(_0x4f0982[_0x3b9c('0x2d')]['includeAll']){_0x548064[_0x3b9c('0x3e')]=[{'all':!![]}];}_0x548064=_['merge']({},_0x548064,_0x4f0982[_0x3b9c('0x3c')]);return db[_0x3b9c('0x3f')][_0x3b9c('0x45')](_0x548064)[_0x3b9c('0x24')](handleEntityNotFound(_0x5af015,null))[_0x3b9c('0x24')](respondWithResult(_0x5af015,null))[_0x3b9c('0x42')](handleError(_0x5af015,null));};exports['create']=function(_0x3d6ff6,_0x4901aa){return db[_0x3b9c('0x3f')][_0x3b9c('0x46')](_0x3d6ff6[_0x3b9c('0x47')],{})['then'](respondWithResult(_0x4901aa,0xc9))[_0x3b9c('0x42')](handleError(_0x4901aa,null));};exports[_0x3b9c('0x23')]=function(_0x589617,_0xeadd10){if(_0x589617[_0x3b9c('0x47')]['id']){delete _0x589617[_0x3b9c('0x47')]['id'];}return db[_0x3b9c('0x3f')][_0x3b9c('0x45')]({'where':{'id':_0x589617['params']['id']}})[_0x3b9c('0x24')](handleEntityNotFound(_0xeadd10,null))['then'](saveUpdates(_0x589617[_0x3b9c('0x47')],null))['then'](respondWithResult(_0xeadd10,null))[_0x3b9c('0x42')](handleError(_0xeadd10,null));};exports[_0x3b9c('0x48')]=function(_0xfba9,_0x5d56dd){return db[_0x3b9c('0x3f')][_0x3b9c('0x45')]({'where':{'id':_0xfba9[_0x3b9c('0x43')]['id']}})[_0x3b9c('0x24')](handleEntityNotFound(_0x5d56dd,null))[_0x3b9c('0x24')](removeEntity(_0x5d56dd,null))[_0x3b9c('0x42')](handleError(_0x5d56dd,null));};exports[_0x3b9c('0x49')]=function(_0x40b0ea,_0x502690){return db[_0x3b9c('0x3f')][_0x3b9c('0x49')]()[_0x3b9c('0x24')](respondWithResult(_0x502690,null))[_0x3b9c('0x42')](handleError(_0x502690,null));};