9eee944b2d3a34763e65d014638716c6fca25ba1
[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 _0xad55=['update','then','error','stack','name','index','map','rawAttributes','fieldName','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','merge','options','VoiceTransferReport','includeAll','findAll','rows','catch','params','include','find','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save'];(function(_0x1d1a25,_0x361d7e){var _0x65fd2c=function(_0x28300b){while(--_0x28300b){_0x1d1a25['push'](_0x1d1a25['shift']());}};_0x65fd2c(++_0x361d7e);}(_0xad55,0x149));var _0x5ad5=function(_0x40d980,_0x21b5ad){_0x40d980=_0x40d980-0x0;var _0x281495=_0xad55[_0x40d980];return _0x281495;};'use strict';var emlformat=require(_0x5ad5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x5ad5('0x1'));var jsonpatch=require(_0x5ad5('0x2'));var rp=require(_0x5ad5('0x3'));var moment=require('moment');var BPromise=require(_0x5ad5('0x4'));var Mustache=require(_0x5ad5('0x5'));var util=require(_0x5ad5('0x6'));var path=require(_0x5ad5('0x7'));var sox=require('sox');var csv=require(_0x5ad5('0x8'));var ejs=require(_0x5ad5('0x9'));var fs=require('fs');var fs_extra=require(_0x5ad5('0xa'));var _=require(_0x5ad5('0xb'));var squel=require(_0x5ad5('0xc'));var crypto=require(_0x5ad5('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x5ad5('0xe'));var toCsv=require(_0x5ad5('0x8'));var querystring=require(_0x5ad5('0xf'));var Papa=require('papaparse');var Redis=require(_0x5ad5('0x10'));var authService=require(_0x5ad5('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5ad5('0x12'));var hardwareService=require(_0x5ad5('0x13'));var logger=require(_0x5ad5('0x14'))(_0x5ad5('0x15'));var utils=require(_0x5ad5('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x5ad5('0x17'))['db'];function respondWithStatusCode(_0x582930,_0x29c3df){_0x29c3df=_0x29c3df||0xcc;return function(_0x31805e){if(_0x31805e){return _0x582930[_0x5ad5('0x18')](_0x29c3df);}return _0x582930[_0x5ad5('0x19')](_0x29c3df)[_0x5ad5('0x1a')]();};}function respondWithResult(_0x4d5212,_0x4568fd){_0x4568fd=_0x4568fd||0xc8;return function(_0x3bcf68){if(_0x3bcf68){return _0x4d5212[_0x5ad5('0x19')](_0x4568fd)[_0x5ad5('0x1b')](_0x3bcf68);}};}function respondWithFilteredResult(_0x55a3b4,_0xeda063){return function(_0x589573){if(_0x589573){var _0x576d04=typeof _0xeda063[_0x5ad5('0x1c')]===_0x5ad5('0x1d')&&typeof _0xeda063[_0x5ad5('0x1e')]===_0x5ad5('0x1d');var _0x7db5d=_0x589573[_0x5ad5('0x1f')];var _0x4a511d=_0x576d04?0x0:_0xeda063['offset'];var _0x24c40e=_0x576d04?_0x589573[_0x5ad5('0x1f')]:_0xeda063[_0x5ad5('0x1c')]+_0xeda063['limit'];var _0x27a043;if(_0x24c40e>=_0x7db5d){_0x24c40e=_0x7db5d;_0x27a043=0xc8;}else{_0x27a043=0xce;}_0x55a3b4[_0x5ad5('0x19')](_0x27a043);return _0x55a3b4['set'](_0x5ad5('0x20'),_0x4a511d+'-'+_0x24c40e+'/'+_0x7db5d)[_0x5ad5('0x1b')](_0x589573);}return null;};}function patchUpdates(_0x1a4b79){return function(_0x13effc){try{jsonpatch[_0x5ad5('0x21')](_0x13effc,_0x1a4b79,!![]);}catch(_0x5224c2){return BPromise[_0x5ad5('0x22')](_0x5224c2);}return _0x13effc[_0x5ad5('0x23')]();};}function saveUpdates(_0x59ddba,_0x247e2d){return function(_0x48b648){if(_0x48b648){return _0x48b648[_0x5ad5('0x24')](_0x59ddba)['then'](function(_0x297177){return _0x297177;});}return null;};}function removeEntity(_0x5b4924,_0x2a7e85){return function(_0xdd89e5){if(_0xdd89e5){return _0xdd89e5['destroy']()[_0x5ad5('0x25')](function(){_0x5b4924[_0x5ad5('0x19')](0xcc)[_0x5ad5('0x1a')]();});}};}function handleEntityNotFound(_0x703879,_0x193503){return function(_0x559662){if(!_0x559662){_0x703879[_0x5ad5('0x18')](0x194);}return _0x559662;};}function handleError(_0x37958a,_0x1406aa){_0x1406aa=_0x1406aa||0x1f4;return function(_0x388aff){logger[_0x5ad5('0x26')](_0x388aff[_0x5ad5('0x27')]);if(_0x388aff[_0x5ad5('0x28')]){delete _0x388aff[_0x5ad5('0x28')];}_0x37958a['status'](_0x1406aa)['send'](_0x388aff);};}exports[_0x5ad5('0x29')]=function(_0x2cdcea,_0x36dad7){var _0x5bd853={},_0x56e5e4={},_0x2d7b67={'count':0x0,'rows':[]};var _0x3c327f=_[_0x5ad5('0x2a')](db['VoiceTransferReport'][_0x5ad5('0x2b')],function(_0x3113cf){return{'name':_0x3113cf[_0x5ad5('0x2c')],'type':_0x3113cf['type']['key']};});_0x56e5e4['model']=_['map'](_0x3c327f,_0x5ad5('0x28'));_0x56e5e4[_0x5ad5('0x2d')]=_[_0x5ad5('0x2e')](_0x2cdcea[_0x5ad5('0x2d')]);_0x56e5e4['filters']=_[_0x5ad5('0x2f')](_0x56e5e4[_0x5ad5('0x30')],_0x56e5e4[_0x5ad5('0x2d')]);_0x5bd853[_0x5ad5('0x31')]=_[_0x5ad5('0x2f')](_0x56e5e4[_0x5ad5('0x30')],qs[_0x5ad5('0x32')](_0x2cdcea[_0x5ad5('0x2d')][_0x5ad5('0x32')]));_0x5bd853[_0x5ad5('0x31')]=_0x5bd853[_0x5ad5('0x31')][_0x5ad5('0x33')]?_0x5bd853[_0x5ad5('0x31')]:_0x56e5e4['model'];if(!_0x2cdcea[_0x5ad5('0x2d')][_0x5ad5('0x34')]('nolimit')){_0x5bd853[_0x5ad5('0x1e')]=qs[_0x5ad5('0x1e')](_0x2cdcea['query']['limit']);_0x5bd853[_0x5ad5('0x1c')]=qs[_0x5ad5('0x1c')](_0x2cdcea[_0x5ad5('0x2d')]['offset']);}_0x5bd853[_0x5ad5('0x35')]=qs['sort'](_0x2cdcea[_0x5ad5('0x2d')][_0x5ad5('0x36')]);_0x5bd853[_0x5ad5('0x37')]=qs[_0x5ad5('0x38')](_[_0x5ad5('0x39')](_0x2cdcea[_0x5ad5('0x2d')],_0x56e5e4['filters']),_0x3c327f);if(_0x2cdcea[_0x5ad5('0x2d')][_0x5ad5('0x3a')]){_0x5bd853[_0x5ad5('0x37')]=_[_0x5ad5('0x3b')](_0x5bd853[_0x5ad5('0x37')],{'$or':_[_0x5ad5('0x2a')](_0x3c327f,function(_0x39436c){if(_0x39436c['type']!=='VIRTUAL'){var _0x20842a={};_0x20842a[_0x39436c['name']]={'$like':'%'+_0x2cdcea[_0x5ad5('0x2d')][_0x5ad5('0x3a')]+'%'};return _0x20842a;}})});}_0x5bd853=_['merge']({},_0x5bd853,_0x2cdcea[_0x5ad5('0x3c')]);var _0xf5759d={'where':_0x5bd853['where']};return db[_0x5ad5('0x3d')][_0x5ad5('0x1f')](_0xf5759d)['then'](function(_0x539963){_0x2d7b67[_0x5ad5('0x1f')]=_0x539963;if(_0x2cdcea['query'][_0x5ad5('0x3e')]){_0x5bd853['include']=[{'all':!![]}];}return db['VoiceTransferReport'][_0x5ad5('0x3f')](_0x5bd853);})['then'](function(_0x72a8d2){_0x2d7b67[_0x5ad5('0x40')]=_0x72a8d2;return _0x2d7b67;})[_0x5ad5('0x25')](respondWithFilteredResult(_0x36dad7,_0x5bd853))[_0x5ad5('0x41')](handleError(_0x36dad7,null));};exports['show']=function(_0x20a791,_0x3b6009){var _0x2cb44f={'raw':!![],'where':{'id':_0x20a791[_0x5ad5('0x42')]['id']}},_0x4da998={};_0x4da998[_0x5ad5('0x30')]=_['keys'](db[_0x5ad5('0x3d')][_0x5ad5('0x2b')]);_0x4da998[_0x5ad5('0x2d')]=_['keys'](_0x20a791[_0x5ad5('0x2d')]);_0x4da998['filters']=_[_0x5ad5('0x2f')](_0x4da998[_0x5ad5('0x30')],_0x4da998[_0x5ad5('0x2d')]);_0x2cb44f[_0x5ad5('0x31')]=_['intersection'](_0x4da998['model'],qs[_0x5ad5('0x32')](_0x20a791['query'][_0x5ad5('0x32')]));_0x2cb44f[_0x5ad5('0x31')]=_0x2cb44f[_0x5ad5('0x31')][_0x5ad5('0x33')]?_0x2cb44f['attributes']:_0x4da998[_0x5ad5('0x30')];if(_0x20a791[_0x5ad5('0x2d')][_0x5ad5('0x3e')]){_0x2cb44f[_0x5ad5('0x43')]=[{'all':!![]}];}_0x2cb44f=_['merge']({},_0x2cb44f,_0x20a791[_0x5ad5('0x3c')]);return db[_0x5ad5('0x3d')][_0x5ad5('0x44')](_0x2cb44f)[_0x5ad5('0x25')](handleEntityNotFound(_0x3b6009,null))[_0x5ad5('0x25')](respondWithResult(_0x3b6009,null))['catch'](handleError(_0x3b6009,null));};exports[_0x5ad5('0x45')]=function(_0x14441d,_0x293dcc){return db[_0x5ad5('0x3d')][_0x5ad5('0x45')](_0x14441d[_0x5ad5('0x46')],{})[_0x5ad5('0x25')](respondWithResult(_0x293dcc,0xc9))[_0x5ad5('0x41')](handleError(_0x293dcc,null));};exports[_0x5ad5('0x24')]=function(_0x2440d7,_0x104d8f){if(_0x2440d7['body']['id']){delete _0x2440d7[_0x5ad5('0x46')]['id'];}return db[_0x5ad5('0x3d')][_0x5ad5('0x44')]({'where':{'id':_0x2440d7[_0x5ad5('0x42')]['id']}})[_0x5ad5('0x25')](handleEntityNotFound(_0x104d8f,null))[_0x5ad5('0x25')](saveUpdates(_0x2440d7[_0x5ad5('0x46')],null))[_0x5ad5('0x25')](respondWithResult(_0x104d8f,null))['catch'](handleError(_0x104d8f,null));};exports[_0x5ad5('0x47')]=function(_0x2cbc5d,_0x2429f2){return db[_0x5ad5('0x3d')][_0x5ad5('0x44')]({'where':{'id':_0x2cbc5d[_0x5ad5('0x42')]['id']}})['then'](handleEntityNotFound(_0x2429f2,null))['then'](removeEntity(_0x2429f2,null))[_0x5ad5('0x41')](handleError(_0x2429f2,null));};exports[_0x5ad5('0x48')]=function(_0x48d019,_0x2ed3d1){return db[_0x5ad5('0x3d')][_0x5ad5('0x48')]()[_0x5ad5('0x25')](respondWithResult(_0x2ed3d1,null))[_0x5ad5('0x41')](handleError(_0x2ed3d1,null));};