aab84a275866fe0183e4685eb39ddd36ff1c7baa
[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 _0x0f31=['describe','html-pdf','eml-format','request-promise','moment','bluebird','mustache','util','path','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','count','offset','limit','set','Content-Range','reject','update','destroy','then','stack','name','send','index','map','VoiceDialReport','fieldName','type','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','include','rows','catch','show','params','rawAttributes','options','find','create','body'];(function(_0x5037ab,_0x43209e){var _0x512adb=function(_0x261783){while(--_0x261783){_0x5037ab['push'](_0x5037ab['shift']());}};_0x512adb(++_0x43209e);}(_0x0f31,0x93));var _0x10f3=function(_0x4c3972,_0x478acd){_0x4c3972=_0x4c3972-0x0;var _0x12409d=_0x0f31[_0x4c3972];return _0x12409d;};'use strict';var pdf=require(_0x10f3('0x0'));var emlformat=require(_0x10f3('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x10f3('0x2'));var moment=require(_0x10f3('0x3'));var BPromise=require(_0x10f3('0x4'));var Mustache=require(_0x10f3('0x5'));var util=require(_0x10f3('0x6'));var path=require(_0x10f3('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x10f3('0x8'));var squel=require(_0x10f3('0x9'));var crypto=require(_0x10f3('0xa'));var jsforce=require(_0x10f3('0xb'));var deskjs=require(_0x10f3('0xc'));var toCsv=require(_0x10f3('0xd'));var querystring=require(_0x10f3('0xe'));var Papa=require('papaparse');var Redis=require(_0x10f3('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x10f3('0x10'));var as=require(_0x10f3('0x11'));var hardwareService=require(_0x10f3('0x12'));var logger=require(_0x10f3('0x13'))(_0x10f3('0x14'));var utils=require(_0x10f3('0x15'));var config=require(_0x10f3('0x16'));var licenseUtil=require(_0x10f3('0x17'));var db=require(_0x10f3('0x18'))['db'];function respondWithStatusCode(_0xbfbf11,_0xc11256){_0xc11256=_0xc11256||0xcc;return function(_0x4fa2a3){if(_0x4fa2a3){return _0xbfbf11['sendStatus'](_0xc11256);}return _0xbfbf11[_0x10f3('0x19')](_0xc11256)[_0x10f3('0x1a')]();};}function respondWithResult(_0x47a37b,_0x5e7e83){_0x5e7e83=_0x5e7e83||0xc8;return function(_0x2ae54f){if(_0x2ae54f){return _0x47a37b['status'](_0x5e7e83)[_0x10f3('0x1b')](_0x2ae54f);}};}function respondWithFilteredResult(_0x36f9f9,_0x57c649){return function(_0x207a38){if(_0x207a38){var _0x51f397=_0x207a38[_0x10f3('0x1c')],_0x47c0b2=_0x57c649['offset'],_0x4c4b70=_0x57c649[_0x10f3('0x1d')]+_0x57c649[_0x10f3('0x1e')],_0x5d016a;if(_0x4c4b70>=_0x51f397){_0x4c4b70=_0x51f397;_0x5d016a=0xc8;}else{_0x5d016a=0xce;}_0x36f9f9[_0x10f3('0x19')](_0x5d016a);return _0x36f9f9[_0x10f3('0x1f')](_0x10f3('0x20'),_0x47c0b2+'-'+_0x4c4b70+'/'+_0x51f397)[_0x10f3('0x1b')](_0x207a38);}return null;};}function patchUpdates(_0x22d55f){return function(_0x1f2525){try{jsonpatch['apply'](_0x1f2525,_0x22d55f,!![]);}catch(_0x11fb32){return BPromise[_0x10f3('0x21')](_0x11fb32);}return _0x1f2525['save']();};}function saveUpdates(_0x5e2584,_0x388291){return function(_0x425564){if(_0x425564){return _0x425564[_0x10f3('0x22')](_0x5e2584)['then'](function(_0x18b5c4){return _0x18b5c4;});}return null;};}function removeEntity(_0x600e8a,_0x1132ea){return function(_0x325974){if(_0x325974){return _0x325974[_0x10f3('0x23')]()[_0x10f3('0x24')](function(){_0x600e8a[_0x10f3('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x50efc7,_0x56f0d5){return function(_0x4e143c){if(!_0x4e143c){_0x50efc7['sendStatus'](0x194);}return _0x4e143c;};}function handleError(_0x26d6fe,_0x2473b8){_0x2473b8=_0x2473b8||0x1f4;return function(_0xe68cc0){logger['error'](_0xe68cc0[_0x10f3('0x25')]);if(_0xe68cc0[_0x10f3('0x26')]){delete _0xe68cc0[_0x10f3('0x26')];}_0x26d6fe[_0x10f3('0x19')](_0x2473b8)[_0x10f3('0x27')](_0xe68cc0);};}exports[_0x10f3('0x28')]=function(_0x1571fb,_0x50465e){var _0x361fd9={},_0x17843e={},_0x3f6311={'count':0x0,'rows':[]};var _0x2f2739=_[_0x10f3('0x29')](db[_0x10f3('0x2a')]['rawAttributes'],function(_0x28b3c3){return{'name':_0x28b3c3[_0x10f3('0x2b')],'type':_0x28b3c3[_0x10f3('0x2c')]['key']};});_0x17843e[_0x10f3('0x2d')]=_[_0x10f3('0x29')](_0x2f2739,_0x10f3('0x26'));_0x17843e['query']=_[_0x10f3('0x2e')](_0x1571fb[_0x10f3('0x2f')]);_0x17843e[_0x10f3('0x30')]=_['intersection'](_0x17843e[_0x10f3('0x2d')],_0x17843e[_0x10f3('0x2f')]);_0x361fd9[_0x10f3('0x31')]=_[_0x10f3('0x32')](_0x17843e['model'],qs['fields'](_0x1571fb[_0x10f3('0x2f')][_0x10f3('0x33')]));_0x361fd9[_0x10f3('0x31')]=_0x361fd9[_0x10f3('0x31')][_0x10f3('0x34')]?_0x361fd9[_0x10f3('0x31')]:_0x17843e[_0x10f3('0x2d')];if(!_0x1571fb[_0x10f3('0x2f')][_0x10f3('0x35')](_0x10f3('0x36'))){_0x361fd9[_0x10f3('0x1e')]=qs[_0x10f3('0x1e')](_0x1571fb[_0x10f3('0x2f')][_0x10f3('0x1e')]);_0x361fd9[_0x10f3('0x1d')]=qs[_0x10f3('0x1d')](_0x1571fb['query'][_0x10f3('0x1d')]);}_0x361fd9[_0x10f3('0x37')]=qs[_0x10f3('0x38')](_0x1571fb[_0x10f3('0x2f')]['sort']);_0x361fd9[_0x10f3('0x39')]=qs[_0x10f3('0x30')](_[_0x10f3('0x3a')](_0x1571fb[_0x10f3('0x2f')],_0x17843e[_0x10f3('0x30')]),_0x2f2739);if(_0x1571fb[_0x10f3('0x2f')][_0x10f3('0x3b')]){_0x361fd9[_0x10f3('0x39')]=_[_0x10f3('0x3c')](_0x361fd9[_0x10f3('0x39')],{'$or':_[_0x10f3('0x29')](_0x2f2739,function(_0x1458e1){if(_0x1458e1[_0x10f3('0x2c')]!==_0x10f3('0x3d')){var _0x42e1e2={};_0x42e1e2[_0x1458e1['name']]={'$like':'%'+_0x1571fb[_0x10f3('0x2f')][_0x10f3('0x3b')]+'%'};return _0x42e1e2;}})});}_0x361fd9=_[_0x10f3('0x3c')]({},_0x361fd9,_0x1571fb['options']);var _0x12f62b={'where':_0x361fd9['where']};return db['VoiceDialReport'][_0x10f3('0x1c')](_0x12f62b)[_0x10f3('0x24')](function(_0x4ad602){_0x3f6311[_0x10f3('0x1c')]=_0x4ad602;if(_0x1571fb[_0x10f3('0x2f')]['includeAll']){_0x361fd9[_0x10f3('0x3e')]=[{'all':!![]}];}return db[_0x10f3('0x2a')]['findAll'](_0x361fd9);})[_0x10f3('0x24')](function(_0xf40283){_0x3f6311[_0x10f3('0x3f')]=_0xf40283;return _0x3f6311;})[_0x10f3('0x24')](respondWithFilteredResult(_0x50465e,_0x361fd9))[_0x10f3('0x40')](handleError(_0x50465e,null));};exports[_0x10f3('0x41')]=function(_0x2ed900,_0x1788a5){var _0x38e0dc={'raw':!![],'where':{'id':_0x2ed900[_0x10f3('0x42')]['id']}},_0x31ffbc={};_0x31ffbc[_0x10f3('0x2d')]=_[_0x10f3('0x2e')](db['VoiceDialReport'][_0x10f3('0x43')]);_0x31ffbc['query']=_[_0x10f3('0x2e')](_0x2ed900['query']);_0x31ffbc[_0x10f3('0x30')]=_['intersection'](_0x31ffbc[_0x10f3('0x2d')],_0x31ffbc[_0x10f3('0x2f')]);_0x38e0dc['attributes']=_[_0x10f3('0x32')](_0x31ffbc[_0x10f3('0x2d')],qs[_0x10f3('0x33')](_0x2ed900[_0x10f3('0x2f')][_0x10f3('0x33')]));_0x38e0dc[_0x10f3('0x31')]=_0x38e0dc[_0x10f3('0x31')][_0x10f3('0x34')]?_0x38e0dc['attributes']:_0x31ffbc[_0x10f3('0x2d')];if(_0x2ed900[_0x10f3('0x2f')]['includeAll']){_0x38e0dc[_0x10f3('0x3e')]=[{'all':!![]}];}_0x38e0dc=_[_0x10f3('0x3c')]({},_0x38e0dc,_0x2ed900[_0x10f3('0x44')]);return db[_0x10f3('0x2a')][_0x10f3('0x45')](_0x38e0dc)[_0x10f3('0x24')](handleEntityNotFound(_0x1788a5,null))[_0x10f3('0x24')](respondWithResult(_0x1788a5,null))[_0x10f3('0x40')](handleError(_0x1788a5,null));};exports[_0x10f3('0x46')]=function(_0x22c313,_0x3160ea){return db[_0x10f3('0x2a')][_0x10f3('0x46')](_0x22c313['body'],{})[_0x10f3('0x24')](respondWithResult(_0x3160ea,0xc9))[_0x10f3('0x40')](handleError(_0x3160ea,null));};exports['update']=function(_0x4fcf9d,_0x47a80f){if(_0x4fcf9d[_0x10f3('0x47')]['id']){delete _0x4fcf9d['body']['id'];}return db[_0x10f3('0x2a')]['find']({'where':{'id':_0x4fcf9d[_0x10f3('0x42')]['id']}})[_0x10f3('0x24')](handleEntityNotFound(_0x47a80f,null))[_0x10f3('0x24')](saveUpdates(_0x4fcf9d[_0x10f3('0x47')],null))[_0x10f3('0x24')](respondWithResult(_0x47a80f,null))[_0x10f3('0x40')](handleError(_0x47a80f,null));};exports[_0x10f3('0x23')]=function(_0x1d991f,_0x956fa7){return db[_0x10f3('0x2a')]['find']({'where':{'id':_0x1d991f[_0x10f3('0x42')]['id']}})[_0x10f3('0x24')](handleEntityNotFound(_0x956fa7,null))['then'](removeEntity(_0x956fa7,null))[_0x10f3('0x40')](handleError(_0x956fa7,null));};exports[_0x10f3('0x48')]=function(_0xb3e75e,_0x4d5322){return db[_0x10f3('0x2a')][_0x10f3('0x48')]()[_0x10f3('0x24')](respondWithResult(_0x4d5322,null))[_0x10f3('0x40')](handleError(_0x4d5322,null));};