d004760e1cec4c80e6d6e68ca4afcbd76cda2ead
[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 _0xf836=['html-pdf','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','status','json','count','offset','limit','apply','reject','save','update','then','error','stack','name','index','VoiceCallReport','rawAttributes','type','key','map','keys','query','filters','intersection','model','attributes','fields','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','fullname','alias','User','findAll','rows','catch','show','params','length','includeAll','find','create','body','destroy','describe','uniqueid'];(function(_0x5efbf7,_0x80a72e){var _0x23a839=function(_0x1a59dc){while(--_0x1a59dc){_0x5efbf7['push'](_0x5efbf7['shift']());}};_0x23a839(++_0x80a72e);}(_0xf836,0x172));var _0x6f83=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0xf836[_0x20a584];return _0x4b41a8;};'use strict';var pdf=require(_0x6f83('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x6f83('0x1'));var zipdir=require(_0x6f83('0x2'));var jsonpatch=require(_0x6f83('0x3'));var rp=require('request-promise');var moment=require(_0x6f83('0x4'));var BPromise=require(_0x6f83('0x5'));var Mustache=require(_0x6f83('0x6'));var util=require(_0x6f83('0x7'));var path=require(_0x6f83('0x8'));var sox=require(_0x6f83('0x9'));var csv=require(_0x6f83('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x6f83('0xb'));var squel=require(_0x6f83('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x6f83('0xd'));var toCsv=require(_0x6f83('0xa'));var querystring=require(_0x6f83('0xe'));var Papa=require('papaparse');var Redis=require(_0x6f83('0xf'));var authService=require(_0x6f83('0x10'));var qs=require(_0x6f83('0x11'));var as=require(_0x6f83('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x6f83('0x13'))(_0x6f83('0x14'));var utils=require('../../config/utils');var config=require(_0x6f83('0x15'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x10ab48,_0x1ccf22){_0x1ccf22=_0x1ccf22||0xcc;return function(_0x5e3387){if(_0x5e3387){return _0x10ab48['sendStatus'](_0x1ccf22);}return _0x10ab48[_0x6f83('0x16')](_0x1ccf22)['end']();};}function respondWithResult(_0x463129,_0x532c1a){_0x532c1a=_0x532c1a||0xc8;return function(_0xb9713){if(_0xb9713){return _0x463129[_0x6f83('0x16')](_0x532c1a)[_0x6f83('0x17')](_0xb9713);}};}function respondWithFilteredResult(_0x10f206,_0x1a6315){return function(_0x3cb49e){if(_0x3cb49e){var _0x417c0d=_0x3cb49e[_0x6f83('0x18')],_0x14e2fc=_0x1a6315[_0x6f83('0x19')],_0x171055=_0x1a6315[_0x6f83('0x19')]+_0x1a6315[_0x6f83('0x1a')],_0x378e4a;if(_0x171055>=_0x417c0d){_0x171055=_0x417c0d;_0x378e4a=0xc8;}else{_0x378e4a=0xce;}_0x10f206[_0x6f83('0x16')](_0x378e4a);return _0x10f206['set']('Content-Range',_0x14e2fc+'-'+_0x171055+'/'+_0x417c0d)[_0x6f83('0x17')](_0x3cb49e);}return null;};}function patchUpdates(_0x58556b){return function(_0x17ea12){try{jsonpatch[_0x6f83('0x1b')](_0x17ea12,_0x58556b,!![]);}catch(_0x484371){return BPromise[_0x6f83('0x1c')](_0x484371);}return _0x17ea12[_0x6f83('0x1d')]();};}function saveUpdates(_0x28f7be,_0x840bd4){return function(_0x57c6ae){if(_0x57c6ae){return _0x57c6ae[_0x6f83('0x1e')](_0x28f7be)[_0x6f83('0x1f')](function(_0x547865){return _0x547865;});}return null;};}function removeEntity(_0x3ff8d2,_0xb1b384){return function(_0x35d5ee){if(_0x35d5ee){return _0x35d5ee['destroy']()['then'](function(){_0x3ff8d2[_0x6f83('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4d00aa,_0x471451){return function(_0x54a5d8){if(!_0x54a5d8){_0x4d00aa['sendStatus'](0x194);}return _0x54a5d8;};}function handleError(_0x32141b,_0x26e9b3){_0x26e9b3=_0x26e9b3||0x1f4;return function(_0x48df9e){logger[_0x6f83('0x20')](_0x48df9e[_0x6f83('0x21')]);if(_0x48df9e[_0x6f83('0x22')]){delete _0x48df9e[_0x6f83('0x22')];}_0x32141b[_0x6f83('0x16')](_0x26e9b3)['send'](_0x48df9e);};}exports[_0x6f83('0x23')]=function(_0x287db2,_0x4a925a){var _0x450344={},_0x3215ce={},_0x270923={'count':0x0,'rows':[]};var _0x5ecdad=_['map'](db[_0x6f83('0x24')][_0x6f83('0x25')],function(_0x242bdc){return{'name':_0x242bdc['fieldName'],'type':_0x242bdc[_0x6f83('0x26')][_0x6f83('0x27')]};});_0x3215ce['model']=_[_0x6f83('0x28')](_0x5ecdad,'name');_0x3215ce['query']=_[_0x6f83('0x29')](_0x287db2[_0x6f83('0x2a')]);_0x3215ce[_0x6f83('0x2b')]=_[_0x6f83('0x2c')](_0x3215ce[_0x6f83('0x2d')],_0x3215ce[_0x6f83('0x2a')]);_0x450344[_0x6f83('0x2e')]=_[_0x6f83('0x2c')](_0x3215ce[_0x6f83('0x2d')],qs[_0x6f83('0x2f')](_0x287db2['query']['fields']));_0x450344[_0x6f83('0x2e')]=_0x450344[_0x6f83('0x2e')]['length']?_0x450344['attributes']:_0x3215ce[_0x6f83('0x2d')];if(!_0x287db2[_0x6f83('0x2a')]['hasOwnProperty'](_0x6f83('0x30'))){_0x450344['limit']=qs[_0x6f83('0x1a')](_0x287db2['query']['limit']);_0x450344[_0x6f83('0x19')]=qs[_0x6f83('0x19')](_0x287db2['query']['offset']);}_0x450344[_0x6f83('0x31')]=qs[_0x6f83('0x32')](_0x287db2['query'][_0x6f83('0x32')]);_0x450344[_0x6f83('0x33')]=qs[_0x6f83('0x2b')](_[_0x6f83('0x34')](_0x287db2['query'],_0x3215ce[_0x6f83('0x2b')]),_0x5ecdad);if(_0x287db2[_0x6f83('0x2a')][_0x6f83('0x35')]){_0x450344[_0x6f83('0x33')]=_[_0x6f83('0x36')](_0x450344['where'],{'$or':_[_0x6f83('0x28')](_0x5ecdad,function(_0x2b7c81){if(_0x2b7c81[_0x6f83('0x26')]!==_0x6f83('0x37')){var _0x19f32d={};_0x19f32d[_0x2b7c81['name']]={'$like':'%'+_0x287db2[_0x6f83('0x2a')]['filter']+'%'};return _0x19f32d;}})});}_0x450344=_['merge']({},_0x450344,_0x287db2[_0x6f83('0x38')]);var _0x18b58b={'where':_0x450344[_0x6f83('0x33')]};return db[_0x6f83('0x24')]['count'](_0x18b58b)[_0x6f83('0x1f')](function(_0xe46e0e){_0x270923[_0x6f83('0x18')]=_0xe46e0e;if(_0x287db2[_0x6f83('0x2a')]['includeAll']){_0x450344[_0x6f83('0x39')]=[{'attributes':['id',_0x6f83('0x22'),_0x6f83('0x3a'),_0x6f83('0x3b')],'model':db[_0x6f83('0x3c')],'as':_0x6f83('0x3c')}];}return db['VoiceCallReport'][_0x6f83('0x3d')](_0x450344);})[_0x6f83('0x1f')](function(_0x514ab3){_0x270923[_0x6f83('0x3e')]=_0x514ab3;return _0x270923;})[_0x6f83('0x1f')](respondWithFilteredResult(_0x4a925a,_0x450344))[_0x6f83('0x3f')](handleError(_0x4a925a,null));};exports[_0x6f83('0x40')]=function(_0x9c3c6e,_0x565d7b){var _0x971509={'raw':!![],'where':{'id':_0x9c3c6e[_0x6f83('0x41')]['id']}},_0x9d6308={};_0x9d6308[_0x6f83('0x2d')]=_['keys'](db[_0x6f83('0x24')][_0x6f83('0x25')]);_0x9d6308[_0x6f83('0x2a')]=_['keys'](_0x9c3c6e[_0x6f83('0x2a')]);_0x9d6308[_0x6f83('0x2b')]=_[_0x6f83('0x2c')](_0x9d6308[_0x6f83('0x2d')],_0x9d6308[_0x6f83('0x2a')]);_0x971509[_0x6f83('0x2e')]=_[_0x6f83('0x2c')](_0x9d6308[_0x6f83('0x2d')],qs[_0x6f83('0x2f')](_0x9c3c6e[_0x6f83('0x2a')][_0x6f83('0x2f')]));_0x971509[_0x6f83('0x2e')]=_0x971509['attributes'][_0x6f83('0x42')]?_0x971509[_0x6f83('0x2e')]:_0x9d6308[_0x6f83('0x2d')];if(_0x9c3c6e['query'][_0x6f83('0x43')]){_0x971509[_0x6f83('0x39')]=[{'all':!![]}];}_0x971509=_[_0x6f83('0x36')]({},_0x971509,_0x9c3c6e[_0x6f83('0x38')]);return db[_0x6f83('0x24')][_0x6f83('0x44')](_0x971509)[_0x6f83('0x1f')](handleEntityNotFound(_0x565d7b,null))['then'](respondWithResult(_0x565d7b,null))['catch'](handleError(_0x565d7b,null));};exports[_0x6f83('0x45')]=function(_0x4731ba,_0x5ca7f5){return db[_0x6f83('0x24')][_0x6f83('0x45')](_0x4731ba[_0x6f83('0x46')],{})[_0x6f83('0x1f')](respondWithResult(_0x5ca7f5,0xc9))['catch'](handleError(_0x5ca7f5,null));};exports[_0x6f83('0x47')]=function(_0xcb2c7a,_0x522681){return db[_0x6f83('0x24')][_0x6f83('0x44')]({'where':{'id':_0xcb2c7a[_0x6f83('0x41')]['id']}})[_0x6f83('0x1f')](handleEntityNotFound(_0x522681,null))['then'](removeEntity(_0x522681,null))[_0x6f83('0x3f')](handleError(_0x522681,null));};exports['describe']=function(_0x45eaac,_0x3bcb7c){return db[_0x6f83('0x24')][_0x6f83('0x48')]()[_0x6f83('0x1f')](respondWithResult(_0x3bcb7c,null))['catch'](handleError(_0x3bcb7c,null));};exports['update']=function(_0x54eb80,_0x378ab5){if(_0x54eb80[_0x6f83('0x46')]['uniqueid']){delete _0x54eb80[_0x6f83('0x46')][_0x6f83('0x49')];}return db[_0x6f83('0x24')][_0x6f83('0x44')]({'where':{'uniqueid':_0x54eb80['params']['id'],'UserId':{'$or':[null,_0x54eb80['user']['id']]}}})[_0x6f83('0x1f')](handleEntityNotFound(_0x378ab5,null))['then'](saveUpdates(_0x54eb80[_0x6f83('0x46')],null))[_0x6f83('0x1f')](respondWithResult(_0x378ab5,null))[_0x6f83('0x3f')](handleError(_0x378ab5,null));};