0f5e11b8c47ba57d4d42e677518b5f9e79dde94f
[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 _0x7524=['VoiceCallReport','rawAttributes','type','key','model','query','filters','attributes','intersection','fields','nolimit','sort','where','pick','filter','merge','options','includeAll','include','fullname','alias','User','findAll','rows','catch','show','params','keys','length','find','create','body','describe','user','uniqueid','../../components/parsers/qs','../../config/logger','../../mysqldb','promise-retry','json','undefined','limit','count','offset','status','set','update','then','destroy','end','sendStatus','error','stack','name','send','index','map'];(function(_0x583ef,_0x10ed47){var _0x2d4ac1=function(_0x4db9e6){while(--_0x4db9e6){_0x583ef['push'](_0x583ef['shift']());}};_0x2d4ac1(++_0x10ed47);}(_0x7524,0xce));var _0x4752=function(_0x18a856,_0x5b3ad6){_0x18a856=_0x18a856-0x0;var _0x509810=_0x7524[_0x18a856];return _0x509810;};'use strict';var _=require('lodash');var qs=require(_0x4752('0x0'));var logger=require(_0x4752('0x1'))('api');var db=require(_0x4752('0x2'))['db'];const promiseRetry=require(_0x4752('0x3'));function respondWithResult(_0x4ac1c0,_0x599e2b){_0x599e2b=_0x599e2b||0xc8;return function(_0x3eae1a){if(_0x3eae1a){return _0x4ac1c0['status'](_0x599e2b)[_0x4752('0x4')](_0x3eae1a);}};}function respondWithFilteredResult(_0x307267,_0x66a421){return function(_0x55b411){if(_0x55b411){var _0x104962=typeof _0x66a421['offset']===_0x4752('0x5')&&typeof _0x66a421[_0x4752('0x6')]==='undefined';var _0x5db15c=_0x55b411[_0x4752('0x7')];var _0x45e0ff=_0x104962?0x0:_0x66a421[_0x4752('0x8')];var _0x1c83b9=_0x104962?_0x55b411['count']:_0x66a421[_0x4752('0x8')]+_0x66a421[_0x4752('0x6')];var _0x8ab6b9;if(_0x1c83b9>=_0x5db15c){_0x1c83b9=_0x5db15c;_0x8ab6b9=0xc8;}else{_0x8ab6b9=0xce;}_0x307267[_0x4752('0x9')](_0x8ab6b9);return _0x307267[_0x4752('0xa')]('Content-Range',_0x45e0ff+'-'+_0x1c83b9+'/'+_0x5db15c)[_0x4752('0x4')](_0x55b411);}return null;};}function saveUpdates(_0x11d84e){return function(_0x404e5a){if(_0x404e5a){return _0x404e5a[_0x4752('0xb')](_0x11d84e)[_0x4752('0xc')](function(_0x7c7890){return _0x7c7890;});}return null;};}function removeEntity(_0xcee47){return function(_0x505d48){if(_0x505d48){return _0x505d48[_0x4752('0xd')]()['then'](function(){_0xcee47[_0x4752('0x9')](0xcc)[_0x4752('0xe')]();});}};}function handleEntityNotFound(_0x461f58){return function(_0x17a8b8){if(!_0x17a8b8){_0x461f58[_0x4752('0xf')](0x194);}return _0x17a8b8;};}function handleError(_0x33131a,_0x410f88){_0x410f88=_0x410f88||0x1f4;return function(_0x552daf){logger[_0x4752('0x10')](_0x552daf[_0x4752('0x11')]);if(_0x552daf['name']){delete _0x552daf[_0x4752('0x12')];}_0x33131a['status'](_0x410f88)[_0x4752('0x13')](_0x552daf);};}exports[_0x4752('0x14')]=function(_0x516f3e,_0x2d7ab6){var _0x4b95f8={},_0x525176={},_0x285688={'count':0x0,'rows':[]};var _0x4444e5=_[_0x4752('0x15')](db[_0x4752('0x16')][_0x4752('0x17')],function(_0x3142b){return{'name':_0x3142b['fieldName'],'type':_0x3142b[_0x4752('0x18')][_0x4752('0x19')]};});_0x525176[_0x4752('0x1a')]=_[_0x4752('0x15')](_0x4444e5,_0x4752('0x12'));_0x525176[_0x4752('0x1b')]=_['keys'](_0x516f3e[_0x4752('0x1b')]);_0x525176[_0x4752('0x1c')]=_['intersection'](_0x525176[_0x4752('0x1a')],_0x525176[_0x4752('0x1b')]);_0x4b95f8[_0x4752('0x1d')]=_[_0x4752('0x1e')](_0x525176[_0x4752('0x1a')],qs[_0x4752('0x1f')](_0x516f3e[_0x4752('0x1b')][_0x4752('0x1f')]));_0x4b95f8[_0x4752('0x1d')]=_0x4b95f8[_0x4752('0x1d')]['length']?_0x4b95f8[_0x4752('0x1d')]:_0x525176['model'];if(!_0x516f3e['query']['hasOwnProperty'](_0x4752('0x20'))){_0x4b95f8[_0x4752('0x6')]=qs[_0x4752('0x6')](_0x516f3e[_0x4752('0x1b')][_0x4752('0x6')]);_0x4b95f8[_0x4752('0x8')]=qs[_0x4752('0x8')](_0x516f3e[_0x4752('0x1b')]['offset']);}_0x4b95f8['order']=qs[_0x4752('0x21')](_0x516f3e[_0x4752('0x1b')][_0x4752('0x21')]);_0x4b95f8[_0x4752('0x22')]=qs[_0x4752('0x1c')](_[_0x4752('0x23')](_0x516f3e[_0x4752('0x1b')],_0x525176[_0x4752('0x1c')]),_0x4444e5);if(_0x516f3e[_0x4752('0x1b')][_0x4752('0x24')]){_0x4b95f8[_0x4752('0x22')]=_[_0x4752('0x25')](_0x4b95f8[_0x4752('0x22')],{'$or':_[_0x4752('0x15')](_0x4444e5,function(_0x46d889){if(_0x46d889[_0x4752('0x18')]!=='VIRTUAL'){var _0x50b325={};_0x50b325[_0x46d889[_0x4752('0x12')]]={'$like':'%'+_0x516f3e[_0x4752('0x1b')][_0x4752('0x24')]+'%'};return _0x50b325;}})});}_0x4b95f8=_[_0x4752('0x25')]({},_0x4b95f8,_0x516f3e[_0x4752('0x26')]);var _0x27c066={'where':_0x4b95f8[_0x4752('0x22')]};return db[_0x4752('0x16')][_0x4752('0x7')](_0x27c066)[_0x4752('0xc')](function(_0x57efc7){_0x285688[_0x4752('0x7')]=_0x57efc7;if(_0x516f3e['query'][_0x4752('0x27')]){_0x4b95f8[_0x4752('0x28')]=[{'attributes':['id',_0x4752('0x12'),_0x4752('0x29'),_0x4752('0x2a')],'model':db['User'],'as':_0x4752('0x2b')}];}return db['VoiceCallReport'][_0x4752('0x2c')](_0x4b95f8);})[_0x4752('0xc')](function(_0xd23ea3){_0x285688[_0x4752('0x2d')]=_0xd23ea3;return _0x285688;})[_0x4752('0xc')](respondWithFilteredResult(_0x2d7ab6,_0x4b95f8))[_0x4752('0x2e')](handleError(_0x2d7ab6,null));};exports[_0x4752('0x2f')]=function(_0x1b8819,_0x21db8e){var _0x3583c0={'raw':!![],'where':{'id':_0x1b8819[_0x4752('0x30')]['id']}},_0x49f116={};_0x49f116[_0x4752('0x1a')]=_[_0x4752('0x31')](db[_0x4752('0x16')][_0x4752('0x17')]);_0x49f116[_0x4752('0x1b')]=_[_0x4752('0x31')](_0x1b8819[_0x4752('0x1b')]);_0x49f116['filters']=_[_0x4752('0x1e')](_0x49f116['model'],_0x49f116[_0x4752('0x1b')]);_0x3583c0[_0x4752('0x1d')]=_[_0x4752('0x1e')](_0x49f116[_0x4752('0x1a')],qs['fields'](_0x1b8819['query']['fields']));_0x3583c0['attributes']=_0x3583c0[_0x4752('0x1d')][_0x4752('0x32')]?_0x3583c0['attributes']:_0x49f116[_0x4752('0x1a')];if(_0x1b8819[_0x4752('0x1b')][_0x4752('0x27')]){_0x3583c0['include']=[{'all':!![]}];}_0x3583c0=_[_0x4752('0x25')]({},_0x3583c0,_0x1b8819[_0x4752('0x26')]);return db[_0x4752('0x16')][_0x4752('0x33')](_0x3583c0)[_0x4752('0xc')](handleEntityNotFound(_0x21db8e,null))['then'](respondWithResult(_0x21db8e,null))['catch'](handleError(_0x21db8e,null));};exports[_0x4752('0x34')]=function(_0x31cef5,_0x828534){return db[_0x4752('0x16')][_0x4752('0x34')](_0x31cef5[_0x4752('0x35')],{})[_0x4752('0xc')](respondWithResult(_0x828534,0xc9))[_0x4752('0x2e')](handleError(_0x828534,null));};exports[_0x4752('0xd')]=function(_0xadc916,_0x42ea8f){return db[_0x4752('0x16')]['find']({'where':{'id':_0xadc916[_0x4752('0x30')]['id']}})['then'](handleEntityNotFound(_0x42ea8f,null))[_0x4752('0xc')](removeEntity(_0x42ea8f,null))[_0x4752('0x2e')](handleError(_0x42ea8f,null));};exports['describe']=function(_0xafde9c,_0x1a940b){return db[_0x4752('0x16')][_0x4752('0x36')]()[_0x4752('0xc')](respondWithResult(_0x1a940b,null))[_0x4752('0x2e')](handleError(_0x1a940b,null));};function findForUpdate(_0x49afcc){return db[_0x4752('0x16')][_0x4752('0x33')]({'where':{'uniqueid':_0x49afcc[_0x4752('0x30')]['id'],'UserId':{'$or':[null,_0x49afcc[_0x4752('0x37')]['id']]}}});}exports[_0x4752('0xb')]=function(_0xec3a1e,_0x564ca3){if(_0xec3a1e[_0x4752('0x35')][_0x4752('0x38')]){delete _0xec3a1e[_0x4752('0x35')][_0x4752('0x38')];}return findForUpdate(_0xec3a1e)[_0x4752('0xc')](handleEntityNotFound(_0x564ca3,null))[_0x4752('0xc')](saveUpdates(_0xec3a1e['body'],null))[_0x4752('0xc')](respondWithResult(_0x564ca3,null))['catch'](handleError(_0x564ca3,null));};exports['updateWithRetry']=function(_0x965429,_0x234220,_0x424ca4){if(_0x965429['body'][_0x4752('0x38')]){delete _0x965429[_0x4752('0x35')]['uniqueid'];}promiseRetry(function(_0x14f83c){return findForUpdate(_0x965429)[_0x4752('0xc')](function(_0x323bd8){if(_0x323bd8!==null){return _0x323bd8;}else{_0x14f83c(new Error('No\x20such\x20report'));}});},{'retries':0x4,'minTimeout':0xfa})[_0x4752('0xc')](function(_0x137a7d){if(!_0x137a7d){return new Promise(function(_0x2d461c){_0x2d461c(handleEntityNotFound(_0x234220)());});}else{return _0x137a7d[_0x4752('0xb')](_0x965429[_0x4752('0x35')])[_0x4752('0xc')](function(_0x54389f){return respondWithResult(_0x234220)(_0x54389f);});}},function(){handleEntityNotFound(_0x234220)();});};