Built motion from commit 20b39a97.|2.6.29
[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 _0x7217=['find','create','describe','params','user','body','uniqueid','updateWithRetry','lodash','../../config/logger','api','../../mysqldb','promise-retry','status','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','end','error','stack','name','send','map','VoiceCallReport','rawAttributes','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','filter','merge','VIRTUAL','includeAll','include','fullname','alias','User','rows','catch','show','keys','options'];(function(_0x27d8bc,_0x19e010){var _0x4b04cb=function(_0x524568){while(--_0x524568){_0x27d8bc['push'](_0x27d8bc['shift']());}};_0x4b04cb(++_0x19e010);}(_0x7217,0x19e));var _0x7721=function(_0x1c546c,_0x5c57cb){_0x1c546c=_0x1c546c-0x0;var _0x2cc384=_0x7217[_0x1c546c];return _0x2cc384;};'use strict';var _=require(_0x7721('0x0'));var qs=require('../../components/parsers/qs');var logger=require(_0x7721('0x1'))(_0x7721('0x2'));var db=require(_0x7721('0x3'))['db'];const promiseRetry=require(_0x7721('0x4'));function respondWithResult(_0x115ab3,_0x4d6446){_0x4d6446=_0x4d6446||0xc8;return function(_0x5bf160){if(_0x5bf160){return _0x115ab3[_0x7721('0x5')](_0x4d6446)[_0x7721('0x6')](_0x5bf160);}};}function respondWithFilteredResult(_0x46415c,_0x3fe47c){return function(_0xb239e0){if(_0xb239e0){var _0xf7ff37=typeof _0x3fe47c[_0x7721('0x7')]===_0x7721('0x8')&&typeof _0x3fe47c[_0x7721('0x9')]===_0x7721('0x8');var _0x3e6368=_0xb239e0[_0x7721('0xa')];var _0xfa8835=_0xf7ff37?0x0:_0x3fe47c[_0x7721('0x7')];var _0x2c3986=_0xf7ff37?_0xb239e0['count']:_0x3fe47c[_0x7721('0x7')]+_0x3fe47c[_0x7721('0x9')];var _0x8729a6;if(_0x2c3986>=_0x3e6368){_0x2c3986=_0x3e6368;_0x8729a6=0xc8;}else{_0x8729a6=0xce;}_0x46415c[_0x7721('0x5')](_0x8729a6);return _0x46415c[_0x7721('0xb')](_0x7721('0xc'),_0xfa8835+'-'+_0x2c3986+'/'+_0x3e6368)[_0x7721('0x6')](_0xb239e0);}return null;};}function saveUpdates(_0x27b36b){return function(_0x55b4ca){if(_0x55b4ca){return _0x55b4ca[_0x7721('0xd')](_0x27b36b)[_0x7721('0xe')](function(_0x57ff6d){return _0x57ff6d;});}return null;};}function removeEntity(_0x109900){return function(_0x30da54){if(_0x30da54){return _0x30da54[_0x7721('0xf')]()[_0x7721('0xe')](function(){_0x109900['status'](0xcc)[_0x7721('0x10')]();});}};}function handleEntityNotFound(_0x25b1c0){return function(_0x534f1b){if(!_0x534f1b){_0x25b1c0['sendStatus'](0x194);}return _0x534f1b;};}function handleError(_0x4b183e,_0x5ed54){_0x5ed54=_0x5ed54||0x1f4;return function(_0x25a628){logger[_0x7721('0x11')](_0x25a628[_0x7721('0x12')]);if(_0x25a628['name']){delete _0x25a628[_0x7721('0x13')];}_0x4b183e['status'](_0x5ed54)[_0x7721('0x14')](_0x25a628);};}exports['index']=function(_0xfec626,_0x4e96fb){var _0x3ab5a5={},_0x3e140d={},_0x2286e5={'count':0x0,'rows':[]};var _0x40af90=_[_0x7721('0x15')](db[_0x7721('0x16')][_0x7721('0x17')],function(_0xaeccc4){return{'name':_0xaeccc4['fieldName'],'type':_0xaeccc4[_0x7721('0x18')][_0x7721('0x19')]};});_0x3e140d[_0x7721('0x1a')]=_[_0x7721('0x15')](_0x40af90,'name');_0x3e140d[_0x7721('0x1b')]=_['keys'](_0xfec626[_0x7721('0x1b')]);_0x3e140d[_0x7721('0x1c')]=_[_0x7721('0x1d')](_0x3e140d[_0x7721('0x1a')],_0x3e140d[_0x7721('0x1b')]);_0x3ab5a5[_0x7721('0x1e')]=_[_0x7721('0x1d')](_0x3e140d['model'],qs[_0x7721('0x1f')](_0xfec626[_0x7721('0x1b')][_0x7721('0x1f')]));_0x3ab5a5[_0x7721('0x1e')]=_0x3ab5a5[_0x7721('0x1e')][_0x7721('0x20')]?_0x3ab5a5[_0x7721('0x1e')]:_0x3e140d[_0x7721('0x1a')];if(!_0xfec626[_0x7721('0x1b')]['hasOwnProperty'](_0x7721('0x21'))){_0x3ab5a5['limit']=qs['limit'](_0xfec626[_0x7721('0x1b')][_0x7721('0x9')]);_0x3ab5a5[_0x7721('0x7')]=qs[_0x7721('0x7')](_0xfec626[_0x7721('0x1b')][_0x7721('0x7')]);}_0x3ab5a5[_0x7721('0x22')]=qs[_0x7721('0x23')](_0xfec626['query'][_0x7721('0x23')]);_0x3ab5a5[_0x7721('0x24')]=qs['filters'](_['pick'](_0xfec626[_0x7721('0x1b')],_0x3e140d[_0x7721('0x1c')]),_0x40af90);if(_0xfec626['query'][_0x7721('0x25')]){_0x3ab5a5[_0x7721('0x24')]=_[_0x7721('0x26')](_0x3ab5a5['where'],{'$or':_[_0x7721('0x15')](_0x40af90,function(_0x1ff31b){if(_0x1ff31b[_0x7721('0x18')]!==_0x7721('0x27')){var _0xc0f3c4={};_0xc0f3c4[_0x1ff31b['name']]={'$like':'%'+_0xfec626[_0x7721('0x1b')][_0x7721('0x25')]+'%'};return _0xc0f3c4;}})});}_0x3ab5a5=_[_0x7721('0x26')]({},_0x3ab5a5,_0xfec626['options']);var _0x35de7a={'where':_0x3ab5a5[_0x7721('0x24')]};return db['VoiceCallReport'][_0x7721('0xa')](_0x35de7a)['then'](function(_0x2d6ba0){_0x2286e5[_0x7721('0xa')]=_0x2d6ba0;if(_0xfec626[_0x7721('0x1b')][_0x7721('0x28')]){_0x3ab5a5[_0x7721('0x29')]=[{'attributes':['id',_0x7721('0x13'),_0x7721('0x2a'),_0x7721('0x2b')],'model':db[_0x7721('0x2c')],'as':_0x7721('0x2c')}];}return db[_0x7721('0x16')]['findAll'](_0x3ab5a5);})[_0x7721('0xe')](function(_0x5e6663){_0x2286e5[_0x7721('0x2d')]=_0x5e6663;return _0x2286e5;})[_0x7721('0xe')](respondWithFilteredResult(_0x4e96fb,_0x3ab5a5))[_0x7721('0x2e')](handleError(_0x4e96fb,null));};exports[_0x7721('0x2f')]=function(_0x3968f3,_0x378ba5){var _0x482b70={'raw':!![],'where':{'id':_0x3968f3['params']['id']}},_0x557c34={};_0x557c34['model']=_[_0x7721('0x30')](db[_0x7721('0x16')][_0x7721('0x17')]);_0x557c34[_0x7721('0x1b')]=_['keys'](_0x3968f3[_0x7721('0x1b')]);_0x557c34['filters']=_[_0x7721('0x1d')](_0x557c34[_0x7721('0x1a')],_0x557c34['query']);_0x482b70[_0x7721('0x1e')]=_[_0x7721('0x1d')](_0x557c34['model'],qs['fields'](_0x3968f3[_0x7721('0x1b')][_0x7721('0x1f')]));_0x482b70[_0x7721('0x1e')]=_0x482b70[_0x7721('0x1e')]['length']?_0x482b70[_0x7721('0x1e')]:_0x557c34[_0x7721('0x1a')];if(_0x3968f3[_0x7721('0x1b')][_0x7721('0x28')]){_0x482b70[_0x7721('0x29')]=[{'all':!![]}];}_0x482b70=_['merge']({},_0x482b70,_0x3968f3[_0x7721('0x31')]);return db['VoiceCallReport'][_0x7721('0x32')](_0x482b70)['then'](handleEntityNotFound(_0x378ba5,null))[_0x7721('0xe')](respondWithResult(_0x378ba5,null))[_0x7721('0x2e')](handleError(_0x378ba5,null));};exports[_0x7721('0x33')]=function(_0x49e0c5,_0x1453d4){return db[_0x7721('0x16')][_0x7721('0x33')](_0x49e0c5['body'],{})[_0x7721('0xe')](respondWithResult(_0x1453d4,0xc9))[_0x7721('0x2e')](handleError(_0x1453d4,null));};exports[_0x7721('0xf')]=function(_0x2d5f35,_0x135dbc){return db[_0x7721('0x16')][_0x7721('0x32')]({'where':{'id':_0x2d5f35['params']['id']}})['then'](handleEntityNotFound(_0x135dbc,null))[_0x7721('0xe')](removeEntity(_0x135dbc,null))[_0x7721('0x2e')](handleError(_0x135dbc,null));};exports[_0x7721('0x34')]=function(_0x39a3ad,_0x335145){return db[_0x7721('0x16')][_0x7721('0x34')]()[_0x7721('0xe')](respondWithResult(_0x335145,null))[_0x7721('0x2e')](handleError(_0x335145,null));};function findForUpdate(_0x3af123){return db['VoiceCallReport']['find']({'where':{'uniqueid':_0x3af123[_0x7721('0x35')]['id'],'UserId':{'$or':[null,_0x3af123[_0x7721('0x36')]['id']]}}});}exports[_0x7721('0xd')]=function(_0x219c9f,_0x589e95){if(_0x219c9f[_0x7721('0x37')][_0x7721('0x38')]){delete _0x219c9f['body'][_0x7721('0x38')];}return findForUpdate(_0x219c9f)['then'](handleEntityNotFound(_0x589e95,null))[_0x7721('0xe')](saveUpdates(_0x219c9f['body'],null))[_0x7721('0xe')](respondWithResult(_0x589e95,null))[_0x7721('0x2e')](handleError(_0x589e95,null));};exports[_0x7721('0x39')]=function(_0x4eda58,_0x2d18dd,_0x20fbbb){if(_0x4eda58['body'][_0x7721('0x38')]){delete _0x4eda58[_0x7721('0x37')][_0x7721('0x38')];}promiseRetry(function(){return findForUpdate(_0x4eda58);},{'retries':0x6,'minTimeout':0xfa})['then'](function(_0x20ba21){if(!_0x20ba21){return new Promise(function(_0x5a32b6){_0x5a32b6(handleEntityNotFound(_0x2d18dd)());});}else{return _0x20ba21[_0x7721('0xd')](_0x4eda58[_0x7721('0x37')])[_0x7721('0xe')](function(_0x443503){return respondWithResult(_0x2d18dd)(_0x443503);});}},function(){handleEntityNotFound(_0x2d18dd)();});};