d4ec9fa9c8f75f3e8f306262626d950019daff4d
[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 _0x6b66=['send','index','VoiceDialReport','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','type','includeAll','findAll','rows','catch','show','params','rawAttributes','include','options','find','create','body','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','sendStatus','stack','name'];(function(_0x765d2,_0xc3fd7c){var _0x3c6658=function(_0x1ab7b2){while(--_0x1ab7b2){_0x765d2['push'](_0x765d2['shift']());}};_0x3c6658(++_0xc3fd7c);}(_0x6b66,0x199));var _0x66b6=function(_0x2e06b4,_0x4c967a){_0x2e06b4=_0x2e06b4-0x0;var _0x1b5d38=_0x6b66[_0x2e06b4];return _0x1b5d38;};'use strict';var pdf=require(_0x66b6('0x0'));var emlformat=require(_0x66b6('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x66b6('0x2'));var jsonpatch=require(_0x66b6('0x3'));var rp=require(_0x66b6('0x4'));var moment=require(_0x66b6('0x5'));var BPromise=require(_0x66b6('0x6'));var Mustache=require(_0x66b6('0x7'));var util=require(_0x66b6('0x8'));var path=require(_0x66b6('0x9'));var sox=require('sox');var csv=require(_0x66b6('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x66b6('0xb'));var squel=require(_0x66b6('0xc'));var crypto=require(_0x66b6('0xd'));var jsforce=require(_0x66b6('0xe'));var deskjs=require(_0x66b6('0xf'));var toCsv=require(_0x66b6('0xa'));var querystring=require(_0x66b6('0x10'));var Papa=require(_0x66b6('0x11'));var Redis=require(_0x66b6('0x12'));var authService=require(_0x66b6('0x13'));var qs=require(_0x66b6('0x14'));var as=require(_0x66b6('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x66b6('0x16'));var utils=require('../../config/utils');var config=require(_0x66b6('0x17'));var licenseUtil=require(_0x66b6('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x89d908,_0x10e0d3){_0x10e0d3=_0x10e0d3||0xcc;return function(_0x35ebe4){if(_0x35ebe4){return _0x89d908['sendStatus'](_0x10e0d3);}return _0x89d908[_0x66b6('0x19')](_0x10e0d3)[_0x66b6('0x1a')]();};}function respondWithResult(_0x2c5e83,_0xa3f5bc){_0xa3f5bc=_0xa3f5bc||0xc8;return function(_0x4af53a){if(_0x4af53a){return _0x2c5e83[_0x66b6('0x19')](_0xa3f5bc)[_0x66b6('0x1b')](_0x4af53a);}};}function respondWithFilteredResult(_0x1ced02,_0x3f80c4){return function(_0x44f094){if(_0x44f094){var _0x361188=_0x44f094[_0x66b6('0x1c')],_0xada849=_0x3f80c4[_0x66b6('0x1d')],_0x133814=_0x3f80c4['offset']+_0x3f80c4[_0x66b6('0x1e')],_0x3760b9;if(_0x133814>=_0x361188){_0x133814=_0x361188;_0x3760b9=0xc8;}else{_0x3760b9=0xce;}_0x1ced02[_0x66b6('0x19')](_0x3760b9);return _0x1ced02[_0x66b6('0x1f')](_0x66b6('0x20'),_0xada849+'-'+_0x133814+'/'+_0x361188)['json'](_0x44f094);}return null;};}function patchUpdates(_0x823e3c){return function(_0x46bec5){try{jsonpatch[_0x66b6('0x21')](_0x46bec5,_0x823e3c,!![]);}catch(_0x300114){return BPromise['reject'](_0x300114);}return _0x46bec5[_0x66b6('0x22')]();};}function saveUpdates(_0x2e8cd,_0x10afac){return function(_0x44d617){if(_0x44d617){return _0x44d617[_0x66b6('0x23')](_0x2e8cd)[_0x66b6('0x24')](function(_0x10968a){return _0x10968a;});}return null;};}function removeEntity(_0x5e9b16,_0x10b32c){return function(_0x1fb58e){if(_0x1fb58e){return _0x1fb58e[_0x66b6('0x25')]()[_0x66b6('0x24')](function(){_0x5e9b16['status'](0xcc)[_0x66b6('0x1a')]();});}};}function handleEntityNotFound(_0x53e988,_0x3c5646){return function(_0x44b4fb){if(!_0x44b4fb){_0x53e988[_0x66b6('0x26')](0x194);}return _0x44b4fb;};}function handleError(_0x40e20d,_0x40ffba){_0x40ffba=_0x40ffba||0x1f4;return function(_0x3d6658){logger['error'](_0x3d6658[_0x66b6('0x27')]);if(_0x3d6658[_0x66b6('0x28')]){delete _0x3d6658[_0x66b6('0x28')];}_0x40e20d[_0x66b6('0x19')](_0x40ffba)[_0x66b6('0x29')](_0x3d6658);};}exports[_0x66b6('0x2a')]=function(_0x55961e,_0x277d9d){var _0x556973={},_0x49fdeb={},_0x39a655={'count':0x0,'rows':[]};var _0x461635=_['map'](db[_0x66b6('0x2b')]['rawAttributes'],function(_0x51b866){return{'name':_0x51b866['fieldName'],'type':_0x51b866['type'][_0x66b6('0x2c')]};});_0x49fdeb[_0x66b6('0x2d')]=_[_0x66b6('0x2e')](_0x461635,'name');_0x49fdeb[_0x66b6('0x2f')]=_[_0x66b6('0x30')](_0x55961e['query']);_0x49fdeb[_0x66b6('0x31')]=_[_0x66b6('0x32')](_0x49fdeb[_0x66b6('0x2d')],_0x49fdeb[_0x66b6('0x2f')]);_0x556973[_0x66b6('0x33')]=_[_0x66b6('0x32')](_0x49fdeb['model'],qs[_0x66b6('0x34')](_0x55961e['query'][_0x66b6('0x34')]));_0x556973[_0x66b6('0x33')]=_0x556973[_0x66b6('0x33')][_0x66b6('0x35')]?_0x556973[_0x66b6('0x33')]:_0x49fdeb['model'];if(!_0x55961e[_0x66b6('0x2f')][_0x66b6('0x36')](_0x66b6('0x37'))){_0x556973[_0x66b6('0x1e')]=qs[_0x66b6('0x1e')](_0x55961e[_0x66b6('0x2f')]['limit']);_0x556973[_0x66b6('0x1d')]=qs[_0x66b6('0x1d')](_0x55961e[_0x66b6('0x2f')][_0x66b6('0x1d')]);}_0x556973['order']=qs['sort'](_0x55961e['query'][_0x66b6('0x38')]);_0x556973[_0x66b6('0x39')]=qs[_0x66b6('0x31')](_[_0x66b6('0x3a')](_0x55961e[_0x66b6('0x2f')],_0x49fdeb['filters']),_0x461635);if(_0x55961e['query'][_0x66b6('0x3b')]){_0x556973['where']=_[_0x66b6('0x3c')](_0x556973[_0x66b6('0x39')],{'$or':_[_0x66b6('0x2e')](_0x461635,function(_0x2ce7eb){if(_0x2ce7eb[_0x66b6('0x3d')]!=='VIRTUAL'){var _0x3572c1={};_0x3572c1[_0x2ce7eb[_0x66b6('0x28')]]={'$like':'%'+_0x55961e[_0x66b6('0x2f')][_0x66b6('0x3b')]+'%'};return _0x3572c1;}})});}_0x556973=_[_0x66b6('0x3c')]({},_0x556973,_0x55961e['options']);var _0x339670={'where':_0x556973[_0x66b6('0x39')]};return db[_0x66b6('0x2b')][_0x66b6('0x1c')](_0x339670)['then'](function(_0x299d7c){_0x39a655[_0x66b6('0x1c')]=_0x299d7c;if(_0x55961e[_0x66b6('0x2f')][_0x66b6('0x3e')]){_0x556973['include']=[{'all':!![]}];}return db[_0x66b6('0x2b')][_0x66b6('0x3f')](_0x556973);})[_0x66b6('0x24')](function(_0x2f06e1){_0x39a655[_0x66b6('0x40')]=_0x2f06e1;return _0x39a655;})[_0x66b6('0x24')](respondWithFilteredResult(_0x277d9d,_0x556973))[_0x66b6('0x41')](handleError(_0x277d9d,null));};exports[_0x66b6('0x42')]=function(_0x1b7800,_0x32221e){var _0xef0180={'raw':!![],'where':{'id':_0x1b7800[_0x66b6('0x43')]['id']}},_0x11533a={};_0x11533a[_0x66b6('0x2d')]=_[_0x66b6('0x30')](db[_0x66b6('0x2b')][_0x66b6('0x44')]);_0x11533a[_0x66b6('0x2f')]=_[_0x66b6('0x30')](_0x1b7800['query']);_0x11533a[_0x66b6('0x31')]=_[_0x66b6('0x32')](_0x11533a[_0x66b6('0x2d')],_0x11533a[_0x66b6('0x2f')]);_0xef0180[_0x66b6('0x33')]=_[_0x66b6('0x32')](_0x11533a[_0x66b6('0x2d')],qs[_0x66b6('0x34')](_0x1b7800[_0x66b6('0x2f')][_0x66b6('0x34')]));_0xef0180[_0x66b6('0x33')]=_0xef0180[_0x66b6('0x33')]['length']?_0xef0180['attributes']:_0x11533a['model'];if(_0x1b7800['query'][_0x66b6('0x3e')]){_0xef0180[_0x66b6('0x45')]=[{'all':!![]}];}_0xef0180=_['merge']({},_0xef0180,_0x1b7800[_0x66b6('0x46')]);return db[_0x66b6('0x2b')][_0x66b6('0x47')](_0xef0180)[_0x66b6('0x24')](handleEntityNotFound(_0x32221e,null))['then'](respondWithResult(_0x32221e,null))[_0x66b6('0x41')](handleError(_0x32221e,null));};exports[_0x66b6('0x48')]=function(_0x3b9b1c,_0x3de000){return db[_0x66b6('0x2b')]['create'](_0x3b9b1c['body'],{})['then'](respondWithResult(_0x3de000,0xc9))[_0x66b6('0x41')](handleError(_0x3de000,null));};exports[_0x66b6('0x23')]=function(_0x237021,_0x442828){if(_0x237021[_0x66b6('0x49')]['id']){delete _0x237021[_0x66b6('0x49')]['id'];}return db['VoiceDialReport'][_0x66b6('0x47')]({'where':{'id':_0x237021[_0x66b6('0x43')]['id']}})[_0x66b6('0x24')](handleEntityNotFound(_0x442828,null))[_0x66b6('0x24')](saveUpdates(_0x237021['body'],null))[_0x66b6('0x24')](respondWithResult(_0x442828,null))['catch'](handleError(_0x442828,null));};exports[_0x66b6('0x25')]=function(_0x4f6df8,_0x405f8b){return db['VoiceDialReport'][_0x66b6('0x47')]({'where':{'id':_0x4f6df8[_0x66b6('0x43')]['id']}})['then'](handleEntityNotFound(_0x405f8b,null))[_0x66b6('0x24')](removeEntity(_0x405f8b,null))['catch'](handleError(_0x405f8b,null));};exports[_0x66b6('0x4a')]=function(_0x4752aa,_0x330dea){return db[_0x66b6('0x2b')][_0x66b6('0x4a')]()[_0x66b6('0x24')](respondWithResult(_0x330dea,null))['catch'](handleError(_0x330dea,null));};