Built motion from commit e0fa946e.|2.6.5
[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 _0x9abc=['intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','map','merge','options','includeAll','findAll','show','include','find','catch','create','body','params','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','fs-extra','lodash','squel','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','VoiceTransferReport','rawAttributes','fieldName','type','key','model','query','keys','filters'];(function(_0x13b7fd,_0x4eaf7f){var _0x32a74a=function(_0x2c5d80){while(--_0x2c5d80){_0x13b7fd['push'](_0x13b7fd['shift']());}};_0x32a74a(++_0x4eaf7f);}(_0x9abc,0x143));var _0xc9ab=function(_0x2ee95b,_0x11de64){_0x2ee95b=_0x2ee95b-0x0;var _0xc66272=_0x9abc[_0x2ee95b];return _0xc66272;};'use strict';var emlformat=require(_0xc9ab('0x0'));var rimraf=require(_0xc9ab('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xc9ab('0x2'));var rp=require(_0xc9ab('0x3'));var moment=require(_0xc9ab('0x4'));var BPromise=require(_0xc9ab('0x5'));var Mustache=require(_0xc9ab('0x6'));var util=require(_0xc9ab('0x7'));var path=require('path');var sox=require(_0xc9ab('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xc9ab('0x9'));var _=require(_0xc9ab('0xa'));var squel=require(_0xc9ab('0xb'));var crypto=require('crypto');var jsforce=require(_0xc9ab('0xc'));var deskjs=require(_0xc9ab('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xc9ab('0xe'));var Redis=require('ioredis');var authService=require(_0xc9ab('0xf'));var qs=require(_0xc9ab('0x10'));var as=require(_0xc9ab('0x11'));var hardwareService=require(_0xc9ab('0x12'));var logger=require(_0xc9ab('0x13'))(_0xc9ab('0x14'));var utils=require(_0xc9ab('0x15'));var config=require(_0xc9ab('0x16'));var licenseUtil=require(_0xc9ab('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x15be99,_0x36b39a){_0x36b39a=_0x36b39a||0xcc;return function(_0x73c4cf){if(_0x73c4cf){return _0x15be99[_0xc9ab('0x18')](_0x36b39a);}return _0x15be99[_0xc9ab('0x19')](_0x36b39a)[_0xc9ab('0x1a')]();};}function respondWithResult(_0x53e2ce,_0x305b20){_0x305b20=_0x305b20||0xc8;return function(_0x4287d4){if(_0x4287d4){return _0x53e2ce['status'](_0x305b20)[_0xc9ab('0x1b')](_0x4287d4);}};}function respondWithFilteredResult(_0x545006,_0x4503ed){return function(_0x13d4e0){if(_0x13d4e0){var _0x520efe=typeof _0x4503ed[_0xc9ab('0x1c')]===_0xc9ab('0x1d')&&typeof _0x4503ed['limit']===_0xc9ab('0x1d');var _0x2f70a4=_0x13d4e0[_0xc9ab('0x1e')];var _0x374eb9=_0x520efe?0x0:_0x4503ed[_0xc9ab('0x1c')];var _0x5f5d48=_0x520efe?_0x13d4e0[_0xc9ab('0x1e')]:_0x4503ed['offset']+_0x4503ed[_0xc9ab('0x1f')];var _0x17142b;if(_0x5f5d48>=_0x2f70a4){_0x5f5d48=_0x2f70a4;_0x17142b=0xc8;}else{_0x17142b=0xce;}_0x545006[_0xc9ab('0x19')](_0x17142b);return _0x545006['set'](_0xc9ab('0x20'),_0x374eb9+'-'+_0x5f5d48+'/'+_0x2f70a4)[_0xc9ab('0x1b')](_0x13d4e0);}return null;};}function patchUpdates(_0x253da0){return function(_0x5d4680){try{jsonpatch[_0xc9ab('0x21')](_0x5d4680,_0x253da0,!![]);}catch(_0x5bd540){return BPromise[_0xc9ab('0x22')](_0x5bd540);}return _0x5d4680[_0xc9ab('0x23')]();};}function saveUpdates(_0x2f7152,_0x4e3f5a){return function(_0x55e3ca){if(_0x55e3ca){return _0x55e3ca[_0xc9ab('0x24')](_0x2f7152)[_0xc9ab('0x25')](function(_0x1af6ec){return _0x1af6ec;});}return null;};}function removeEntity(_0x184bf8,_0xefed61){return function(_0x2810a1){if(_0x2810a1){return _0x2810a1['destroy']()[_0xc9ab('0x25')](function(){_0x184bf8[_0xc9ab('0x19')](0xcc)[_0xc9ab('0x1a')]();});}};}function handleEntityNotFound(_0x87df04,_0x44ad8d){return function(_0x1f75a2){if(!_0x1f75a2){_0x87df04[_0xc9ab('0x18')](0x194);}return _0x1f75a2;};}function handleError(_0x4b53e9,_0x4f1d1b){_0x4f1d1b=_0x4f1d1b||0x1f4;return function(_0x1b1e78){logger[_0xc9ab('0x26')](_0x1b1e78[_0xc9ab('0x27')]);if(_0x1b1e78[_0xc9ab('0x28')]){delete _0x1b1e78[_0xc9ab('0x28')];}_0x4b53e9[_0xc9ab('0x19')](_0x4f1d1b)[_0xc9ab('0x29')](_0x1b1e78);};}exports[_0xc9ab('0x2a')]=function(_0x1c9584,_0x3be764){var _0x29f390={},_0x5d4ed6={},_0x2c2f88={'count':0x0,'rows':[]};var _0x5a1a55=_['map'](db[_0xc9ab('0x2b')][_0xc9ab('0x2c')],function(_0x275445){return{'name':_0x275445[_0xc9ab('0x2d')],'type':_0x275445[_0xc9ab('0x2e')][_0xc9ab('0x2f')]};});_0x5d4ed6[_0xc9ab('0x30')]=_['map'](_0x5a1a55,_0xc9ab('0x28'));_0x5d4ed6[_0xc9ab('0x31')]=_[_0xc9ab('0x32')](_0x1c9584[_0xc9ab('0x31')]);_0x5d4ed6[_0xc9ab('0x33')]=_[_0xc9ab('0x34')](_0x5d4ed6[_0xc9ab('0x30')],_0x5d4ed6[_0xc9ab('0x31')]);_0x29f390[_0xc9ab('0x35')]=_[_0xc9ab('0x34')](_0x5d4ed6[_0xc9ab('0x30')],qs[_0xc9ab('0x36')](_0x1c9584['query']['fields']));_0x29f390[_0xc9ab('0x35')]=_0x29f390[_0xc9ab('0x35')][_0xc9ab('0x37')]?_0x29f390[_0xc9ab('0x35')]:_0x5d4ed6[_0xc9ab('0x30')];if(!_0x1c9584[_0xc9ab('0x31')][_0xc9ab('0x38')](_0xc9ab('0x39'))){_0x29f390[_0xc9ab('0x1f')]=qs[_0xc9ab('0x1f')](_0x1c9584[_0xc9ab('0x31')]['limit']);_0x29f390[_0xc9ab('0x1c')]=qs[_0xc9ab('0x1c')](_0x1c9584[_0xc9ab('0x31')][_0xc9ab('0x1c')]);}_0x29f390[_0xc9ab('0x3a')]=qs[_0xc9ab('0x3b')](_0x1c9584[_0xc9ab('0x31')][_0xc9ab('0x3b')]);_0x29f390[_0xc9ab('0x3c')]=qs[_0xc9ab('0x33')](_['pick'](_0x1c9584[_0xc9ab('0x31')],_0x5d4ed6[_0xc9ab('0x33')]),_0x5a1a55);if(_0x1c9584[_0xc9ab('0x31')][_0xc9ab('0x3d')]){_0x29f390[_0xc9ab('0x3c')]=_['merge'](_0x29f390[_0xc9ab('0x3c')],{'$or':_[_0xc9ab('0x3e')](_0x5a1a55,function(_0x112e51){if(_0x112e51[_0xc9ab('0x2e')]!=='VIRTUAL'){var _0x559de9={};_0x559de9[_0x112e51[_0xc9ab('0x28')]]={'$like':'%'+_0x1c9584[_0xc9ab('0x31')][_0xc9ab('0x3d')]+'%'};return _0x559de9;}})});}_0x29f390=_[_0xc9ab('0x3f')]({},_0x29f390,_0x1c9584[_0xc9ab('0x40')]);var _0x137f19={'where':_0x29f390[_0xc9ab('0x3c')]};return db[_0xc9ab('0x2b')][_0xc9ab('0x1e')](_0x137f19)[_0xc9ab('0x25')](function(_0x2d4161){_0x2c2f88[_0xc9ab('0x1e')]=_0x2d4161;if(_0x1c9584['query'][_0xc9ab('0x41')]){_0x29f390['include']=[{'all':!![]}];}return db['VoiceTransferReport'][_0xc9ab('0x42')](_0x29f390);})['then'](function(_0x5147cd){_0x2c2f88['rows']=_0x5147cd;return _0x2c2f88;})[_0xc9ab('0x25')](respondWithFilteredResult(_0x3be764,_0x29f390))['catch'](handleError(_0x3be764,null));};exports[_0xc9ab('0x43')]=function(_0x34db88,_0x33fa79){var _0x42f7b0={'raw':!![],'where':{'id':_0x34db88['params']['id']}},_0x350ee5={};_0x350ee5['model']=_['keys'](db[_0xc9ab('0x2b')][_0xc9ab('0x2c')]);_0x350ee5['query']=_[_0xc9ab('0x32')](_0x34db88[_0xc9ab('0x31')]);_0x350ee5[_0xc9ab('0x33')]=_[_0xc9ab('0x34')](_0x350ee5[_0xc9ab('0x30')],_0x350ee5['query']);_0x42f7b0[_0xc9ab('0x35')]=_['intersection'](_0x350ee5['model'],qs[_0xc9ab('0x36')](_0x34db88[_0xc9ab('0x31')][_0xc9ab('0x36')]));_0x42f7b0[_0xc9ab('0x35')]=_0x42f7b0[_0xc9ab('0x35')][_0xc9ab('0x37')]?_0x42f7b0[_0xc9ab('0x35')]:_0x350ee5[_0xc9ab('0x30')];if(_0x34db88[_0xc9ab('0x31')]['includeAll']){_0x42f7b0[_0xc9ab('0x44')]=[{'all':!![]}];}_0x42f7b0=_['merge']({},_0x42f7b0,_0x34db88[_0xc9ab('0x40')]);return db[_0xc9ab('0x2b')][_0xc9ab('0x45')](_0x42f7b0)[_0xc9ab('0x25')](handleEntityNotFound(_0x33fa79,null))['then'](respondWithResult(_0x33fa79,null))[_0xc9ab('0x46')](handleError(_0x33fa79,null));};exports[_0xc9ab('0x47')]=function(_0xee5caf,_0x5a9bde){return db['VoiceTransferReport'][_0xc9ab('0x47')](_0xee5caf[_0xc9ab('0x48')],{})[_0xc9ab('0x25')](respondWithResult(_0x5a9bde,0xc9))['catch'](handleError(_0x5a9bde,null));};exports[_0xc9ab('0x24')]=function(_0x47e93d,_0x288d13){if(_0x47e93d['body']['id']){delete _0x47e93d[_0xc9ab('0x48')]['id'];}return db[_0xc9ab('0x2b')][_0xc9ab('0x45')]({'where':{'id':_0x47e93d[_0xc9ab('0x49')]['id']}})['then'](handleEntityNotFound(_0x288d13,null))[_0xc9ab('0x25')](saveUpdates(_0x47e93d['body'],null))['then'](respondWithResult(_0x288d13,null))[_0xc9ab('0x46')](handleError(_0x288d13,null));};exports['destroy']=function(_0x2395aa,_0x16b4b5){return db[_0xc9ab('0x2b')][_0xc9ab('0x45')]({'where':{'id':_0x2395aa['params']['id']}})[_0xc9ab('0x25')](handleEntityNotFound(_0x16b4b5,null))['then'](removeEntity(_0x16b4b5,null))[_0xc9ab('0x46')](handleError(_0x16b4b5,null));};exports[_0xc9ab('0x4a')]=function(_0x2d306d,_0x259b16){return db[_0xc9ab('0x2b')][_0xc9ab('0x4a')]()[_0xc9ab('0x25')](respondWithResult(_0x259b16,null))[_0xc9ab('0x46')](handleError(_0x259b16,null));};