35f9e0fb2c35c09fdcf09dfe627f64da332777ff
[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 _0xbfa2=['offset','undefined','count','set','Content-Range','reject','update','then','destroy','error','stack','name','index','VoiceTransferReport','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','where','pick','filter','merge','map','type','VIRTUAL','options','findAll','rows','catch','show','params','includeAll','find','create','body','describe','eml-format','rimraf','zip-dir','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json'];(function(_0x267a2d,_0x204cb8){var _0x3f660a=function(_0xa7a70c){while(--_0xa7a70c){_0x267a2d['push'](_0x267a2d['shift']());}};_0x3f660a(++_0x204cb8);}(_0xbfa2,0x1a1));var _0x2bfa=function(_0x29f887,_0x521f0f){_0x29f887=_0x29f887-0x0;var _0x220aed=_0xbfa2[_0x29f887];return _0x220aed;};'use strict';var emlformat=require(_0x2bfa('0x0'));var rimraf=require(_0x2bfa('0x1'));var zipdir=require(_0x2bfa('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x2bfa('0x3'));var Mustache=require(_0x2bfa('0x4'));var util=require(_0x2bfa('0x5'));var path=require(_0x2bfa('0x6'));var sox=require(_0x2bfa('0x7'));var csv=require(_0x2bfa('0x8'));var ejs=require(_0x2bfa('0x9'));var fs=require('fs');var fs_extra=require(_0x2bfa('0xa'));var _=require(_0x2bfa('0xb'));var squel=require(_0x2bfa('0xc'));var crypto=require(_0x2bfa('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x2bfa('0xe'));var toCsv=require(_0x2bfa('0x8'));var querystring=require('querystring');var Papa=require(_0x2bfa('0xf'));var Redis=require('ioredis');var authService=require(_0x2bfa('0x10'));var qs=require(_0x2bfa('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x2bfa('0x12'))(_0x2bfa('0x13'));var utils=require(_0x2bfa('0x14'));var config=require(_0x2bfa('0x15'));var licenseUtil=require(_0x2bfa('0x16'));var db=require(_0x2bfa('0x17'))['db'];function respondWithStatusCode(_0x377e34,_0x1fad4a){_0x1fad4a=_0x1fad4a||0xcc;return function(_0x5124a3){if(_0x5124a3){return _0x377e34['sendStatus'](_0x1fad4a);}return _0x377e34[_0x2bfa('0x18')](_0x1fad4a)[_0x2bfa('0x19')]();};}function respondWithResult(_0x5b9b8b,_0x1cd9bd){_0x1cd9bd=_0x1cd9bd||0xc8;return function(_0x39efd7){if(_0x39efd7){return _0x5b9b8b['status'](_0x1cd9bd)[_0x2bfa('0x1a')](_0x39efd7);}};}function respondWithFilteredResult(_0x5f0445,_0x28ab93){return function(_0x20fef5){if(_0x20fef5){var _0x5d2644=typeof _0x28ab93[_0x2bfa('0x1b')]===_0x2bfa('0x1c')&&typeof _0x28ab93['limit']===_0x2bfa('0x1c');var _0x14a3ed=_0x20fef5[_0x2bfa('0x1d')];var _0x4d3785=_0x5d2644?0x0:_0x28ab93[_0x2bfa('0x1b')];var _0x2536e1=_0x5d2644?_0x20fef5[_0x2bfa('0x1d')]:_0x28ab93['offset']+_0x28ab93['limit'];var _0x5306fb;if(_0x2536e1>=_0x14a3ed){_0x2536e1=_0x14a3ed;_0x5306fb=0xc8;}else{_0x5306fb=0xce;}_0x5f0445['status'](_0x5306fb);return _0x5f0445[_0x2bfa('0x1e')](_0x2bfa('0x1f'),_0x4d3785+'-'+_0x2536e1+'/'+_0x14a3ed)[_0x2bfa('0x1a')](_0x20fef5);}return null;};}function patchUpdates(_0x158e64){return function(_0x118590){try{jsonpatch['apply'](_0x118590,_0x158e64,!![]);}catch(_0x54edf1){return BPromise[_0x2bfa('0x20')](_0x54edf1);}return _0x118590['save']();};}function saveUpdates(_0x14bd23,_0x47bc27){return function(_0x1d29ed){if(_0x1d29ed){return _0x1d29ed[_0x2bfa('0x21')](_0x14bd23)[_0x2bfa('0x22')](function(_0x3f5236){return _0x3f5236;});}return null;};}function removeEntity(_0x1e894f,_0xe50db4){return function(_0x1a3b72){if(_0x1a3b72){return _0x1a3b72[_0x2bfa('0x23')]()[_0x2bfa('0x22')](function(){_0x1e894f[_0x2bfa('0x18')](0xcc)[_0x2bfa('0x19')]();});}};}function handleEntityNotFound(_0xa3d1d2,_0x36bb35){return function(_0x585092){if(!_0x585092){_0xa3d1d2['sendStatus'](0x194);}return _0x585092;};}function handleError(_0x24c963,_0x266699){_0x266699=_0x266699||0x1f4;return function(_0x25f683){logger[_0x2bfa('0x24')](_0x25f683[_0x2bfa('0x25')]);if(_0x25f683[_0x2bfa('0x26')]){delete _0x25f683[_0x2bfa('0x26')];}_0x24c963['status'](_0x266699)['send'](_0x25f683);};}exports[_0x2bfa('0x27')]=function(_0x5bf626,_0x3cce68){var _0x465daa={},_0x4da69b={},_0x1eb257={'count':0x0,'rows':[]};var _0xe8924e=_['map'](db[_0x2bfa('0x28')][_0x2bfa('0x29')],function(_0x4d1ccb){return{'name':_0x4d1ccb[_0x2bfa('0x2a')],'type':_0x4d1ccb['type'][_0x2bfa('0x2b')]};});_0x4da69b[_0x2bfa('0x2c')]=_['map'](_0xe8924e,_0x2bfa('0x26'));_0x4da69b[_0x2bfa('0x2d')]=_[_0x2bfa('0x2e')](_0x5bf626[_0x2bfa('0x2d')]);_0x4da69b[_0x2bfa('0x2f')]=_[_0x2bfa('0x30')](_0x4da69b[_0x2bfa('0x2c')],_0x4da69b['query']);_0x465daa[_0x2bfa('0x31')]=_[_0x2bfa('0x30')](_0x4da69b[_0x2bfa('0x2c')],qs[_0x2bfa('0x32')](_0x5bf626[_0x2bfa('0x2d')]['fields']));_0x465daa['attributes']=_0x465daa['attributes'][_0x2bfa('0x33')]?_0x465daa[_0x2bfa('0x31')]:_0x4da69b[_0x2bfa('0x2c')];if(!_0x5bf626[_0x2bfa('0x2d')][_0x2bfa('0x34')](_0x2bfa('0x35'))){_0x465daa[_0x2bfa('0x36')]=qs[_0x2bfa('0x36')](_0x5bf626[_0x2bfa('0x2d')][_0x2bfa('0x36')]);_0x465daa[_0x2bfa('0x1b')]=qs[_0x2bfa('0x1b')](_0x5bf626[_0x2bfa('0x2d')]['offset']);}_0x465daa[_0x2bfa('0x37')]=qs['sort'](_0x5bf626[_0x2bfa('0x2d')]['sort']);_0x465daa[_0x2bfa('0x38')]=qs[_0x2bfa('0x2f')](_[_0x2bfa('0x39')](_0x5bf626[_0x2bfa('0x2d')],_0x4da69b[_0x2bfa('0x2f')]),_0xe8924e);if(_0x5bf626['query'][_0x2bfa('0x3a')]){_0x465daa['where']=_[_0x2bfa('0x3b')](_0x465daa['where'],{'$or':_[_0x2bfa('0x3c')](_0xe8924e,function(_0x3dbe12){if(_0x3dbe12[_0x2bfa('0x3d')]!==_0x2bfa('0x3e')){var _0x361781={};_0x361781[_0x3dbe12[_0x2bfa('0x26')]]={'$like':'%'+_0x5bf626['query'][_0x2bfa('0x3a')]+'%'};return _0x361781;}})});}_0x465daa=_[_0x2bfa('0x3b')]({},_0x465daa,_0x5bf626[_0x2bfa('0x3f')]);var _0x4d1f25={'where':_0x465daa[_0x2bfa('0x38')]};return db['VoiceTransferReport'][_0x2bfa('0x1d')](_0x4d1f25)[_0x2bfa('0x22')](function(_0x111077){_0x1eb257['count']=_0x111077;if(_0x5bf626['query']['includeAll']){_0x465daa['include']=[{'all':!![]}];}return db[_0x2bfa('0x28')][_0x2bfa('0x40')](_0x465daa);})[_0x2bfa('0x22')](function(_0x31f589){_0x1eb257[_0x2bfa('0x41')]=_0x31f589;return _0x1eb257;})['then'](respondWithFilteredResult(_0x3cce68,_0x465daa))[_0x2bfa('0x42')](handleError(_0x3cce68,null));};exports[_0x2bfa('0x43')]=function(_0x51fea9,_0x2f9ace){var _0x158d44={'raw':!![],'where':{'id':_0x51fea9[_0x2bfa('0x44')]['id']}},_0x382af6={};_0x382af6[_0x2bfa('0x2c')]=_['keys'](db['VoiceTransferReport']['rawAttributes']);_0x382af6['query']=_[_0x2bfa('0x2e')](_0x51fea9[_0x2bfa('0x2d')]);_0x382af6['filters']=_[_0x2bfa('0x30')](_0x382af6[_0x2bfa('0x2c')],_0x382af6[_0x2bfa('0x2d')]);_0x158d44[_0x2bfa('0x31')]=_[_0x2bfa('0x30')](_0x382af6[_0x2bfa('0x2c')],qs[_0x2bfa('0x32')](_0x51fea9[_0x2bfa('0x2d')][_0x2bfa('0x32')]));_0x158d44[_0x2bfa('0x31')]=_0x158d44[_0x2bfa('0x31')][_0x2bfa('0x33')]?_0x158d44[_0x2bfa('0x31')]:_0x382af6[_0x2bfa('0x2c')];if(_0x51fea9[_0x2bfa('0x2d')][_0x2bfa('0x45')]){_0x158d44['include']=[{'all':!![]}];}_0x158d44=_[_0x2bfa('0x3b')]({},_0x158d44,_0x51fea9[_0x2bfa('0x3f')]);return db[_0x2bfa('0x28')][_0x2bfa('0x46')](_0x158d44)[_0x2bfa('0x22')](handleEntityNotFound(_0x2f9ace,null))[_0x2bfa('0x22')](respondWithResult(_0x2f9ace,null))['catch'](handleError(_0x2f9ace,null));};exports[_0x2bfa('0x47')]=function(_0x102450,_0x261858){return db['VoiceTransferReport']['create'](_0x102450[_0x2bfa('0x48')],{})['then'](respondWithResult(_0x261858,0xc9))['catch'](handleError(_0x261858,null));};exports[_0x2bfa('0x21')]=function(_0x7c221b,_0xc31a85){if(_0x7c221b[_0x2bfa('0x48')]['id']){delete _0x7c221b[_0x2bfa('0x48')]['id'];}return db[_0x2bfa('0x28')]['find']({'where':{'id':_0x7c221b['params']['id']}})[_0x2bfa('0x22')](handleEntityNotFound(_0xc31a85,null))[_0x2bfa('0x22')](saveUpdates(_0x7c221b[_0x2bfa('0x48')],null))[_0x2bfa('0x22')](respondWithResult(_0xc31a85,null))[_0x2bfa('0x42')](handleError(_0xc31a85,null));};exports[_0x2bfa('0x23')]=function(_0x1859a6,_0x72d5d3){return db['VoiceTransferReport'][_0x2bfa('0x46')]({'where':{'id':_0x1859a6[_0x2bfa('0x44')]['id']}})[_0x2bfa('0x22')](handleEntityNotFound(_0x72d5d3,null))[_0x2bfa('0x22')](removeEntity(_0x72d5d3,null))[_0x2bfa('0x42')](handleError(_0x72d5d3,null));};exports[_0x2bfa('0x49')]=function(_0x381176,_0x1f2289){return db['VoiceTransferReport'][_0x2bfa('0x49')]()[_0x2bfa('0x22')](respondWithResult(_0x1f2289,null))[_0x2bfa('0x42')](handleError(_0x1f2289,null));};