067b20a01e29a1614be0db0c95947789f93bafbf
[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 _0xacf7=['fields','length','order','sort','where','filter','merge','options','count','includeAll','include','findAll','catch','show','params','keys','find','create','body','update','destroy','describe','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','reject','then','error','stack','name','send','index','map','VoiceDialReport','rawAttributes','fieldName','type','query','filters','intersection','attributes','model'];(function(_0x698e19,_0x37fd58){var _0x3db5bf=function(_0x73b6b0){while(--_0x73b6b0){_0x698e19['push'](_0x698e19['shift']());}};_0x3db5bf(++_0x37fd58);}(_0xacf7,0x1d2));var _0x7acf=function(_0x4b369d,_0x265eb8){_0x4b369d=_0x4b369d-0x0;var _0x571a98=_0xacf7[_0x4b369d];return _0x571a98;};'use strict';var pdf=require(_0x7acf('0x0'));var emlformat=require(_0x7acf('0x1'));var rimraf=require(_0x7acf('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7acf('0x3'));var rp=require(_0x7acf('0x4'));var moment=require(_0x7acf('0x5'));var BPromise=require(_0x7acf('0x6'));var Mustache=require(_0x7acf('0x7'));var util=require(_0x7acf('0x8'));var path=require('path');var sox=require(_0x7acf('0x9'));var csv=require('to-csv');var ejs=require(_0x7acf('0xa'));var fs=require('fs');var _=require(_0x7acf('0xb'));var squel=require(_0x7acf('0xc'));var crypto=require(_0x7acf('0xd'));var jsforce=require(_0x7acf('0xe'));var deskjs=require(_0x7acf('0xf'));var toCsv=require(_0x7acf('0x10'));var querystring=require(_0x7acf('0x11'));var Papa=require(_0x7acf('0x12'));var Redis=require('ioredis');var authService=require(_0x7acf('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x7acf('0x14'));var hardwareService=require(_0x7acf('0x15'));var logger=require(_0x7acf('0x16'))(_0x7acf('0x17'));var utils=require(_0x7acf('0x18'));var config=require(_0x7acf('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x7acf('0x1a'))['db'];function respondWithStatusCode(_0x28d047,_0xf8bf6f){_0xf8bf6f=_0xf8bf6f||0xcc;return function(_0x5109ea){if(_0x5109ea){return _0x28d047[_0x7acf('0x1b')](_0xf8bf6f);}return _0x28d047[_0x7acf('0x1c')](_0xf8bf6f)[_0x7acf('0x1d')]();};}function respondWithResult(_0x5184aa,_0x4b113f){_0x4b113f=_0x4b113f||0xc8;return function(_0x10c5c0){if(_0x10c5c0){return _0x5184aa[_0x7acf('0x1c')](_0x4b113f)[_0x7acf('0x1e')](_0x10c5c0);}};}function respondWithFilteredResult(_0x3dfb10,_0x31c8b0){return function(_0x2e3a60){if(_0x2e3a60){var _0x1df01b=_0x2e3a60['count'],_0x4b303a=_0x31c8b0[_0x7acf('0x1f')],_0x21bf76=_0x31c8b0[_0x7acf('0x1f')]+_0x31c8b0[_0x7acf('0x20')],_0x5530e8;if(_0x21bf76>=_0x1df01b){_0x21bf76=_0x1df01b;_0x5530e8=0xc8;}else{_0x5530e8=0xce;}_0x3dfb10[_0x7acf('0x1c')](_0x5530e8);return _0x3dfb10[_0x7acf('0x21')](_0x7acf('0x22'),_0x4b303a+'-'+_0x21bf76+'/'+_0x1df01b)[_0x7acf('0x1e')](_0x2e3a60);}return null;};}function patchUpdates(_0x86de96){return function(_0x327003){try{jsonpatch['apply'](_0x327003,_0x86de96,!![]);}catch(_0x1e2b1c){return BPromise[_0x7acf('0x23')](_0x1e2b1c);}return _0x327003['save']();};}function saveUpdates(_0xdb5f3c,_0x5c6295){return function(_0xe37d9d){if(_0xe37d9d){return _0xe37d9d['update'](_0xdb5f3c)['then'](function(_0x3e97ea){return _0x3e97ea;});}return null;};}function removeEntity(_0x5e47c6,_0x4a5763){return function(_0x113500){if(_0x113500){return _0x113500['destroy']()[_0x7acf('0x24')](function(){_0x5e47c6[_0x7acf('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4c9f2a,_0x2670b6){return function(_0x460594){if(!_0x460594){_0x4c9f2a['sendStatus'](0x194);}return _0x460594;};}function handleError(_0x3271e1,_0x4d0791){_0x4d0791=_0x4d0791||0x1f4;return function(_0x50d3e6){logger[_0x7acf('0x25')](_0x50d3e6[_0x7acf('0x26')]);if(_0x50d3e6[_0x7acf('0x27')]){delete _0x50d3e6[_0x7acf('0x27')];}_0x3271e1[_0x7acf('0x1c')](_0x4d0791)[_0x7acf('0x28')](_0x50d3e6);};}exports[_0x7acf('0x29')]=function(_0x167634,_0xdd5d46){var _0x4a8eb2={},_0xc0c0f7={},_0x41771d={'count':0x0,'rows':[]};var _0x460253=_[_0x7acf('0x2a')](db[_0x7acf('0x2b')][_0x7acf('0x2c')],function(_0x8ddbcf){return{'name':_0x8ddbcf[_0x7acf('0x2d')],'type':_0x8ddbcf[_0x7acf('0x2e')]['key']};});_0xc0c0f7['model']=_[_0x7acf('0x2a')](_0x460253,_0x7acf('0x27'));_0xc0c0f7['query']=_['keys'](_0x167634[_0x7acf('0x2f')]);_0xc0c0f7[_0x7acf('0x30')]=_[_0x7acf('0x31')](_0xc0c0f7['model'],_0xc0c0f7[_0x7acf('0x2f')]);_0x4a8eb2[_0x7acf('0x32')]=_[_0x7acf('0x31')](_0xc0c0f7[_0x7acf('0x33')],qs['fields'](_0x167634[_0x7acf('0x2f')][_0x7acf('0x34')]));_0x4a8eb2[_0x7acf('0x32')]=_0x4a8eb2[_0x7acf('0x32')][_0x7acf('0x35')]?_0x4a8eb2[_0x7acf('0x32')]:_0xc0c0f7[_0x7acf('0x33')];if(!_0x167634['query']['hasOwnProperty']('nolimit')){_0x4a8eb2[_0x7acf('0x20')]=qs[_0x7acf('0x20')](_0x167634[_0x7acf('0x2f')][_0x7acf('0x20')]);_0x4a8eb2['offset']=qs[_0x7acf('0x1f')](_0x167634[_0x7acf('0x2f')][_0x7acf('0x1f')]);}_0x4a8eb2[_0x7acf('0x36')]=qs[_0x7acf('0x37')](_0x167634[_0x7acf('0x2f')][_0x7acf('0x37')]);_0x4a8eb2[_0x7acf('0x38')]=qs[_0x7acf('0x30')](_['pick'](_0x167634[_0x7acf('0x2f')],_0xc0c0f7[_0x7acf('0x30')]),_0x460253);if(_0x167634['query'][_0x7acf('0x39')]){_0x4a8eb2[_0x7acf('0x38')]=_[_0x7acf('0x3a')](_0x4a8eb2[_0x7acf('0x38')],{'$or':_['map'](_0x460253,function(_0x4ce7de){if(_0x4ce7de['type']!=='VIRTUAL'){var _0x127a74={};_0x127a74[_0x4ce7de['name']]={'$like':'%'+_0x167634[_0x7acf('0x2f')][_0x7acf('0x39')]+'%'};return _0x127a74;}})});}_0x4a8eb2=_[_0x7acf('0x3a')]({},_0x4a8eb2,_0x167634[_0x7acf('0x3b')]);var _0x14d02f={'where':_0x4a8eb2[_0x7acf('0x38')]};return db[_0x7acf('0x2b')]['count'](_0x14d02f)[_0x7acf('0x24')](function(_0x367362){_0x41771d[_0x7acf('0x3c')]=_0x367362;if(_0x167634['query'][_0x7acf('0x3d')]){_0x4a8eb2[_0x7acf('0x3e')]=[{'all':!![]}];}return db['VoiceDialReport'][_0x7acf('0x3f')](_0x4a8eb2);})[_0x7acf('0x24')](function(_0xf38e61){_0x41771d['rows']=_0xf38e61;return _0x41771d;})[_0x7acf('0x24')](respondWithFilteredResult(_0xdd5d46,_0x4a8eb2))[_0x7acf('0x40')](handleError(_0xdd5d46,null));};exports[_0x7acf('0x41')]=function(_0x4559a1,_0x5b5937){var _0x3fee19={'raw':!![],'where':{'id':_0x4559a1[_0x7acf('0x42')]['id']}},_0x5292d6={};_0x5292d6[_0x7acf('0x33')]=_[_0x7acf('0x43')](db['VoiceDialReport'][_0x7acf('0x2c')]);_0x5292d6['query']=_[_0x7acf('0x43')](_0x4559a1['query']);_0x5292d6[_0x7acf('0x30')]=_[_0x7acf('0x31')](_0x5292d6[_0x7acf('0x33')],_0x5292d6[_0x7acf('0x2f')]);_0x3fee19['attributes']=_[_0x7acf('0x31')](_0x5292d6['model'],qs['fields'](_0x4559a1[_0x7acf('0x2f')][_0x7acf('0x34')]));_0x3fee19[_0x7acf('0x32')]=_0x3fee19[_0x7acf('0x32')][_0x7acf('0x35')]?_0x3fee19[_0x7acf('0x32')]:_0x5292d6[_0x7acf('0x33')];if(_0x4559a1[_0x7acf('0x2f')]['includeAll']){_0x3fee19['include']=[{'all':!![]}];}_0x3fee19=_['merge']({},_0x3fee19,_0x4559a1['options']);return db[_0x7acf('0x2b')][_0x7acf('0x44')](_0x3fee19)[_0x7acf('0x24')](handleEntityNotFound(_0x5b5937,null))['then'](respondWithResult(_0x5b5937,null))['catch'](handleError(_0x5b5937,null));};exports[_0x7acf('0x45')]=function(_0x479110,_0x425e0c){return db['VoiceDialReport']['create'](_0x479110[_0x7acf('0x46')],{})[_0x7acf('0x24')](respondWithResult(_0x425e0c,0xc9))[_0x7acf('0x40')](handleError(_0x425e0c,null));};exports[_0x7acf('0x47')]=function(_0x39c998,_0x377e59){if(_0x39c998[_0x7acf('0x46')]['id']){delete _0x39c998[_0x7acf('0x46')]['id'];}return db['VoiceDialReport'][_0x7acf('0x44')]({'where':{'id':_0x39c998[_0x7acf('0x42')]['id']}})[_0x7acf('0x24')](handleEntityNotFound(_0x377e59,null))[_0x7acf('0x24')](saveUpdates(_0x39c998['body'],null))['then'](respondWithResult(_0x377e59,null))[_0x7acf('0x40')](handleError(_0x377e59,null));};exports[_0x7acf('0x48')]=function(_0x2b06f4,_0x462e94){return db[_0x7acf('0x2b')][_0x7acf('0x44')]({'where':{'id':_0x2b06f4[_0x7acf('0x42')]['id']}})[_0x7acf('0x24')](handleEntityNotFound(_0x462e94,null))[_0x7acf('0x24')](removeEntity(_0x462e94,null))['catch'](handleError(_0x462e94,null));};exports[_0x7acf('0x49')]=function(_0x546528,_0x207a86){return db[_0x7acf('0x2b')]['describe']()[_0x7acf('0x24')](respondWithResult(_0x207a86,null))[_0x7acf('0x40')](handleError(_0x207a86,null));};