Built motion from commit (unavailable).|2.5.3
[motion2.git] / server / api / voiceCallReport / voiceCallReport.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 _0xf403=['key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','options','includeAll','include','fullname','alias','User','catch','show','params','find','create','body','describe','user','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','status','end','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','sendStatus','error','stack','name','send','index','map','VoiceCallReport','rawAttributes','fieldName','type'];(function(_0x307d86,_0x9264f2){var _0x361745=function(_0x1b64e1){while(--_0x1b64e1){_0x307d86['push'](_0x307d86['shift']());}};_0x361745(++_0x9264f2);}(_0xf403,0x1e5));var _0x3f40=function(_0x4fbee0,_0x45f69c){_0x4fbee0=_0x4fbee0-0x0;var _0x465779=_0xf403[_0x4fbee0];return _0x465779;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x3f40('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x3f40('0x1'));var rp=require(_0x3f40('0x2'));var moment=require(_0x3f40('0x3'));var BPromise=require(_0x3f40('0x4'));var Mustache=require('mustache');var util=require(_0x3f40('0x5'));var path=require(_0x3f40('0x6'));var sox=require(_0x3f40('0x7'));var csv=require(_0x3f40('0x8'));var ejs=require(_0x3f40('0x9'));var fs=require('fs');var _=require(_0x3f40('0xa'));var squel=require(_0x3f40('0xb'));var crypto=require('crypto');var jsforce=require(_0x3f40('0xc'));var deskjs=require(_0x3f40('0xd'));var toCsv=require('to-csv');var querystring=require(_0x3f40('0xe'));var Papa=require(_0x3f40('0xf'));var Redis=require(_0x3f40('0x10'));var authService=require(_0x3f40('0x11'));var qs=require(_0x3f40('0x12'));var as=require(_0x3f40('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3f40('0x14'));var utils=require(_0x3f40('0x15'));var config=require(_0x3f40('0x16'));var db=require(_0x3f40('0x17'))['db'];function respondWithStatusCode(_0x3a8629,_0x43f618){_0x43f618=_0x43f618||0xcc;return function(_0x2360ea){if(_0x2360ea){return _0x3a8629['sendStatus'](_0x43f618);}return _0x3a8629[_0x3f40('0x18')](_0x43f618)[_0x3f40('0x19')]();};}function respondWithResult(_0x36e3e4,_0x2f32a1){_0x2f32a1=_0x2f32a1||0xc8;return function(_0x3cd4bd){if(_0x3cd4bd){return _0x36e3e4[_0x3f40('0x18')](_0x2f32a1)['json'](_0x3cd4bd);}};}function respondWithFilteredResult(_0x311dcb,_0x3e2654){return function(_0x44ce34){if(_0x44ce34){var _0x106fcf=_0x44ce34[_0x3f40('0x1a')],_0x11b538=_0x3e2654['offset'],_0x49514e=_0x3e2654[_0x3f40('0x1b')]+_0x3e2654[_0x3f40('0x1c')],_0x1a3539;if(_0x49514e>=_0x106fcf){_0x49514e=_0x106fcf;_0x1a3539=0xc8;}else{_0x1a3539=0xce;}_0x311dcb['status'](_0x1a3539);return _0x311dcb[_0x3f40('0x1d')](_0x3f40('0x1e'),_0x11b538+'-'+_0x49514e+'/'+_0x106fcf)['json'](_0x44ce34);}return null;};}function patchUpdates(_0x6af5aa){return function(_0xde3f8d){try{jsonpatch[_0x3f40('0x1f')](_0xde3f8d,_0x6af5aa,!![]);}catch(_0x47fca3){return BPromise['reject'](_0x47fca3);}return _0xde3f8d[_0x3f40('0x20')]();};}function saveUpdates(_0x31e24f,_0x13e619){return function(_0x5d0945){if(_0x5d0945){return _0x5d0945[_0x3f40('0x21')](_0x31e24f)[_0x3f40('0x22')](function(_0x4fd49a){return _0x4fd49a;});}return null;};}function removeEntity(_0x5ede22,_0x5dcf0e){return function(_0x3b915e){if(_0x3b915e){return _0x3b915e[_0x3f40('0x23')]()['then'](function(){_0x5ede22[_0x3f40('0x18')](0xcc)[_0x3f40('0x19')]();});}};}function handleEntityNotFound(_0x3604ff,_0x7c2d32){return function(_0x3731be){if(!_0x3731be){_0x3604ff[_0x3f40('0x24')](0x194);}return _0x3731be;};}function handleError(_0x3c98cd,_0x38db80){_0x38db80=_0x38db80||0x1f4;return function(_0x2c6845){logger[_0x3f40('0x25')](_0x2c6845[_0x3f40('0x26')]);if(_0x2c6845[_0x3f40('0x27')]){delete _0x2c6845[_0x3f40('0x27')];}_0x3c98cd['status'](_0x38db80)[_0x3f40('0x28')](_0x2c6845);};}exports[_0x3f40('0x29')]=function(_0x3e4c1c,_0x4e8642){var _0x42094b={},_0x24dcb0={},_0x533964={'count':0x0,'rows':[]};var _0x338e45=_[_0x3f40('0x2a')](db[_0x3f40('0x2b')][_0x3f40('0x2c')],function(_0x13f584){return{'name':_0x13f584[_0x3f40('0x2d')],'type':_0x13f584[_0x3f40('0x2e')][_0x3f40('0x2f')]};});_0x24dcb0[_0x3f40('0x30')]=_[_0x3f40('0x2a')](_0x338e45,_0x3f40('0x27'));_0x24dcb0[_0x3f40('0x31')]=_[_0x3f40('0x32')](_0x3e4c1c[_0x3f40('0x31')]);_0x24dcb0[_0x3f40('0x33')]=_[_0x3f40('0x34')](_0x24dcb0[_0x3f40('0x30')],_0x24dcb0[_0x3f40('0x31')]);_0x42094b[_0x3f40('0x35')]=_[_0x3f40('0x34')](_0x24dcb0[_0x3f40('0x30')],qs[_0x3f40('0x36')](_0x3e4c1c[_0x3f40('0x31')][_0x3f40('0x36')]));_0x42094b['attributes']=_0x42094b[_0x3f40('0x35')][_0x3f40('0x37')]?_0x42094b[_0x3f40('0x35')]:_0x24dcb0[_0x3f40('0x30')];if(!_0x3e4c1c['query']['hasOwnProperty'](_0x3f40('0x38'))){_0x42094b[_0x3f40('0x1c')]=qs[_0x3f40('0x1c')](_0x3e4c1c['query'][_0x3f40('0x1c')]);_0x42094b['offset']=qs[_0x3f40('0x1b')](_0x3e4c1c['query'][_0x3f40('0x1b')]);}_0x42094b['order']=qs['sort'](_0x3e4c1c[_0x3f40('0x31')][_0x3f40('0x39')]);_0x42094b[_0x3f40('0x3a')]=qs['filters'](_[_0x3f40('0x3b')](_0x3e4c1c['query'],_0x24dcb0[_0x3f40('0x33')]),_0x338e45);if(_0x3e4c1c[_0x3f40('0x31')][_0x3f40('0x3c')]){_0x42094b[_0x3f40('0x3a')]=_[_0x3f40('0x3d')](_0x42094b[_0x3f40('0x3a')],{'$or':_[_0x3f40('0x2a')](_0x338e45,function(_0x17cf6f){if(_0x17cf6f[_0x3f40('0x2e')]!=='VIRTUAL'){var _0x46282e={};_0x46282e[_0x17cf6f[_0x3f40('0x27')]]={'$like':'%'+_0x3e4c1c['query']['filter']+'%'};return _0x46282e;}})});}_0x42094b=_[_0x3f40('0x3d')]({},_0x42094b,_0x3e4c1c[_0x3f40('0x3e')]);var _0x534be1={'where':_0x42094b[_0x3f40('0x3a')]};return db[_0x3f40('0x2b')][_0x3f40('0x1a')](_0x534be1)[_0x3f40('0x22')](function(_0x4fa69b){_0x533964[_0x3f40('0x1a')]=_0x4fa69b;if(_0x3e4c1c['query'][_0x3f40('0x3f')]){_0x42094b[_0x3f40('0x40')]=[{'attributes':['id',_0x3f40('0x27'),_0x3f40('0x41'),_0x3f40('0x42')],'model':db[_0x3f40('0x43')],'as':_0x3f40('0x43')}];}return db[_0x3f40('0x2b')]['findAll'](_0x42094b);})[_0x3f40('0x22')](function(_0x35f877){_0x533964['rows']=_0x35f877;return _0x533964;})[_0x3f40('0x22')](respondWithFilteredResult(_0x4e8642,_0x42094b))[_0x3f40('0x44')](handleError(_0x4e8642,null));};exports[_0x3f40('0x45')]=function(_0x199edc,_0x3fba07){var _0x3e4810={'raw':!![],'where':{'id':_0x199edc[_0x3f40('0x46')]['id']}},_0x406507={};_0x406507['model']=_[_0x3f40('0x32')](db['VoiceCallReport'][_0x3f40('0x2c')]);_0x406507[_0x3f40('0x31')]=_[_0x3f40('0x32')](_0x199edc['query']);_0x406507['filters']=_[_0x3f40('0x34')](_0x406507['model'],_0x406507['query']);_0x3e4810[_0x3f40('0x35')]=_[_0x3f40('0x34')](_0x406507[_0x3f40('0x30')],qs[_0x3f40('0x36')](_0x199edc['query'][_0x3f40('0x36')]));_0x3e4810[_0x3f40('0x35')]=_0x3e4810[_0x3f40('0x35')][_0x3f40('0x37')]?_0x3e4810[_0x3f40('0x35')]:_0x406507[_0x3f40('0x30')];if(_0x199edc[_0x3f40('0x31')][_0x3f40('0x3f')]){_0x3e4810['include']=[{'all':!![]}];}_0x3e4810=_[_0x3f40('0x3d')]({},_0x3e4810,_0x199edc[_0x3f40('0x3e')]);return db['VoiceCallReport'][_0x3f40('0x47')](_0x3e4810)['then'](handleEntityNotFound(_0x3fba07,null))['then'](respondWithResult(_0x3fba07,null))[_0x3f40('0x44')](handleError(_0x3fba07,null));};exports[_0x3f40('0x48')]=function(_0x589119,_0x29ca08){return db[_0x3f40('0x2b')][_0x3f40('0x48')](_0x589119[_0x3f40('0x49')],{})[_0x3f40('0x22')](respondWithResult(_0x29ca08,0xc9))['catch'](handleError(_0x29ca08,null));};exports[_0x3f40('0x23')]=function(_0x254e19,_0x5e97d8){return db[_0x3f40('0x2b')]['find']({'where':{'id':_0x254e19[_0x3f40('0x46')]['id']}})[_0x3f40('0x22')](handleEntityNotFound(_0x5e97d8,null))['then'](removeEntity(_0x5e97d8,null))[_0x3f40('0x44')](handleError(_0x5e97d8,null));};exports[_0x3f40('0x4a')]=function(_0x1677c9,_0x3bbc3a){return db[_0x3f40('0x2b')][_0x3f40('0x4a')]()['then'](respondWithResult(_0x3bbc3a,null))[_0x3f40('0x44')](handleError(_0x3bbc3a,null));};exports['update']=function(_0x1c9378,_0x441429){if(_0x1c9378[_0x3f40('0x49')]['uniqueid']){delete _0x1c9378[_0x3f40('0x49')]['uniqueid'];}return db[_0x3f40('0x2b')][_0x3f40('0x47')]({'where':{'uniqueid':_0x1c9378[_0x3f40('0x46')]['id'],'UserId':{'$or':[null,_0x1c9378[_0x3f40('0x4b')]['id']]}}})[_0x3f40('0x22')](handleEntityNotFound(_0x441429,null))[_0x3f40('0x22')](saveUpdates(_0x1c9378[_0x3f40('0x49')],null))[_0x3f40('0x22')](respondWithResult(_0x441429,null))['catch'](handleError(_0x441429,null));};