2eabba39cea6e91c5d24f431f97604120800da38
[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 _0xea16=['stack','name','send','index','VoiceTransferReport','rawAttributes','fieldName','type','key','keys','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','filter','map','VIRTUAL','merge','includeAll','findAll','rows','catch','show','params','include','options','find','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','reject','save','update','then','end','error'];(function(_0x5983da,_0x5882de){var _0x5198cb=function(_0x507308){while(--_0x507308){_0x5983da['push'](_0x5983da['shift']());}};_0x5198cb(++_0x5882de);}(_0xea16,0x76));var _0x6ea1=function(_0x160c73,_0x2ee678){_0x160c73=_0x160c73-0x0;var _0xd9302=_0xea16[_0x160c73];return _0xd9302;};'use strict';var emlformat=require(_0x6ea1('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x6ea1('0x1'));var jsonpatch=require(_0x6ea1('0x2'));var rp=require(_0x6ea1('0x3'));var moment=require(_0x6ea1('0x4'));var BPromise=require(_0x6ea1('0x5'));var Mustache=require(_0x6ea1('0x6'));var util=require('util');var path=require(_0x6ea1('0x7'));var sox=require('sox');var csv=require(_0x6ea1('0x8'));var ejs=require(_0x6ea1('0x9'));var fs=require('fs');var fs_extra=require(_0x6ea1('0xa'));var _=require(_0x6ea1('0xb'));var squel=require(_0x6ea1('0xc'));var crypto=require(_0x6ea1('0xd'));var jsforce=require(_0x6ea1('0xe'));var deskjs=require(_0x6ea1('0xf'));var toCsv=require(_0x6ea1('0x8'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x6ea1('0x10'));var authService=require(_0x6ea1('0x11'));var qs=require(_0x6ea1('0x12'));var as=require(_0x6ea1('0x13'));var hardwareService=require(_0x6ea1('0x14'));var logger=require(_0x6ea1('0x15'))('api');var utils=require(_0x6ea1('0x16'));var config=require(_0x6ea1('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x6ea1('0x18'))['db'];function respondWithStatusCode(_0x2dcd1d,_0x203459){_0x203459=_0x203459||0xcc;return function(_0x4d90f4){if(_0x4d90f4){return _0x2dcd1d[_0x6ea1('0x19')](_0x203459);}return _0x2dcd1d[_0x6ea1('0x1a')](_0x203459)['end']();};}function respondWithResult(_0x5c526f,_0x86f6ab){_0x86f6ab=_0x86f6ab||0xc8;return function(_0x406d4c){if(_0x406d4c){return _0x5c526f[_0x6ea1('0x1a')](_0x86f6ab)['json'](_0x406d4c);}};}function respondWithFilteredResult(_0x5067b0,_0x152c71){return function(_0x37702f){if(_0x37702f){var _0x82201a=typeof _0x152c71[_0x6ea1('0x1b')]===_0x6ea1('0x1c')&&typeof _0x152c71[_0x6ea1('0x1d')]===_0x6ea1('0x1c');var _0x18601b=_0x37702f[_0x6ea1('0x1e')];var _0x54c93b=_0x82201a?0x0:_0x152c71[_0x6ea1('0x1b')];var _0x46dbb1=_0x82201a?_0x37702f['count']:_0x152c71[_0x6ea1('0x1b')]+_0x152c71[_0x6ea1('0x1d')];var _0x120789;if(_0x46dbb1>=_0x18601b){_0x46dbb1=_0x18601b;_0x120789=0xc8;}else{_0x120789=0xce;}_0x5067b0[_0x6ea1('0x1a')](_0x120789);return _0x5067b0[_0x6ea1('0x1f')](_0x6ea1('0x20'),_0x54c93b+'-'+_0x46dbb1+'/'+_0x18601b)[_0x6ea1('0x21')](_0x37702f);}return null;};}function patchUpdates(_0x50daf7){return function(_0x16210d){try{jsonpatch['apply'](_0x16210d,_0x50daf7,!![]);}catch(_0x36f6d7){return BPromise[_0x6ea1('0x22')](_0x36f6d7);}return _0x16210d[_0x6ea1('0x23')]();};}function saveUpdates(_0x41dd2d,_0x5ccb7b){return function(_0x377d4e){if(_0x377d4e){return _0x377d4e[_0x6ea1('0x24')](_0x41dd2d)['then'](function(_0x3a3787){return _0x3a3787;});}return null;};}function removeEntity(_0x184a12,_0x454695){return function(_0x37b205){if(_0x37b205){return _0x37b205['destroy']()[_0x6ea1('0x25')](function(){_0x184a12[_0x6ea1('0x1a')](0xcc)[_0x6ea1('0x26')]();});}};}function handleEntityNotFound(_0x2a8d44,_0xa62b72){return function(_0x2aebd9){if(!_0x2aebd9){_0x2a8d44[_0x6ea1('0x19')](0x194);}return _0x2aebd9;};}function handleError(_0x50bb9b,_0x7e4a1e){_0x7e4a1e=_0x7e4a1e||0x1f4;return function(_0x15eda7){logger[_0x6ea1('0x27')](_0x15eda7[_0x6ea1('0x28')]);if(_0x15eda7[_0x6ea1('0x29')]){delete _0x15eda7[_0x6ea1('0x29')];}_0x50bb9b['status'](_0x7e4a1e)[_0x6ea1('0x2a')](_0x15eda7);};}exports[_0x6ea1('0x2b')]=function(_0x4c60ce,_0x30531b){var _0x3e7f21={},_0x291c33={},_0x500abc={'count':0x0,'rows':[]};var _0x54c7b6=_['map'](db[_0x6ea1('0x2c')][_0x6ea1('0x2d')],function(_0x439227){return{'name':_0x439227[_0x6ea1('0x2e')],'type':_0x439227[_0x6ea1('0x2f')][_0x6ea1('0x30')]};});_0x291c33['model']=_['map'](_0x54c7b6,_0x6ea1('0x29'));_0x291c33['query']=_[_0x6ea1('0x31')](_0x4c60ce[_0x6ea1('0x32')]);_0x291c33[_0x6ea1('0x33')]=_['intersection'](_0x291c33[_0x6ea1('0x34')],_0x291c33['query']);_0x3e7f21[_0x6ea1('0x35')]=_[_0x6ea1('0x36')](_0x291c33[_0x6ea1('0x34')],qs[_0x6ea1('0x37')](_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x37')]));_0x3e7f21[_0x6ea1('0x35')]=_0x3e7f21[_0x6ea1('0x35')][_0x6ea1('0x38')]?_0x3e7f21[_0x6ea1('0x35')]:_0x291c33['model'];if(!_0x4c60ce['query'][_0x6ea1('0x39')]('nolimit')){_0x3e7f21[_0x6ea1('0x1d')]=qs['limit'](_0x4c60ce['query'][_0x6ea1('0x1d')]);_0x3e7f21[_0x6ea1('0x1b')]=qs[_0x6ea1('0x1b')](_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x1b')]);}_0x3e7f21[_0x6ea1('0x3a')]=qs[_0x6ea1('0x3b')](_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x3b')]);_0x3e7f21[_0x6ea1('0x3c')]=qs[_0x6ea1('0x33')](_[_0x6ea1('0x3d')](_0x4c60ce[_0x6ea1('0x32')],_0x291c33['filters']),_0x54c7b6);if(_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x3e')]){_0x3e7f21[_0x6ea1('0x3c')]=_['merge'](_0x3e7f21[_0x6ea1('0x3c')],{'$or':_[_0x6ea1('0x3f')](_0x54c7b6,function(_0x452b3d){if(_0x452b3d[_0x6ea1('0x2f')]!==_0x6ea1('0x40')){var _0x112411={};_0x112411[_0x452b3d[_0x6ea1('0x29')]]={'$like':'%'+_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x3e')]+'%'};return _0x112411;}})});}_0x3e7f21=_[_0x6ea1('0x41')]({},_0x3e7f21,_0x4c60ce['options']);var _0x273849={'where':_0x3e7f21[_0x6ea1('0x3c')]};return db['VoiceTransferReport'][_0x6ea1('0x1e')](_0x273849)['then'](function(_0x4756f6){_0x500abc[_0x6ea1('0x1e')]=_0x4756f6;if(_0x4c60ce[_0x6ea1('0x32')][_0x6ea1('0x42')]){_0x3e7f21['include']=[{'all':!![]}];}return db[_0x6ea1('0x2c')][_0x6ea1('0x43')](_0x3e7f21);})['then'](function(_0x172f55){_0x500abc[_0x6ea1('0x44')]=_0x172f55;return _0x500abc;})[_0x6ea1('0x25')](respondWithFilteredResult(_0x30531b,_0x3e7f21))[_0x6ea1('0x45')](handleError(_0x30531b,null));};exports[_0x6ea1('0x46')]=function(_0x4604bf,_0xd33ddb){var _0x55922c={'raw':!![],'where':{'id':_0x4604bf[_0x6ea1('0x47')]['id']}},_0x3e6876={};_0x3e6876['model']=_['keys'](db[_0x6ea1('0x2c')][_0x6ea1('0x2d')]);_0x3e6876[_0x6ea1('0x32')]=_[_0x6ea1('0x31')](_0x4604bf[_0x6ea1('0x32')]);_0x3e6876[_0x6ea1('0x33')]=_[_0x6ea1('0x36')](_0x3e6876[_0x6ea1('0x34')],_0x3e6876[_0x6ea1('0x32')]);_0x55922c[_0x6ea1('0x35')]=_[_0x6ea1('0x36')](_0x3e6876[_0x6ea1('0x34')],qs[_0x6ea1('0x37')](_0x4604bf[_0x6ea1('0x32')][_0x6ea1('0x37')]));_0x55922c['attributes']=_0x55922c[_0x6ea1('0x35')]['length']?_0x55922c[_0x6ea1('0x35')]:_0x3e6876[_0x6ea1('0x34')];if(_0x4604bf[_0x6ea1('0x32')][_0x6ea1('0x42')]){_0x55922c[_0x6ea1('0x48')]=[{'all':!![]}];}_0x55922c=_[_0x6ea1('0x41')]({},_0x55922c,_0x4604bf[_0x6ea1('0x49')]);return db['VoiceTransferReport'][_0x6ea1('0x4a')](_0x55922c)[_0x6ea1('0x25')](handleEntityNotFound(_0xd33ddb,null))[_0x6ea1('0x25')](respondWithResult(_0xd33ddb,null))[_0x6ea1('0x45')](handleError(_0xd33ddb,null));};exports[_0x6ea1('0x4b')]=function(_0x1093b9,_0x265d27){return db[_0x6ea1('0x2c')]['create'](_0x1093b9[_0x6ea1('0x4c')],{})[_0x6ea1('0x25')](respondWithResult(_0x265d27,0xc9))[_0x6ea1('0x45')](handleError(_0x265d27,null));};exports['update']=function(_0x3262b5,_0x7afc76){if(_0x3262b5[_0x6ea1('0x4c')]['id']){delete _0x3262b5[_0x6ea1('0x4c')]['id'];}return db[_0x6ea1('0x2c')][_0x6ea1('0x4a')]({'where':{'id':_0x3262b5[_0x6ea1('0x47')]['id']}})[_0x6ea1('0x25')](handleEntityNotFound(_0x7afc76,null))[_0x6ea1('0x25')](saveUpdates(_0x3262b5['body'],null))[_0x6ea1('0x25')](respondWithResult(_0x7afc76,null))[_0x6ea1('0x45')](handleError(_0x7afc76,null));};exports[_0x6ea1('0x4d')]=function(_0x1653b3,_0x1d646f){return db[_0x6ea1('0x2c')][_0x6ea1('0x4a')]({'where':{'id':_0x1653b3[_0x6ea1('0x47')]['id']}})['then'](handleEntityNotFound(_0x1d646f,null))[_0x6ea1('0x25')](removeEntity(_0x1d646f,null))[_0x6ea1('0x45')](handleError(_0x1d646f,null));};exports[_0x6ea1('0x4e')]=function(_0x52d2bc,_0x509e96){return db[_0x6ea1('0x2c')]['describe']()['then'](respondWithResult(_0x509e96,null))[_0x6ea1('0x45')](handleError(_0x509e96,null));};