3f44cf87d7f3c4d4c0dffb74cbc59497cd5a0a95
[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 _0xf702=['create','body','update','find','params','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','fs-extra','lodash','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','undefined','limit','count','offset','Content-Range','json','reject','save','destroy','then','error','stack','name','send','index','map','rawAttributes','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','filters','filter','merge','type','VIRTUAL','where','includeAll','VoiceTransferReport','findAll','rows','options','catch'];(function(_0x44b443,_0x14ae06){var _0x4432bc=function(_0x555ace){while(--_0x555ace){_0x44b443['push'](_0x44b443['shift']());}};_0x4432bc(++_0x14ae06);}(_0xf702,0x173));var _0x2f70=function(_0x25f358,_0x243df3){_0x25f358=_0x25f358-0x0;var _0x584195=_0xf702[_0x25f358];return _0x584195;};'use strict';var emlformat=require(_0x2f70('0x0'));var rimraf=require(_0x2f70('0x1'));var zipdir=require(_0x2f70('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x2f70('0x3'));var moment=require(_0x2f70('0x4'));var BPromise=require(_0x2f70('0x5'));var Mustache=require(_0x2f70('0x6'));var util=require(_0x2f70('0x7'));var path=require(_0x2f70('0x8'));var sox=require('sox');var csv=require(_0x2f70('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2f70('0xa'));var _=require(_0x2f70('0xb'));var squel=require('squel');var crypto=require(_0x2f70('0xc'));var jsforce=require(_0x2f70('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x2f70('0xe'));var Redis=require('ioredis');var authService=require(_0x2f70('0xf'));var qs=require(_0x2f70('0x10'));var as=require(_0x2f70('0x11'));var hardwareService=require(_0x2f70('0x12'));var logger=require(_0x2f70('0x13'))(_0x2f70('0x14'));var utils=require(_0x2f70('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x2f70('0x16'));var db=require(_0x2f70('0x17'))['db'];function respondWithStatusCode(_0x3f2ec1,_0x53990d){_0x53990d=_0x53990d||0xcc;return function(_0xf86afa){if(_0xf86afa){return _0x3f2ec1[_0x2f70('0x18')](_0x53990d);}return _0x3f2ec1[_0x2f70('0x19')](_0x53990d)[_0x2f70('0x1a')]();};}function respondWithResult(_0x211820,_0x28b855){_0x28b855=_0x28b855||0xc8;return function(_0x40af35){if(_0x40af35){return _0x211820[_0x2f70('0x19')](_0x28b855)['json'](_0x40af35);}};}function respondWithFilteredResult(_0x4af2b7,_0x286f3e){return function(_0x11296f){if(_0x11296f){var _0x34d37d=typeof _0x286f3e['offset']===_0x2f70('0x1b')&&typeof _0x286f3e[_0x2f70('0x1c')]===_0x2f70('0x1b');var _0x10e179=_0x11296f[_0x2f70('0x1d')];var _0x2231ec=_0x34d37d?0x0:_0x286f3e[_0x2f70('0x1e')];var _0x43ae14=_0x34d37d?_0x11296f[_0x2f70('0x1d')]:_0x286f3e['offset']+_0x286f3e[_0x2f70('0x1c')];var _0x502ed6;if(_0x43ae14>=_0x10e179){_0x43ae14=_0x10e179;_0x502ed6=0xc8;}else{_0x502ed6=0xce;}_0x4af2b7[_0x2f70('0x19')](_0x502ed6);return _0x4af2b7['set'](_0x2f70('0x1f'),_0x2231ec+'-'+_0x43ae14+'/'+_0x10e179)[_0x2f70('0x20')](_0x11296f);}return null;};}function patchUpdates(_0x30e6d6){return function(_0x2679c8){try{jsonpatch['apply'](_0x2679c8,_0x30e6d6,!![]);}catch(_0x5a79d8){return BPromise[_0x2f70('0x21')](_0x5a79d8);}return _0x2679c8[_0x2f70('0x22')]();};}function saveUpdates(_0x41ed56,_0x204557){return function(_0x6ae987){if(_0x6ae987){return _0x6ae987['update'](_0x41ed56)['then'](function(_0x12f595){return _0x12f595;});}return null;};}function removeEntity(_0x17ff36,_0x541e30){return function(_0xcaab9f){if(_0xcaab9f){return _0xcaab9f[_0x2f70('0x23')]()[_0x2f70('0x24')](function(){_0x17ff36[_0x2f70('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3f1449,_0x45153f){return function(_0x44ec3a){if(!_0x44ec3a){_0x3f1449[_0x2f70('0x18')](0x194);}return _0x44ec3a;};}function handleError(_0x59f39d,_0xff997a){_0xff997a=_0xff997a||0x1f4;return function(_0x3d252a){logger[_0x2f70('0x25')](_0x3d252a[_0x2f70('0x26')]);if(_0x3d252a[_0x2f70('0x27')]){delete _0x3d252a[_0x2f70('0x27')];}_0x59f39d[_0x2f70('0x19')](_0xff997a)[_0x2f70('0x28')](_0x3d252a);};}exports[_0x2f70('0x29')]=function(_0x26028c,_0x2a418f){var _0x40876d={},_0x2aeb27={},_0x1f7d13={'count':0x0,'rows':[]};var _0x20fcbf=_[_0x2f70('0x2a')](db['VoiceTransferReport'][_0x2f70('0x2b')],function(_0x62be4d){return{'name':_0x62be4d['fieldName'],'type':_0x62be4d['type'][_0x2f70('0x2c')]};});_0x2aeb27[_0x2f70('0x2d')]=_[_0x2f70('0x2a')](_0x20fcbf,_0x2f70('0x27'));_0x2aeb27[_0x2f70('0x2e')]=_[_0x2f70('0x2f')](_0x26028c[_0x2f70('0x2e')]);_0x2aeb27['filters']=_[_0x2f70('0x30')](_0x2aeb27[_0x2f70('0x2d')],_0x2aeb27[_0x2f70('0x2e')]);_0x40876d[_0x2f70('0x31')]=_[_0x2f70('0x30')](_0x2aeb27[_0x2f70('0x2d')],qs[_0x2f70('0x32')](_0x26028c['query'][_0x2f70('0x32')]));_0x40876d[_0x2f70('0x31')]=_0x40876d['attributes'][_0x2f70('0x33')]?_0x40876d[_0x2f70('0x31')]:_0x2aeb27['model'];if(!_0x26028c[_0x2f70('0x2e')][_0x2f70('0x34')](_0x2f70('0x35'))){_0x40876d[_0x2f70('0x1c')]=qs[_0x2f70('0x1c')](_0x26028c['query'][_0x2f70('0x1c')]);_0x40876d[_0x2f70('0x1e')]=qs['offset'](_0x26028c['query'][_0x2f70('0x1e')]);}_0x40876d['order']=qs['sort'](_0x26028c[_0x2f70('0x2e')][_0x2f70('0x36')]);_0x40876d['where']=qs[_0x2f70('0x37')](_['pick'](_0x26028c[_0x2f70('0x2e')],_0x2aeb27[_0x2f70('0x37')]),_0x20fcbf);if(_0x26028c['query'][_0x2f70('0x38')]){_0x40876d['where']=_[_0x2f70('0x39')](_0x40876d['where'],{'$or':_[_0x2f70('0x2a')](_0x20fcbf,function(_0x53d1e3){if(_0x53d1e3[_0x2f70('0x3a')]!==_0x2f70('0x3b')){var _0x3b5ce9={};_0x3b5ce9[_0x53d1e3[_0x2f70('0x27')]]={'$like':'%'+_0x26028c[_0x2f70('0x2e')][_0x2f70('0x38')]+'%'};return _0x3b5ce9;}})});}_0x40876d=_[_0x2f70('0x39')]({},_0x40876d,_0x26028c['options']);var _0x811c60={'where':_0x40876d[_0x2f70('0x3c')]};return db['VoiceTransferReport'][_0x2f70('0x1d')](_0x811c60)['then'](function(_0x379a69){_0x1f7d13[_0x2f70('0x1d')]=_0x379a69;if(_0x26028c['query'][_0x2f70('0x3d')]){_0x40876d['include']=[{'all':!![]}];}return db[_0x2f70('0x3e')][_0x2f70('0x3f')](_0x40876d);})[_0x2f70('0x24')](function(_0x35156e){_0x1f7d13[_0x2f70('0x40')]=_0x35156e;return _0x1f7d13;})['then'](respondWithFilteredResult(_0x2a418f,_0x40876d))['catch'](handleError(_0x2a418f,null));};exports['show']=function(_0x21d2e1,_0x19935b){var _0x185325={'raw':!![],'where':{'id':_0x21d2e1['params']['id']}},_0x5441b1={};_0x5441b1[_0x2f70('0x2d')]=_[_0x2f70('0x2f')](db['VoiceTransferReport'][_0x2f70('0x2b')]);_0x5441b1[_0x2f70('0x2e')]=_[_0x2f70('0x2f')](_0x21d2e1[_0x2f70('0x2e')]);_0x5441b1[_0x2f70('0x37')]=_['intersection'](_0x5441b1[_0x2f70('0x2d')],_0x5441b1[_0x2f70('0x2e')]);_0x185325[_0x2f70('0x31')]=_[_0x2f70('0x30')](_0x5441b1['model'],qs[_0x2f70('0x32')](_0x21d2e1[_0x2f70('0x2e')][_0x2f70('0x32')]));_0x185325['attributes']=_0x185325[_0x2f70('0x31')][_0x2f70('0x33')]?_0x185325[_0x2f70('0x31')]:_0x5441b1['model'];if(_0x21d2e1['query'][_0x2f70('0x3d')]){_0x185325['include']=[{'all':!![]}];}_0x185325=_['merge']({},_0x185325,_0x21d2e1[_0x2f70('0x41')]);return db[_0x2f70('0x3e')]['find'](_0x185325)['then'](handleEntityNotFound(_0x19935b,null))[_0x2f70('0x24')](respondWithResult(_0x19935b,null))[_0x2f70('0x42')](handleError(_0x19935b,null));};exports['create']=function(_0x1f42d1,_0x161796){return db['VoiceTransferReport'][_0x2f70('0x43')](_0x1f42d1[_0x2f70('0x44')],{})[_0x2f70('0x24')](respondWithResult(_0x161796,0xc9))[_0x2f70('0x42')](handleError(_0x161796,null));};exports[_0x2f70('0x45')]=function(_0x5a00bf,_0x162cbb){if(_0x5a00bf[_0x2f70('0x44')]['id']){delete _0x5a00bf['body']['id'];}return db[_0x2f70('0x3e')][_0x2f70('0x46')]({'where':{'id':_0x5a00bf[_0x2f70('0x47')]['id']}})['then'](handleEntityNotFound(_0x162cbb,null))['then'](saveUpdates(_0x5a00bf[_0x2f70('0x44')],null))[_0x2f70('0x24')](respondWithResult(_0x162cbb,null))[_0x2f70('0x42')](handleError(_0x162cbb,null));};exports['destroy']=function(_0x36e4eb,_0x5cde39){return db['VoiceTransferReport'][_0x2f70('0x46')]({'where':{'id':_0x36e4eb[_0x2f70('0x47')]['id']}})['then'](handleEntityNotFound(_0x5cde39,null))[_0x2f70('0x24')](removeEntity(_0x5cde39,null))['catch'](handleError(_0x5cde39,null));};exports['describe']=function(_0xbd301e,_0x1cbcd5){return db[_0x2f70('0x3e')][_0x2f70('0x48')]()[_0x2f70('0x24')](respondWithResult(_0x1cbcd5,null))[_0x2f70('0x42')](handleError(_0x1cbcd5,null));};