Built motion from commit (unavailable).|2.5.4
[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 _0x628b=['name','send','map','VoiceCallReport','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','count','includeAll','include','fullname','alias','User','rows','params','keys','find','create','catch','destroy','describe','update','body','uniqueid','user','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','json','offset','limit','Content-Range','apply','save','then','sendStatus','stack'];(function(_0x294a6b,_0x389e06){var _0x5d4163=function(_0x2378f2){while(--_0x2378f2){_0x294a6b['push'](_0x294a6b['shift']());}};_0x5d4163(++_0x389e06);}(_0x628b,0x110));var _0xb628=function(_0x55d3a5,_0xa419c1){_0x55d3a5=_0x55d3a5-0x0;var _0x3ae4d6=_0x628b[_0x55d3a5];return _0x3ae4d6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb628('0x0'));var rimraf=require(_0xb628('0x1'));var zipdir=require(_0xb628('0x2'));var jsonpatch=require(_0xb628('0x3'));var rp=require('request-promise');var moment=require(_0xb628('0x4'));var BPromise=require(_0xb628('0x5'));var Mustache=require('mustache');var util=require(_0xb628('0x6'));var path=require(_0xb628('0x7'));var sox=require(_0xb628('0x8'));var csv=require(_0xb628('0x9'));var ejs=require(_0xb628('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb628('0xb'));var crypto=require(_0xb628('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xb628('0xd'));var toCsv=require('to-csv');var querystring=require(_0xb628('0xe'));var Papa=require(_0xb628('0xf'));var Redis=require(_0xb628('0x10'));var authService=require(_0xb628('0x11'));var qs=require(_0xb628('0x12'));var as=require(_0xb628('0x13'));var hardwareService=require(_0xb628('0x14'));var logger=require(_0xb628('0x15'))(_0xb628('0x16'));var utils=require(_0xb628('0x17'));var config=require(_0xb628('0x18'));var db=require(_0xb628('0x19'))['db'];function respondWithStatusCode(_0x3a8b3a,_0xbb6f4a){_0xbb6f4a=_0xbb6f4a||0xcc;return function(_0x441a29){if(_0x441a29){return _0x3a8b3a['sendStatus'](_0xbb6f4a);}return _0x3a8b3a[_0xb628('0x1a')](_0xbb6f4a)['end']();};}function respondWithResult(_0x35f10d,_0x57caad){_0x57caad=_0x57caad||0xc8;return function(_0x57cfc1){if(_0x57cfc1){return _0x35f10d[_0xb628('0x1a')](_0x57caad)[_0xb628('0x1b')](_0x57cfc1);}};}function respondWithFilteredResult(_0x344646,_0x2e084f){return function(_0x14aea5){if(_0x14aea5){var _0x543769=_0x14aea5['count'],_0x291952=_0x2e084f['offset'],_0x41aec8=_0x2e084f[_0xb628('0x1c')]+_0x2e084f[_0xb628('0x1d')],_0xf575ee;if(_0x41aec8>=_0x543769){_0x41aec8=_0x543769;_0xf575ee=0xc8;}else{_0xf575ee=0xce;}_0x344646[_0xb628('0x1a')](_0xf575ee);return _0x344646['set'](_0xb628('0x1e'),_0x291952+'-'+_0x41aec8+'/'+_0x543769)[_0xb628('0x1b')](_0x14aea5);}return null;};}function patchUpdates(_0x227788){return function(_0x5a0963){try{jsonpatch[_0xb628('0x1f')](_0x5a0963,_0x227788,!![]);}catch(_0x2b8b8d){return BPromise['reject'](_0x2b8b8d);}return _0x5a0963[_0xb628('0x20')]();};}function saveUpdates(_0x507022,_0x16e068){return function(_0x2c54ca){if(_0x2c54ca){return _0x2c54ca['update'](_0x507022)[_0xb628('0x21')](function(_0x30b9d2){return _0x30b9d2;});}return null;};}function removeEntity(_0x592062,_0xbceb23){return function(_0x417094){if(_0x417094){return _0x417094['destroy']()[_0xb628('0x21')](function(){_0x592062['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4129ec,_0x53b98c){return function(_0x4978cf){if(!_0x4978cf){_0x4129ec[_0xb628('0x22')](0x194);}return _0x4978cf;};}function handleError(_0x1f3828,_0x363b64){_0x363b64=_0x363b64||0x1f4;return function(_0x5c527d){logger['error'](_0x5c527d[_0xb628('0x23')]);if(_0x5c527d[_0xb628('0x24')]){delete _0x5c527d['name'];}_0x1f3828[_0xb628('0x1a')](_0x363b64)[_0xb628('0x25')](_0x5c527d);};}exports['index']=function(_0xa2bde3,_0x5569fb){var _0x4cd380={},_0x2c9797={},_0x2ad7f1={'count':0x0,'rows':[]};var _0x55e7f8=_[_0xb628('0x26')](db[_0xb628('0x27')][_0xb628('0x28')],function(_0x59f427){return{'name':_0x59f427['fieldName'],'type':_0x59f427[_0xb628('0x29')][_0xb628('0x2a')]};});_0x2c9797[_0xb628('0x2b')]=_[_0xb628('0x26')](_0x55e7f8,_0xb628('0x24'));_0x2c9797['query']=_['keys'](_0xa2bde3[_0xb628('0x2c')]);_0x2c9797[_0xb628('0x2d')]=_[_0xb628('0x2e')](_0x2c9797[_0xb628('0x2b')],_0x2c9797[_0xb628('0x2c')]);_0x4cd380['attributes']=_[_0xb628('0x2e')](_0x2c9797[_0xb628('0x2b')],qs[_0xb628('0x2f')](_0xa2bde3['query']['fields']));_0x4cd380['attributes']=_0x4cd380[_0xb628('0x30')][_0xb628('0x31')]?_0x4cd380[_0xb628('0x30')]:_0x2c9797[_0xb628('0x2b')];if(!_0xa2bde3[_0xb628('0x2c')][_0xb628('0x32')](_0xb628('0x33'))){_0x4cd380[_0xb628('0x1d')]=qs[_0xb628('0x1d')](_0xa2bde3[_0xb628('0x2c')][_0xb628('0x1d')]);_0x4cd380['offset']=qs['offset'](_0xa2bde3[_0xb628('0x2c')][_0xb628('0x1c')]);}_0x4cd380[_0xb628('0x34')]=qs[_0xb628('0x35')](_0xa2bde3[_0xb628('0x2c')][_0xb628('0x35')]);_0x4cd380[_0xb628('0x36')]=qs[_0xb628('0x2d')](_[_0xb628('0x37')](_0xa2bde3[_0xb628('0x2c')],_0x2c9797[_0xb628('0x2d')]),_0x55e7f8);if(_0xa2bde3[_0xb628('0x2c')][_0xb628('0x38')]){_0x4cd380[_0xb628('0x36')]=_['merge'](_0x4cd380['where'],{'$or':_[_0xb628('0x26')](_0x55e7f8,function(_0x300bad){if(_0x300bad[_0xb628('0x29')]!==_0xb628('0x39')){var _0x34db07={};_0x34db07[_0x300bad['name']]={'$like':'%'+_0xa2bde3[_0xb628('0x2c')]['filter']+'%'};return _0x34db07;}})});}_0x4cd380=_[_0xb628('0x3a')]({},_0x4cd380,_0xa2bde3['options']);var _0x401779={'where':_0x4cd380[_0xb628('0x36')]};return db[_0xb628('0x27')]['count'](_0x401779)[_0xb628('0x21')](function(_0x2f113b){_0x2ad7f1[_0xb628('0x3b')]=_0x2f113b;if(_0xa2bde3[_0xb628('0x2c')][_0xb628('0x3c')]){_0x4cd380[_0xb628('0x3d')]=[{'attributes':['id',_0xb628('0x24'),_0xb628('0x3e'),_0xb628('0x3f')],'model':db[_0xb628('0x40')],'as':_0xb628('0x40')}];}return db[_0xb628('0x27')]['findAll'](_0x4cd380);})[_0xb628('0x21')](function(_0x1a9a6e){_0x2ad7f1[_0xb628('0x41')]=_0x1a9a6e;return _0x2ad7f1;})[_0xb628('0x21')](respondWithFilteredResult(_0x5569fb,_0x4cd380))['catch'](handleError(_0x5569fb,null));};exports['show']=function(_0x17b3e8,_0x3a7fbd){var _0x3c5391={'raw':!![],'where':{'id':_0x17b3e8[_0xb628('0x42')]['id']}},_0x56ae26={};_0x56ae26['model']=_[_0xb628('0x43')](db['VoiceCallReport'][_0xb628('0x28')]);_0x56ae26[_0xb628('0x2c')]=_[_0xb628('0x43')](_0x17b3e8[_0xb628('0x2c')]);_0x56ae26[_0xb628('0x2d')]=_[_0xb628('0x2e')](_0x56ae26[_0xb628('0x2b')],_0x56ae26['query']);_0x3c5391[_0xb628('0x30')]=_['intersection'](_0x56ae26[_0xb628('0x2b')],qs['fields'](_0x17b3e8[_0xb628('0x2c')][_0xb628('0x2f')]));_0x3c5391[_0xb628('0x30')]=_0x3c5391['attributes'][_0xb628('0x31')]?_0x3c5391[_0xb628('0x30')]:_0x56ae26[_0xb628('0x2b')];if(_0x17b3e8[_0xb628('0x2c')]['includeAll']){_0x3c5391['include']=[{'all':!![]}];}_0x3c5391=_[_0xb628('0x3a')]({},_0x3c5391,_0x17b3e8['options']);return db[_0xb628('0x27')][_0xb628('0x44')](_0x3c5391)['then'](handleEntityNotFound(_0x3a7fbd,null))['then'](respondWithResult(_0x3a7fbd,null))['catch'](handleError(_0x3a7fbd,null));};exports[_0xb628('0x45')]=function(_0x16cd1f,_0x49b6c7){return db[_0xb628('0x27')]['create'](_0x16cd1f['body'],{})[_0xb628('0x21')](respondWithResult(_0x49b6c7,0xc9))[_0xb628('0x46')](handleError(_0x49b6c7,null));};exports[_0xb628('0x47')]=function(_0x4c4d8a,_0x3d3903){return db['VoiceCallReport'][_0xb628('0x44')]({'where':{'id':_0x4c4d8a['params']['id']}})[_0xb628('0x21')](handleEntityNotFound(_0x3d3903,null))['then'](removeEntity(_0x3d3903,null))[_0xb628('0x46')](handleError(_0x3d3903,null));};exports[_0xb628('0x48')]=function(_0x4594a6,_0x522c5b){return db[_0xb628('0x27')]['describe']()[_0xb628('0x21')](respondWithResult(_0x522c5b,null))['catch'](handleError(_0x522c5b,null));};exports[_0xb628('0x49')]=function(_0x3111c2,_0x223e28){if(_0x3111c2[_0xb628('0x4a')][_0xb628('0x4b')]){delete _0x3111c2[_0xb628('0x4a')]['uniqueid'];}return db[_0xb628('0x27')][_0xb628('0x44')]({'where':{'uniqueid':_0x3111c2[_0xb628('0x42')]['id'],'UserId':{'$or':[null,_0x3111c2[_0xb628('0x4c')]['id']]}}})['then'](handleEntityNotFound(_0x223e28,null))[_0xb628('0x21')](saveUpdates(_0x3111c2[_0xb628('0x4a')],null))[_0xb628('0x21')](respondWithResult(_0x223e28,null))[_0xb628('0x46')](handleError(_0x223e28,null));};