Built motion from commit (unavailable).|2.4.3
[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 _0xce68=['jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','Content-Range','json','reject','update','then','destroy','name','send','index','VoiceTransferReport','rawAttributes','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','merge','where','type','key','VIRTUAL','field','include','findAll','catch','show','params','includeAll','options','find','create','body','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','crypto'];(function(_0x54ef48,_0x783269){var _0x24eb39=function(_0x3488ca){while(--_0x3488ca){_0x54ef48['push'](_0x54ef48['shift']());}};_0x24eb39(++_0x783269);}(_0xce68,0x10c));var _0x8ce6=function(_0x3ce167,_0x1afd04){_0x3ce167=_0x3ce167-0x0;var _0xafb35b=_0xce68[_0x3ce167];return _0xafb35b;};'use strict';var pdf=require(_0x8ce6('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x8ce6('0x1'));var zipdir=require(_0x8ce6('0x2'));var jsonpatch=require(_0x8ce6('0x3'));var rp=require(_0x8ce6('0x4'));var moment=require(_0x8ce6('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x8ce6('0x6'));var util=require(_0x8ce6('0x7'));var path=require(_0x8ce6('0x8'));var sox=require('sox');var csv=require(_0x8ce6('0x9'));var ejs=require(_0x8ce6('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x8ce6('0xb'));var jsforce=require(_0x8ce6('0xc'));var deskjs=require(_0x8ce6('0xd'));var toCsv=require(_0x8ce6('0x9'));var querystring=require('querystring');var Papa=require(_0x8ce6('0xe'));var Redis=require(_0x8ce6('0xf'));var authService=require(_0x8ce6('0x10'));var qs=require(_0x8ce6('0x11'));var hardwareService=require(_0x8ce6('0x12'));var logger=require(_0x8ce6('0x13'))(_0x8ce6('0x14'));var utils=require(_0x8ce6('0x15'));var config=require(_0x8ce6('0x16'));var db=require(_0x8ce6('0x17'))['db'];function respondWithStatusCode(_0x3476c1,_0x461841){_0x461841=_0x461841||0xcc;return function(_0x301a9b){if(_0x301a9b){return _0x3476c1[_0x8ce6('0x18')](_0x461841);}return _0x3476c1[_0x8ce6('0x19')](_0x461841)[_0x8ce6('0x1a')]();};}function respondWithResult(_0x38252e,_0x1d7aaf){_0x1d7aaf=_0x1d7aaf||0xc8;return function(_0x4a68fd){if(_0x4a68fd){return _0x38252e[_0x8ce6('0x19')](_0x1d7aaf)['json'](_0x4a68fd);}};}function respondWithFilteredResult(_0x216eb7,_0x349b16){return function(_0x150f89){if(_0x150f89){var _0x2ac4b3=_0x150f89[_0x8ce6('0x1b')],_0x2c2d7e=_0x349b16[_0x8ce6('0x1c')],_0x34cce2=_0x349b16[_0x8ce6('0x1c')]+_0x349b16['limit'],_0x25aa78;if(_0x34cce2>=_0x2ac4b3){_0x34cce2=_0x2ac4b3;_0x25aa78=0xc8;}else{_0x25aa78=0xce;}_0x216eb7[_0x8ce6('0x19')](_0x25aa78);return _0x216eb7['set'](_0x8ce6('0x1d'),_0x2c2d7e+'-'+_0x34cce2+'/'+_0x2ac4b3)[_0x8ce6('0x1e')](_0x150f89);}return null;};}function patchUpdates(_0xb18a16){return function(_0x50e2f7){try{jsonpatch['apply'](_0x50e2f7,_0xb18a16,!![]);}catch(_0x30e233){return BPromise[_0x8ce6('0x1f')](_0x30e233);}return _0x50e2f7['save']();};}function saveUpdates(_0x1876eb,_0x1b2602){return function(_0x444cba){if(_0x444cba){return _0x444cba[_0x8ce6('0x20')](_0x1876eb)[_0x8ce6('0x21')](function(_0x1b2b91){return _0x1b2b91;});}return null;};}function removeEntity(_0x5709d,_0x34c00f){return function(_0x2fef1c){if(_0x2fef1c){return _0x2fef1c[_0x8ce6('0x22')]()[_0x8ce6('0x21')](function(){_0x5709d[_0x8ce6('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x462c8b,_0x5e5702){return function(_0xdf5830){if(!_0xdf5830){_0x462c8b[_0x8ce6('0x18')](0x194);}return _0xdf5830;};}function handleError(_0x1c8ed7,_0x4a4316){_0x4a4316=_0x4a4316||0x1f4;return function(_0x4862b0){logger['error'](_0x4862b0['stack']);if(_0x4862b0[_0x8ce6('0x23')]){delete _0x4862b0[_0x8ce6('0x23')];}_0x1c8ed7[_0x8ce6('0x19')](_0x4a4316)[_0x8ce6('0x24')](_0x4862b0);};}exports[_0x8ce6('0x25')]=function(_0xadc624,_0x526e9e){var _0x5656ab={},_0x1233b0={},_0x6a0f99={'count':0x0,'rows':[]};var _0x31bf49=db[_0x8ce6('0x26')][_0x8ce6('0x27')];_0x1233b0[_0x8ce6('0x28')]=_['keys'](_0x31bf49);_0x1233b0['query']=_[_0x8ce6('0x29')](_0xadc624[_0x8ce6('0x2a')]);_0x1233b0[_0x8ce6('0x2b')]=_['intersection'](_0x1233b0[_0x8ce6('0x28')],_0x1233b0[_0x8ce6('0x2a')]);_0x5656ab[_0x8ce6('0x2c')]=_[_0x8ce6('0x2d')](_0x1233b0['model'],qs[_0x8ce6('0x2e')](_0xadc624[_0x8ce6('0x2a')]['fields']));_0x5656ab['attributes']=_0x5656ab[_0x8ce6('0x2c')][_0x8ce6('0x2f')]?_0x5656ab[_0x8ce6('0x2c')]:_0x1233b0[_0x8ce6('0x28')];if(!_0xadc624[_0x8ce6('0x2a')][_0x8ce6('0x30')](_0x8ce6('0x31'))){_0x5656ab[_0x8ce6('0x32')]=qs[_0x8ce6('0x32')](_0xadc624[_0x8ce6('0x2a')][_0x8ce6('0x32')]);_0x5656ab[_0x8ce6('0x1c')]=qs[_0x8ce6('0x1c')](_0xadc624[_0x8ce6('0x2a')][_0x8ce6('0x1c')]);}_0x5656ab[_0x8ce6('0x33')]=qs[_0x8ce6('0x34')](_0xadc624[_0x8ce6('0x2a')][_0x8ce6('0x34')]);_0x5656ab['where']=qs[_0x8ce6('0x2b')](_[_0x8ce6('0x35')](_0xadc624[_0x8ce6('0x2a')],_0x1233b0[_0x8ce6('0x2b')]));if(_0xadc624[_0x8ce6('0x2a')]['filter']){_0x5656ab['where']=_[_0x8ce6('0x36')](_0x5656ab[_0x8ce6('0x37')],{'$or':_['map'](_0x31bf49,function(_0x5199b4){if(_0x5199b4[_0x8ce6('0x38')][_0x8ce6('0x39')]!==_0x8ce6('0x3a')){var _0x32f26e={};_0x32f26e[_0x5199b4[_0x8ce6('0x3b')]]={'$like':'%'+_0xadc624[_0x8ce6('0x2a')]['filter']+'%'};return _0x32f26e;}})});}_0x5656ab=_[_0x8ce6('0x36')]({},_0x5656ab,_0xadc624['options']);var _0x14deb3={'where':_0x5656ab['where']};return db[_0x8ce6('0x26')][_0x8ce6('0x1b')](_0x14deb3)[_0x8ce6('0x21')](function(_0x3f3515){_0x6a0f99['count']=_0x3f3515;if(_0xadc624[_0x8ce6('0x2a')]['includeAll']){_0x5656ab[_0x8ce6('0x3c')]=[{'all':!![]}];}return db['VoiceTransferReport'][_0x8ce6('0x3d')](_0x5656ab);})[_0x8ce6('0x21')](function(_0x265495){_0x6a0f99['rows']=_0x265495;return _0x6a0f99;})[_0x8ce6('0x21')](respondWithFilteredResult(_0x526e9e,_0x5656ab))[_0x8ce6('0x3e')](handleError(_0x526e9e,null));};exports[_0x8ce6('0x3f')]=function(_0x4f0e3f,_0x3c98d9){var _0x37a47f={'raw':!![],'where':{'id':_0x4f0e3f[_0x8ce6('0x40')]['id']}},_0x5a5424={};_0x5a5424[_0x8ce6('0x28')]=_[_0x8ce6('0x29')](db['VoiceTransferReport'][_0x8ce6('0x27')]);_0x5a5424[_0x8ce6('0x2a')]=_[_0x8ce6('0x29')](_0x4f0e3f[_0x8ce6('0x2a')]);_0x5a5424[_0x8ce6('0x2b')]=_[_0x8ce6('0x2d')](_0x5a5424[_0x8ce6('0x28')],_0x5a5424[_0x8ce6('0x2a')]);_0x37a47f[_0x8ce6('0x2c')]=_[_0x8ce6('0x2d')](_0x5a5424[_0x8ce6('0x28')],qs[_0x8ce6('0x2e')](_0x4f0e3f[_0x8ce6('0x2a')][_0x8ce6('0x2e')]));_0x37a47f[_0x8ce6('0x2c')]=_0x37a47f['attributes'][_0x8ce6('0x2f')]?_0x37a47f[_0x8ce6('0x2c')]:_0x5a5424[_0x8ce6('0x28')];if(_0x4f0e3f[_0x8ce6('0x2a')][_0x8ce6('0x41')]){_0x37a47f[_0x8ce6('0x3c')]=[{'all':!![]}];}_0x37a47f=_[_0x8ce6('0x36')]({},_0x37a47f,_0x4f0e3f[_0x8ce6('0x42')]);return db[_0x8ce6('0x26')][_0x8ce6('0x43')](_0x37a47f)[_0x8ce6('0x21')](handleEntityNotFound(_0x3c98d9,null))[_0x8ce6('0x21')](respondWithResult(_0x3c98d9,null))['catch'](handleError(_0x3c98d9,null));};exports[_0x8ce6('0x44')]=function(_0x29b020,_0x16ba59){return db[_0x8ce6('0x26')][_0x8ce6('0x44')](_0x29b020[_0x8ce6('0x45')],{})['then'](respondWithResult(_0x16ba59,0xc9))[_0x8ce6('0x3e')](handleError(_0x16ba59,null));};exports[_0x8ce6('0x20')]=function(_0x23de47,_0x3af196){if(_0x23de47[_0x8ce6('0x45')]['id']){delete _0x23de47[_0x8ce6('0x45')]['id'];}return db['VoiceTransferReport'][_0x8ce6('0x43')]({'where':{'id':_0x23de47[_0x8ce6('0x40')]['id']}})['then'](handleEntityNotFound(_0x3af196,null))[_0x8ce6('0x21')](saveUpdates(_0x23de47[_0x8ce6('0x45')],null))[_0x8ce6('0x21')](respondWithResult(_0x3af196,null))[_0x8ce6('0x3e')](handleError(_0x3af196,null));};exports[_0x8ce6('0x22')]=function(_0x5a6ff0,_0xbafc5a){return db[_0x8ce6('0x26')]['find']({'where':{'id':_0x5a6ff0[_0x8ce6('0x40')]['id']}})['then'](handleEntityNotFound(_0xbafc5a,null))['then'](removeEntity(_0xbafc5a,null))['catch'](handleError(_0xbafc5a,null));};