Built motion from commit 67e5df37.|2.0.66
[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 _0x0b62=['rawAttributes','length','includeAll','catch','create','describe','uniqueid','user','body','fast-json-patch','moment','bluebird','util','path','sox','to-csv','lodash','squel','desk.js','querystring','../../components/parsers/qs','api','../../mysqldb','sendStatus','end','status','json','offset','set','Content-Range','reject','save','update','then','destroy','error','name','send','index','model','keys','query','dateStart','dateEnd','filters','intersection','attributes','fields','hasOwnProperty','nolimit','limit','sort','where','pick','add','day','filter','merge','map','options','VoiceCallReport','count','include','findAll','rows','params'];(function(_0x3ec532,_0x37446f){var _0x2103c7=function(_0x3cd452){while(--_0x3cd452){_0x3ec532['push'](_0x3ec532['shift']());}};_0x2103c7(++_0x37446f);}(_0x0b62,0x1d7));var _0x20b6=function(_0x5814bf,_0x2cd816){_0x5814bf=_0x5814bf-0x0;var _0x78a352=_0x0b62[_0x5814bf];return _0x78a352;};'use strict';var jsonpatch=require(_0x20b6('0x0'));var rp=require('request-promise');var moment=require(_0x20b6('0x1'));var BPromise=require(_0x20b6('0x2'));var Mustache=require('mustache');var util=require(_0x20b6('0x3'));var path=require(_0x20b6('0x4'));var sox=require(_0x20b6('0x5'));var csv=require(_0x20b6('0x6'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x20b6('0x7'));var squel=require(_0x20b6('0x8'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x20b6('0x9'));var toCsv=require(_0x20b6('0x6'));var querystring=require(_0x20b6('0xa'));var Papa=require('papaparse');var qs=require(_0x20b6('0xb'));var logger=require('../../config/logger')(_0x20b6('0xc'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x20b6('0xd'))['db'];function respondWithStatusCode(_0x25f68a,_0x51443d){_0x51443d=_0x51443d||0xcc;return function(_0x283218){if(_0x283218){return _0x25f68a[_0x20b6('0xe')](_0x51443d);}return _0x25f68a['status'](_0x51443d)[_0x20b6('0xf')]();};}function respondWithResult(_0x2b5a48,_0x3d374e){_0x3d374e=_0x3d374e||0xc8;return function(_0x56a3d6){if(_0x56a3d6){return _0x2b5a48[_0x20b6('0x10')](_0x3d374e)[_0x20b6('0x11')](_0x56a3d6);}};}function respondWithFilteredResult(_0x9fc80b,_0x4d2add){return function(_0x253acc){if(_0x253acc){var _0x1d8f29=_0x253acc['count'],_0x111f20=_0x4d2add[_0x20b6('0x12')],_0x230083=_0x4d2add[_0x20b6('0x12')]+_0x4d2add['limit'],_0x18130a;if(_0x230083>=_0x1d8f29){_0x230083=_0x1d8f29;_0x18130a=0xc8;}else{_0x18130a=0xce;}_0x9fc80b['status'](_0x18130a);return _0x9fc80b[_0x20b6('0x13')](_0x20b6('0x14'),_0x111f20+'-'+_0x230083+'/'+_0x1d8f29)[_0x20b6('0x11')](_0x253acc);}return null;};}function patchUpdates(_0x2b4268){return function(_0x496798){try{jsonpatch['apply'](_0x496798,_0x2b4268,!![]);}catch(_0x491eda){return BPromise[_0x20b6('0x15')](_0x491eda);}return _0x496798[_0x20b6('0x16')]();};}function saveUpdates(_0x3959c4,_0x4b6d9b){return function(_0x39bbff){if(_0x39bbff){return _0x39bbff[_0x20b6('0x17')](_0x3959c4)[_0x20b6('0x18')](function(_0x5f4fe7){return _0x5f4fe7;});}return null;};}function removeEntity(_0x2e38c2,_0x1bdd30){return function(_0x28bffc){if(_0x28bffc){return _0x28bffc[_0x20b6('0x19')]()[_0x20b6('0x18')](function(){_0x2e38c2[_0x20b6('0x10')](0xcc)[_0x20b6('0xf')]();});}};}function handleEntityNotFound(_0x426e81,_0x56c6aa){return function(_0x343282){if(!_0x343282){_0x426e81[_0x20b6('0xe')](0x194);}return _0x343282;};}function handleError(_0x542287,_0x1973d8){_0x1973d8=_0x1973d8||0x1f4;return function(_0x551b08){logger[_0x20b6('0x1a')](_0x551b08['stack']);if(_0x551b08['name']){delete _0x551b08[_0x20b6('0x1b')];}_0x542287['status'](_0x1973d8)[_0x20b6('0x1c')](_0x551b08);};}exports[_0x20b6('0x1d')]=function(_0x44fad9,_0x165a2d){var _0x2fbf8f={},_0x145193={},_0x53035e={'count':0x0,'rows':[]};_0x145193[_0x20b6('0x1e')]=_[_0x20b6('0x1f')](db['VoiceCallReport']['rawAttributes']);var _0x3080de={'dateStart':_0x44fad9[_0x20b6('0x20')][_0x20b6('0x21')],'dateEnd':_0x44fad9[_0x20b6('0x20')][_0x20b6('0x22')]};delete _0x44fad9[_0x20b6('0x20')][_0x20b6('0x21')];delete _0x44fad9[_0x20b6('0x20')][_0x20b6('0x22')];_0x145193['query']=_[_0x20b6('0x1f')](_0x44fad9[_0x20b6('0x20')]);_0x145193[_0x20b6('0x23')]=_[_0x20b6('0x24')](_0x145193[_0x20b6('0x1e')],_0x145193['query']);_0x2fbf8f[_0x20b6('0x25')]=_[_0x20b6('0x24')](_0x145193[_0x20b6('0x1e')],qs[_0x20b6('0x26')](_0x44fad9[_0x20b6('0x20')][_0x20b6('0x26')]));_0x2fbf8f[_0x20b6('0x25')]=_0x2fbf8f[_0x20b6('0x25')]['length']?_0x2fbf8f[_0x20b6('0x25')]:_0x145193[_0x20b6('0x1e')];if(!_0x44fad9['query'][_0x20b6('0x27')](_0x20b6('0x28'))){_0x2fbf8f[_0x20b6('0x29')]=qs['limit'](_0x44fad9[_0x20b6('0x20')][_0x20b6('0x29')]);_0x2fbf8f[_0x20b6('0x12')]=qs['offset'](_0x44fad9[_0x20b6('0x20')][_0x20b6('0x12')]);}_0x2fbf8f['order']=qs[_0x20b6('0x2a')](_0x44fad9[_0x20b6('0x20')]['sort']);_0x2fbf8f[_0x20b6('0x2b')]=qs[_0x20b6('0x23')](_[_0x20b6('0x2c')](_0x44fad9[_0x20b6('0x20')],_0x145193[_0x20b6('0x23')]));if(_0x3080de[_0x20b6('0x21')]){if(_0x3080de[_0x20b6('0x22')]){_0x3080de['dateEnd']=moment(_0x3080de['dateEnd'])['add'](0x1,'day');}else{_0x3080de[_0x20b6('0x22')]=moment(_0x3080de[_0x20b6('0x21')])[_0x20b6('0x2d')](0x1,_0x20b6('0x2e'));}_['merge'](_0x2fbf8f[_0x20b6('0x2b')],{'createdAt':{'$gte':_0x3080de[_0x20b6('0x21')],'$lte':_0x3080de['dateEnd']}});}if(_0x44fad9['query'][_0x20b6('0x2f')]){_0x2fbf8f['where']=_[_0x20b6('0x30')](_0x2fbf8f[_0x20b6('0x2b')],{'$or':_[_0x20b6('0x31')](_0x2fbf8f[_0x20b6('0x25')],function(_0x36a091){var _0x224167={};_0x224167[_0x36a091]={'$like':'%'+_0x44fad9[_0x20b6('0x20')][_0x20b6('0x2f')]+'%'};return _0x224167;})});}_0x2fbf8f=_['merge']({},_0x2fbf8f,_0x44fad9[_0x20b6('0x32')]);var _0x1c7a73={'where':_0x2fbf8f[_0x20b6('0x2b')]};return db[_0x20b6('0x33')][_0x20b6('0x34')](_0x1c7a73)[_0x20b6('0x18')](function(_0x5aad49){_0x53035e[_0x20b6('0x34')]=_0x5aad49;if(_0x44fad9[_0x20b6('0x20')]['includeAll']){_0x2fbf8f[_0x20b6('0x35')]=[{'all':!![]}];}return db[_0x20b6('0x33')][_0x20b6('0x36')](_0x2fbf8f);})[_0x20b6('0x18')](function(_0x5dd7e8){_0x53035e[_0x20b6('0x37')]=_0x5dd7e8;return _0x53035e;})['then'](respondWithFilteredResult(_0x165a2d,_0x2fbf8f))['catch'](handleError(_0x165a2d,null));};exports['show']=function(_0x3cc339,_0x90d0a1){var _0x4b9fc6={'raw':!![],'where':{'id':_0x3cc339[_0x20b6('0x38')]['id']}},_0x4a716f={};_0x4a716f['model']=_[_0x20b6('0x1f')](db[_0x20b6('0x33')][_0x20b6('0x39')]);_0x4a716f[_0x20b6('0x20')]=_[_0x20b6('0x1f')](_0x3cc339[_0x20b6('0x20')]);_0x4a716f[_0x20b6('0x23')]=_['intersection'](_0x4a716f[_0x20b6('0x1e')],_0x4a716f[_0x20b6('0x20')]);_0x4b9fc6[_0x20b6('0x25')]=_[_0x20b6('0x24')](_0x4a716f['model'],qs[_0x20b6('0x26')](_0x3cc339['query']['fields']));_0x4b9fc6[_0x20b6('0x25')]=_0x4b9fc6['attributes'][_0x20b6('0x3a')]?_0x4b9fc6[_0x20b6('0x25')]:_0x4a716f[_0x20b6('0x1e')];if(_0x3cc339[_0x20b6('0x20')][_0x20b6('0x3b')]){_0x4b9fc6[_0x20b6('0x35')]=[{'all':!![]}];}_0x4b9fc6=_[_0x20b6('0x30')]({},_0x4b9fc6,_0x3cc339[_0x20b6('0x32')]);return db[_0x20b6('0x33')]['find'](_0x4b9fc6)[_0x20b6('0x18')](handleEntityNotFound(_0x90d0a1,null))[_0x20b6('0x18')](respondWithResult(_0x90d0a1,null))[_0x20b6('0x3c')](handleError(_0x90d0a1,null));};exports[_0x20b6('0x3d')]=function(_0x152f6c,_0x57a4af){return db[_0x20b6('0x33')][_0x20b6('0x3d')](_0x152f6c['body'],{})[_0x20b6('0x18')](respondWithResult(_0x57a4af,0xc9))[_0x20b6('0x3c')](handleError(_0x57a4af,null));};exports['destroy']=function(_0x54cc04,_0x188886){return db[_0x20b6('0x33')]['find']({'where':{'id':_0x54cc04['params']['id']}})['then'](handleEntityNotFound(_0x188886,null))['then'](removeEntity(_0x188886,null))[_0x20b6('0x3c')](handleError(_0x188886,null));};exports[_0x20b6('0x3e')]=function(_0x3e3217,_0x4a5ef1){return db[_0x20b6('0x33')]['describe']()[_0x20b6('0x18')](respondWithResult(_0x4a5ef1,null))[_0x20b6('0x3c')](handleError(_0x4a5ef1,null));};exports[_0x20b6('0x17')]=function(_0x3eed74,_0x265840){if(_0x3eed74['body']['uniqueid']){delete _0x3eed74['body'][_0x20b6('0x3f')];}return db[_0x20b6('0x33')]['find']({'where':{'uniqueid':_0x3eed74[_0x20b6('0x38')]['id'],'UserId':{'$or':[null,_0x3eed74[_0x20b6('0x40')]['id']]}}})['then'](handleEntityNotFound(_0x265840,null))[_0x20b6('0x18')](saveUpdates(_0x3eed74[_0x20b6('0x41')],null))[_0x20b6('0x18')](respondWithResult(_0x265840,null))[_0x20b6('0x3c')](handleError(_0x265840,null));};