Built motion from commit 25580385.|2.6.2
[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 _0x3af8=['mustache','util','path','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../mysqldb','sendStatus','json','offset','limit','undefined','count','status','set','Content-Range','apply','reject','save','update','then','destroy','end','error','name','send','map','rawAttributes','type','query','keys','filters','intersection','model','attributes','fields','length','nolimit','sort','where','pick','filter','merge','VoiceDialReport','include','findAll','rows','catch','find','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x91f6b4,_0x237124){var _0x472b8a=function(_0x163ac6){while(--_0x163ac6){_0x91f6b4['push'](_0x91f6b4['shift']());}};_0x472b8a(++_0x237124);}(_0x3af8,0xc7));var _0x83af=function(_0x4d7420,_0x12c453){_0x4d7420=_0x4d7420-0x0;var _0x575f76=_0x3af8[_0x4d7420];return _0x575f76;};'use strict';var emlformat=require(_0x83af('0x0'));var rimraf=require(_0x83af('0x1'));var zipdir=require(_0x83af('0x2'));var jsonpatch=require(_0x83af('0x3'));var rp=require(_0x83af('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x83af('0x5'));var util=require(_0x83af('0x6'));var path=require(_0x83af('0x7'));var sox=require('sox');var csv=require(_0x83af('0x8'));var ejs=require(_0x83af('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x83af('0xa'));var squel=require(_0x83af('0xb'));var crypto=require('crypto');var jsforce=require(_0x83af('0xc'));var deskjs=require(_0x83af('0xd'));var toCsv=require(_0x83af('0x8'));var querystring=require(_0x83af('0xe'));var Papa=require(_0x83af('0xf'));var Redis=require('ioredis');var authService=require(_0x83af('0x10'));var qs=require(_0x83af('0x11'));var as=require(_0x83af('0x12'));var hardwareService=require(_0x83af('0x13'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x83af('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x83af('0x15'))['db'];function respondWithStatusCode(_0x1997cc,_0x57eac4){_0x57eac4=_0x57eac4||0xcc;return function(_0x1fcb04){if(_0x1fcb04){return _0x1997cc[_0x83af('0x16')](_0x57eac4);}return _0x1997cc['status'](_0x57eac4)['end']();};}function respondWithResult(_0x59564e,_0xfb50e2){_0xfb50e2=_0xfb50e2||0xc8;return function(_0x1abf26){if(_0x1abf26){return _0x59564e['status'](_0xfb50e2)[_0x83af('0x17')](_0x1abf26);}};}function respondWithFilteredResult(_0x1cf2da,_0x2d25df){return function(_0x31f45c){if(_0x31f45c){var _0x2451db=typeof _0x2d25df[_0x83af('0x18')]==='undefined'&&typeof _0x2d25df[_0x83af('0x19')]===_0x83af('0x1a');var _0x390c29=_0x31f45c[_0x83af('0x1b')];var _0x598929=_0x2451db?0x0:_0x2d25df[_0x83af('0x18')];var _0x897f9d=_0x2451db?_0x31f45c[_0x83af('0x1b')]:_0x2d25df[_0x83af('0x18')]+_0x2d25df[_0x83af('0x19')];var _0x263cc9;if(_0x897f9d>=_0x390c29){_0x897f9d=_0x390c29;_0x263cc9=0xc8;}else{_0x263cc9=0xce;}_0x1cf2da[_0x83af('0x1c')](_0x263cc9);return _0x1cf2da[_0x83af('0x1d')](_0x83af('0x1e'),_0x598929+'-'+_0x897f9d+'/'+_0x390c29)[_0x83af('0x17')](_0x31f45c);}return null;};}function patchUpdates(_0x5f1826){return function(_0x189b95){try{jsonpatch[_0x83af('0x1f')](_0x189b95,_0x5f1826,!![]);}catch(_0x14fbf7){return BPromise[_0x83af('0x20')](_0x14fbf7);}return _0x189b95[_0x83af('0x21')]();};}function saveUpdates(_0x36ffa9,_0x4062af){return function(_0x287784){if(_0x287784){return _0x287784[_0x83af('0x22')](_0x36ffa9)[_0x83af('0x23')](function(_0x3bce46){return _0x3bce46;});}return null;};}function removeEntity(_0x51df0d,_0x17b8ae){return function(_0x4569b7){if(_0x4569b7){return _0x4569b7[_0x83af('0x24')]()[_0x83af('0x23')](function(){_0x51df0d[_0x83af('0x1c')](0xcc)[_0x83af('0x25')]();});}};}function handleEntityNotFound(_0xfbc493,_0x32479f){return function(_0x4abe27){if(!_0x4abe27){_0xfbc493[_0x83af('0x16')](0x194);}return _0x4abe27;};}function handleError(_0x3695e4,_0x635bc5){_0x635bc5=_0x635bc5||0x1f4;return function(_0x1c814c){logger[_0x83af('0x26')](_0x1c814c['stack']);if(_0x1c814c[_0x83af('0x27')]){delete _0x1c814c[_0x83af('0x27')];}_0x3695e4[_0x83af('0x1c')](_0x635bc5)[_0x83af('0x28')](_0x1c814c);};}exports['index']=function(_0x5227fa,_0x26de29){var _0xf6174a={},_0x3472f0={},_0x42d086={'count':0x0,'rows':[]};var _0x3c0458=_[_0x83af('0x29')](db['VoiceDialReport'][_0x83af('0x2a')],function(_0xe893e4){return{'name':_0xe893e4['fieldName'],'type':_0xe893e4[_0x83af('0x2b')]['key']};});_0x3472f0['model']=_[_0x83af('0x29')](_0x3c0458,_0x83af('0x27'));_0x3472f0[_0x83af('0x2c')]=_[_0x83af('0x2d')](_0x5227fa[_0x83af('0x2c')]);_0x3472f0[_0x83af('0x2e')]=_[_0x83af('0x2f')](_0x3472f0[_0x83af('0x30')],_0x3472f0[_0x83af('0x2c')]);_0xf6174a[_0x83af('0x31')]=_['intersection'](_0x3472f0[_0x83af('0x30')],qs[_0x83af('0x32')](_0x5227fa[_0x83af('0x2c')][_0x83af('0x32')]));_0xf6174a[_0x83af('0x31')]=_0xf6174a['attributes'][_0x83af('0x33')]?_0xf6174a[_0x83af('0x31')]:_0x3472f0[_0x83af('0x30')];if(!_0x5227fa[_0x83af('0x2c')]['hasOwnProperty'](_0x83af('0x34'))){_0xf6174a['limit']=qs[_0x83af('0x19')](_0x5227fa[_0x83af('0x2c')][_0x83af('0x19')]);_0xf6174a[_0x83af('0x18')]=qs[_0x83af('0x18')](_0x5227fa[_0x83af('0x2c')][_0x83af('0x18')]);}_0xf6174a['order']=qs['sort'](_0x5227fa[_0x83af('0x2c')][_0x83af('0x35')]);_0xf6174a[_0x83af('0x36')]=qs[_0x83af('0x2e')](_[_0x83af('0x37')](_0x5227fa['query'],_0x3472f0['filters']),_0x3c0458);if(_0x5227fa['query']['filter']){_0xf6174a[_0x83af('0x36')]=_['merge'](_0xf6174a[_0x83af('0x36')],{'$or':_[_0x83af('0x29')](_0x3c0458,function(_0x528dd7){if(_0x528dd7['type']!=='VIRTUAL'){var _0xb410={};_0xb410[_0x528dd7[_0x83af('0x27')]]={'$like':'%'+_0x5227fa['query'][_0x83af('0x38')]+'%'};return _0xb410;}})});}_0xf6174a=_[_0x83af('0x39')]({},_0xf6174a,_0x5227fa['options']);var _0x2622e8={'where':_0xf6174a[_0x83af('0x36')]};return db[_0x83af('0x3a')][_0x83af('0x1b')](_0x2622e8)['then'](function(_0xc2eaf7){_0x42d086['count']=_0xc2eaf7;if(_0x5227fa[_0x83af('0x2c')]['includeAll']){_0xf6174a[_0x83af('0x3b')]=[{'all':!![]}];}return db[_0x83af('0x3a')][_0x83af('0x3c')](_0xf6174a);})[_0x83af('0x23')](function(_0x10809b){_0x42d086[_0x83af('0x3d')]=_0x10809b;return _0x42d086;})['then'](respondWithFilteredResult(_0x26de29,_0xf6174a))[_0x83af('0x3e')](handleError(_0x26de29,null));};exports['show']=function(_0xccf716,_0x5bef48){var _0x121be7={'raw':!![],'where':{'id':_0xccf716['params']['id']}},_0x5115bd={};_0x5115bd[_0x83af('0x30')]=_[_0x83af('0x2d')](db[_0x83af('0x3a')][_0x83af('0x2a')]);_0x5115bd[_0x83af('0x2c')]=_[_0x83af('0x2d')](_0xccf716[_0x83af('0x2c')]);_0x5115bd[_0x83af('0x2e')]=_[_0x83af('0x2f')](_0x5115bd[_0x83af('0x30')],_0x5115bd[_0x83af('0x2c')]);_0x121be7['attributes']=_[_0x83af('0x2f')](_0x5115bd[_0x83af('0x30')],qs[_0x83af('0x32')](_0xccf716['query'][_0x83af('0x32')]));_0x121be7[_0x83af('0x31')]=_0x121be7[_0x83af('0x31')]['length']?_0x121be7[_0x83af('0x31')]:_0x5115bd[_0x83af('0x30')];if(_0xccf716['query']['includeAll']){_0x121be7[_0x83af('0x3b')]=[{'all':!![]}];}_0x121be7=_['merge']({},_0x121be7,_0xccf716['options']);return db[_0x83af('0x3a')][_0x83af('0x3f')](_0x121be7)[_0x83af('0x23')](handleEntityNotFound(_0x5bef48,null))[_0x83af('0x23')](respondWithResult(_0x5bef48,null))['catch'](handleError(_0x5bef48,null));};exports[_0x83af('0x40')]=function(_0x591d7d,_0x189e1b){return db['VoiceDialReport'][_0x83af('0x40')](_0x591d7d[_0x83af('0x41')],{})['then'](respondWithResult(_0x189e1b,0xc9))[_0x83af('0x3e')](handleError(_0x189e1b,null));};exports['update']=function(_0x2e4bd1,_0x2837bc){if(_0x2e4bd1[_0x83af('0x41')]['id']){delete _0x2e4bd1[_0x83af('0x41')]['id'];}return db['VoiceDialReport']['find']({'where':{'id':_0x2e4bd1[_0x83af('0x42')]['id']}})[_0x83af('0x23')](handleEntityNotFound(_0x2837bc,null))['then'](saveUpdates(_0x2e4bd1['body'],null))[_0x83af('0x23')](respondWithResult(_0x2837bc,null))[_0x83af('0x3e')](handleError(_0x2837bc,null));};exports[_0x83af('0x24')]=function(_0x28e431,_0x30ffee){return db['VoiceDialReport']['find']({'where':{'id':_0x28e431[_0x83af('0x42')]['id']}})['then'](handleEntityNotFound(_0x30ffee,null))[_0x83af('0x23')](removeEntity(_0x30ffee,null))['catch'](handleError(_0x30ffee,null));};exports['describe']=function(_0x578527,_0x35b649){return db[_0x83af('0x3a')][_0x83af('0x43')]()[_0x83af('0x23')](respondWithResult(_0x35b649,null))[_0x83af('0x3e')](handleError(_0x35b649,null));};