d1fec245f3c89c15e5184376357749dea4c4022a
[motion2.git] / server / api / voiceDialReport / voiceDialReport.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 _0xf603=['send','index','map','VoiceDialReport','rawAttributes','type','key','query','keys','filters','intersection','attributes','model','fields','length','nolimit','order','sort','where','VIRTUAL','merge','options','includeAll','findAll','rows','show','include','find','catch','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','json','undefined','count','offset','limit','status','Content-Range','apply','save','update','then','destroy','error','stack','name'];(function(_0xae7c2f,_0xf31e04){var _0x5d7001=function(_0x4eeadb){while(--_0x4eeadb){_0xae7c2f['push'](_0xae7c2f['shift']());}};_0x5d7001(++_0xf31e04);}(_0xf603,0x102));var _0x3f60=function(_0x28b351,_0xa7072d){_0x28b351=_0x28b351-0x0;var _0x1265df=_0xf603[_0x28b351];return _0x1265df;};'use strict';var emlformat=require(_0x3f60('0x0'));var rimraf=require(_0x3f60('0x1'));var zipdir=require(_0x3f60('0x2'));var jsonpatch=require(_0x3f60('0x3'));var rp=require(_0x3f60('0x4'));var moment=require('moment');var BPromise=require(_0x3f60('0x5'));var Mustache=require(_0x3f60('0x6'));var util=require('util');var path=require(_0x3f60('0x7'));var sox=require(_0x3f60('0x8'));var csv=require(_0x3f60('0x9'));var ejs=require(_0x3f60('0xa'));var fs=require('fs');var fs_extra=require(_0x3f60('0xb'));var _=require('lodash');var squel=require(_0x3f60('0xc'));var crypto=require('crypto');var jsforce=require(_0x3f60('0xd'));var deskjs=require(_0x3f60('0xe'));var toCsv=require(_0x3f60('0x9'));var querystring=require('querystring');var Papa=require(_0x3f60('0xf'));var Redis=require(_0x3f60('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x3f60('0x11'));var as=require(_0x3f60('0x12'));var hardwareService=require(_0x3f60('0x13'));var logger=require(_0x3f60('0x14'))(_0x3f60('0x15'));var utils=require(_0x3f60('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x3f60('0x17'));var db=require(_0x3f60('0x18'))['db'];function respondWithStatusCode(_0x3ce9a5,_0x44c201){_0x44c201=_0x44c201||0xcc;return function(_0x3a1efb){if(_0x3a1efb){return _0x3ce9a5[_0x3f60('0x19')](_0x44c201);}return _0x3ce9a5['status'](_0x44c201)[_0x3f60('0x1a')]();};}function respondWithResult(_0xff8613,_0x55e1b0){_0x55e1b0=_0x55e1b0||0xc8;return function(_0x4d847e){if(_0x4d847e){return _0xff8613['status'](_0x55e1b0)[_0x3f60('0x1b')](_0x4d847e);}};}function respondWithFilteredResult(_0x420623,_0x4809b5){return function(_0x5066e5){if(_0x5066e5){var _0x25c221=typeof _0x4809b5['offset']===_0x3f60('0x1c')&&typeof _0x4809b5['limit']==='undefined';var _0x5af9e1=_0x5066e5[_0x3f60('0x1d')];var _0x4a857e=_0x25c221?0x0:_0x4809b5[_0x3f60('0x1e')];var _0x151e32=_0x25c221?_0x5066e5[_0x3f60('0x1d')]:_0x4809b5[_0x3f60('0x1e')]+_0x4809b5[_0x3f60('0x1f')];var _0x248887;if(_0x151e32>=_0x5af9e1){_0x151e32=_0x5af9e1;_0x248887=0xc8;}else{_0x248887=0xce;}_0x420623[_0x3f60('0x20')](_0x248887);return _0x420623['set'](_0x3f60('0x21'),_0x4a857e+'-'+_0x151e32+'/'+_0x5af9e1)[_0x3f60('0x1b')](_0x5066e5);}return null;};}function patchUpdates(_0x11605e){return function(_0x3a292d){try{jsonpatch[_0x3f60('0x22')](_0x3a292d,_0x11605e,!![]);}catch(_0x58d4f6){return BPromise['reject'](_0x58d4f6);}return _0x3a292d[_0x3f60('0x23')]();};}function saveUpdates(_0x150abd,_0x5a9ef1){return function(_0x12f0cd){if(_0x12f0cd){return _0x12f0cd[_0x3f60('0x24')](_0x150abd)[_0x3f60('0x25')](function(_0x43da86){return _0x43da86;});}return null;};}function removeEntity(_0x2b2802,_0x15cde7){return function(_0x15cd87){if(_0x15cd87){return _0x15cd87[_0x3f60('0x26')]()['then'](function(){_0x2b2802[_0x3f60('0x20')](0xcc)[_0x3f60('0x1a')]();});}};}function handleEntityNotFound(_0x2dcf54,_0x39f214){return function(_0x4cb8f2){if(!_0x4cb8f2){_0x2dcf54[_0x3f60('0x19')](0x194);}return _0x4cb8f2;};}function handleError(_0x555fc6,_0x283273){_0x283273=_0x283273||0x1f4;return function(_0x49bb5d){logger[_0x3f60('0x27')](_0x49bb5d[_0x3f60('0x28')]);if(_0x49bb5d[_0x3f60('0x29')]){delete _0x49bb5d['name'];}_0x555fc6['status'](_0x283273)[_0x3f60('0x2a')](_0x49bb5d);};}exports[_0x3f60('0x2b')]=function(_0x439aab,_0x7e0c80){var _0xa17710={},_0x22dca4={},_0x256ec8={'count':0x0,'rows':[]};var _0x4a6129=_[_0x3f60('0x2c')](db[_0x3f60('0x2d')][_0x3f60('0x2e')],function(_0x4759f2){return{'name':_0x4759f2['fieldName'],'type':_0x4759f2[_0x3f60('0x2f')][_0x3f60('0x30')]};});_0x22dca4['model']=_[_0x3f60('0x2c')](_0x4a6129,_0x3f60('0x29'));_0x22dca4[_0x3f60('0x31')]=_[_0x3f60('0x32')](_0x439aab[_0x3f60('0x31')]);_0x22dca4[_0x3f60('0x33')]=_[_0x3f60('0x34')](_0x22dca4['model'],_0x22dca4[_0x3f60('0x31')]);_0xa17710[_0x3f60('0x35')]=_[_0x3f60('0x34')](_0x22dca4[_0x3f60('0x36')],qs[_0x3f60('0x37')](_0x439aab[_0x3f60('0x31')][_0x3f60('0x37')]));_0xa17710['attributes']=_0xa17710['attributes'][_0x3f60('0x38')]?_0xa17710[_0x3f60('0x35')]:_0x22dca4[_0x3f60('0x36')];if(!_0x439aab[_0x3f60('0x31')]['hasOwnProperty'](_0x3f60('0x39'))){_0xa17710[_0x3f60('0x1f')]=qs[_0x3f60('0x1f')](_0x439aab[_0x3f60('0x31')]['limit']);_0xa17710[_0x3f60('0x1e')]=qs['offset'](_0x439aab[_0x3f60('0x31')][_0x3f60('0x1e')]);}_0xa17710[_0x3f60('0x3a')]=qs[_0x3f60('0x3b')](_0x439aab['query'][_0x3f60('0x3b')]);_0xa17710[_0x3f60('0x3c')]=qs[_0x3f60('0x33')](_['pick'](_0x439aab[_0x3f60('0x31')],_0x22dca4[_0x3f60('0x33')]),_0x4a6129);if(_0x439aab['query']['filter']){_0xa17710[_0x3f60('0x3c')]=_['merge'](_0xa17710[_0x3f60('0x3c')],{'$or':_['map'](_0x4a6129,function(_0x47d2cb){if(_0x47d2cb[_0x3f60('0x2f')]!==_0x3f60('0x3d')){var _0x4dab08={};_0x4dab08[_0x47d2cb[_0x3f60('0x29')]]={'$like':'%'+_0x439aab[_0x3f60('0x31')]['filter']+'%'};return _0x4dab08;}})});}_0xa17710=_[_0x3f60('0x3e')]({},_0xa17710,_0x439aab[_0x3f60('0x3f')]);var _0x1876f2={'where':_0xa17710['where']};return db[_0x3f60('0x2d')]['count'](_0x1876f2)[_0x3f60('0x25')](function(_0x30fa5c){_0x256ec8[_0x3f60('0x1d')]=_0x30fa5c;if(_0x439aab[_0x3f60('0x31')][_0x3f60('0x40')]){_0xa17710['include']=[{'all':!![]}];}return db[_0x3f60('0x2d')][_0x3f60('0x41')](_0xa17710);})[_0x3f60('0x25')](function(_0x2c3dfe){_0x256ec8[_0x3f60('0x42')]=_0x2c3dfe;return _0x256ec8;})['then'](respondWithFilteredResult(_0x7e0c80,_0xa17710))['catch'](handleError(_0x7e0c80,null));};exports[_0x3f60('0x43')]=function(_0x36fb8d,_0x58da50){var _0x3e15e1={'raw':!![],'where':{'id':_0x36fb8d['params']['id']}},_0x293849={};_0x293849['model']=_[_0x3f60('0x32')](db[_0x3f60('0x2d')][_0x3f60('0x2e')]);_0x293849[_0x3f60('0x31')]=_[_0x3f60('0x32')](_0x36fb8d[_0x3f60('0x31')]);_0x293849[_0x3f60('0x33')]=_['intersection'](_0x293849['model'],_0x293849[_0x3f60('0x31')]);_0x3e15e1['attributes']=_[_0x3f60('0x34')](_0x293849[_0x3f60('0x36')],qs['fields'](_0x36fb8d[_0x3f60('0x31')][_0x3f60('0x37')]));_0x3e15e1[_0x3f60('0x35')]=_0x3e15e1[_0x3f60('0x35')][_0x3f60('0x38')]?_0x3e15e1[_0x3f60('0x35')]:_0x293849[_0x3f60('0x36')];if(_0x36fb8d[_0x3f60('0x31')][_0x3f60('0x40')]){_0x3e15e1[_0x3f60('0x44')]=[{'all':!![]}];}_0x3e15e1=_['merge']({},_0x3e15e1,_0x36fb8d['options']);return db['VoiceDialReport'][_0x3f60('0x45')](_0x3e15e1)['then'](handleEntityNotFound(_0x58da50,null))[_0x3f60('0x25')](respondWithResult(_0x58da50,null))[_0x3f60('0x46')](handleError(_0x58da50,null));};exports['create']=function(_0x35e182,_0x2b6984){return db[_0x3f60('0x2d')][_0x3f60('0x47')](_0x35e182[_0x3f60('0x48')],{})[_0x3f60('0x25')](respondWithResult(_0x2b6984,0xc9))[_0x3f60('0x46')](handleError(_0x2b6984,null));};exports['update']=function(_0x389f5a,_0x77ec62){if(_0x389f5a[_0x3f60('0x48')]['id']){delete _0x389f5a[_0x3f60('0x48')]['id'];}return db[_0x3f60('0x2d')]['find']({'where':{'id':_0x389f5a[_0x3f60('0x49')]['id']}})['then'](handleEntityNotFound(_0x77ec62,null))[_0x3f60('0x25')](saveUpdates(_0x389f5a[_0x3f60('0x48')],null))['then'](respondWithResult(_0x77ec62,null))[_0x3f60('0x46')](handleError(_0x77ec62,null));};exports['destroy']=function(_0x193167,_0x5b80ce){return db[_0x3f60('0x2d')][_0x3f60('0x45')]({'where':{'id':_0x193167[_0x3f60('0x49')]['id']}})[_0x3f60('0x25')](handleEntityNotFound(_0x5b80ce,null))[_0x3f60('0x25')](removeEntity(_0x5b80ce,null))['catch'](handleError(_0x5b80ce,null));};exports[_0x3f60('0x4a')]=function(_0x43b2e3,_0x5d9916){return db['VoiceDialReport']['describe']()[_0x3f60('0x25')](respondWithResult(_0x5d9916,null))[_0x3f60('0x46')](handleError(_0x5d9916,null));};