7981ee8e367a30697038cc201b3d8ab1a64f0a9b
[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 _0x758a=['filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','undefined','limit','count','offset','set','reject','update','then','destroy','sendStatus','error','stack','name','send','map','VoiceDialReport','rawAttributes','fieldName','type','key','model','keys','query','intersection','fields','attributes','length','nolimit','order','sort','where','filters','pick'];(function(_0x1e09ef,_0x17e23f){var _0x2d1254=function(_0x5935f1){while(--_0x5935f1){_0x1e09ef['push'](_0x1e09ef['shift']());}};_0x2d1254(++_0x17e23f);}(_0x758a,0x18f));var _0xa758=function(_0x3341fc,_0x193dbb){_0x3341fc=_0x3341fc-0x0;var _0x714789=_0x758a[_0x3341fc];return _0x714789;};'use strict';var emlformat=require(_0xa758('0x0'));var rimraf=require(_0xa758('0x1'));var zipdir=require(_0xa758('0x2'));var jsonpatch=require(_0xa758('0x3'));var rp=require(_0xa758('0x4'));var moment=require(_0xa758('0x5'));var BPromise=require(_0xa758('0x6'));var Mustache=require(_0xa758('0x7'));var util=require(_0xa758('0x8'));var path=require('path');var sox=require(_0xa758('0x9'));var csv=require(_0xa758('0xa'));var ejs=require(_0xa758('0xb'));var fs=require('fs');var fs_extra=require(_0xa758('0xc'));var _=require(_0xa758('0xd'));var squel=require(_0xa758('0xe'));var crypto=require(_0xa758('0xf'));var jsforce=require('jsforce');var deskjs=require(_0xa758('0x10'));var toCsv=require('to-csv');var querystring=require(_0xa758('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xa758('0x12'));var qs=require(_0xa758('0x13'));var as=require(_0xa758('0x14'));var hardwareService=require(_0xa758('0x15'));var logger=require(_0xa758('0x16'))('api');var utils=require(_0xa758('0x17'));var config=require(_0xa758('0x18'));var licenseUtil=require(_0xa758('0x19'));var db=require(_0xa758('0x1a'))['db'];function respondWithStatusCode(_0x270a52,_0x38b69d){_0x38b69d=_0x38b69d||0xcc;return function(_0x1d3a56){if(_0x1d3a56){return _0x270a52['sendStatus'](_0x38b69d);}return _0x270a52['status'](_0x38b69d)[_0xa758('0x1b')]();};}function respondWithResult(_0x403658,_0xd32f3f){_0xd32f3f=_0xd32f3f||0xc8;return function(_0x177865){if(_0x177865){return _0x403658[_0xa758('0x1c')](_0xd32f3f)[_0xa758('0x1d')](_0x177865);}};}function respondWithFilteredResult(_0x44b313,_0x2e9098){return function(_0x3ba46e){if(_0x3ba46e){var _0x570503=typeof _0x2e9098['offset']===_0xa758('0x1e')&&typeof _0x2e9098[_0xa758('0x1f')]===_0xa758('0x1e');var _0x3fff72=_0x3ba46e[_0xa758('0x20')];var _0x333638=_0x570503?0x0:_0x2e9098[_0xa758('0x21')];var _0x221e94=_0x570503?_0x3ba46e['count']:_0x2e9098[_0xa758('0x21')]+_0x2e9098[_0xa758('0x1f')];var _0xe47204;if(_0x221e94>=_0x3fff72){_0x221e94=_0x3fff72;_0xe47204=0xc8;}else{_0xe47204=0xce;}_0x44b313[_0xa758('0x1c')](_0xe47204);return _0x44b313[_0xa758('0x22')]('Content-Range',_0x333638+'-'+_0x221e94+'/'+_0x3fff72)[_0xa758('0x1d')](_0x3ba46e);}return null;};}function patchUpdates(_0x175f95){return function(_0x6b0603){try{jsonpatch['apply'](_0x6b0603,_0x175f95,!![]);}catch(_0x1e7d3c){return BPromise[_0xa758('0x23')](_0x1e7d3c);}return _0x6b0603['save']();};}function saveUpdates(_0x16b734,_0x218c4f){return function(_0x1db661){if(_0x1db661){return _0x1db661[_0xa758('0x24')](_0x16b734)[_0xa758('0x25')](function(_0x43b6d3){return _0x43b6d3;});}return null;};}function removeEntity(_0x593212,_0x186443){return function(_0x3fb511){if(_0x3fb511){return _0x3fb511[_0xa758('0x26')]()[_0xa758('0x25')](function(){_0x593212[_0xa758('0x1c')](0xcc)[_0xa758('0x1b')]();});}};}function handleEntityNotFound(_0x272574,_0x9b75ec){return function(_0x39e16f){if(!_0x39e16f){_0x272574[_0xa758('0x27')](0x194);}return _0x39e16f;};}function handleError(_0x4f510e,_0x16c11b){_0x16c11b=_0x16c11b||0x1f4;return function(_0x5a3723){logger[_0xa758('0x28')](_0x5a3723[_0xa758('0x29')]);if(_0x5a3723['name']){delete _0x5a3723[_0xa758('0x2a')];}_0x4f510e[_0xa758('0x1c')](_0x16c11b)[_0xa758('0x2b')](_0x5a3723);};}exports['index']=function(_0x3c79ca,_0x1d3897){var _0xf5117e={},_0x2fb4e8={},_0x98b85c={'count':0x0,'rows':[]};var _0x532eb4=_[_0xa758('0x2c')](db[_0xa758('0x2d')][_0xa758('0x2e')],function(_0x5572be){return{'name':_0x5572be[_0xa758('0x2f')],'type':_0x5572be[_0xa758('0x30')][_0xa758('0x31')]};});_0x2fb4e8[_0xa758('0x32')]=_[_0xa758('0x2c')](_0x532eb4,_0xa758('0x2a'));_0x2fb4e8['query']=_[_0xa758('0x33')](_0x3c79ca[_0xa758('0x34')]);_0x2fb4e8['filters']=_[_0xa758('0x35')](_0x2fb4e8[_0xa758('0x32')],_0x2fb4e8[_0xa758('0x34')]);_0xf5117e['attributes']=_[_0xa758('0x35')](_0x2fb4e8['model'],qs[_0xa758('0x36')](_0x3c79ca[_0xa758('0x34')][_0xa758('0x36')]));_0xf5117e['attributes']=_0xf5117e[_0xa758('0x37')][_0xa758('0x38')]?_0xf5117e[_0xa758('0x37')]:_0x2fb4e8[_0xa758('0x32')];if(!_0x3c79ca[_0xa758('0x34')]['hasOwnProperty'](_0xa758('0x39'))){_0xf5117e[_0xa758('0x1f')]=qs[_0xa758('0x1f')](_0x3c79ca[_0xa758('0x34')][_0xa758('0x1f')]);_0xf5117e[_0xa758('0x21')]=qs['offset'](_0x3c79ca['query'][_0xa758('0x21')]);}_0xf5117e[_0xa758('0x3a')]=qs['sort'](_0x3c79ca[_0xa758('0x34')][_0xa758('0x3b')]);_0xf5117e[_0xa758('0x3c')]=qs[_0xa758('0x3d')](_[_0xa758('0x3e')](_0x3c79ca[_0xa758('0x34')],_0x2fb4e8[_0xa758('0x3d')]),_0x532eb4);if(_0x3c79ca[_0xa758('0x34')][_0xa758('0x3f')]){_0xf5117e[_0xa758('0x3c')]=_[_0xa758('0x40')](_0xf5117e[_0xa758('0x3c')],{'$or':_[_0xa758('0x2c')](_0x532eb4,function(_0x338df3){if(_0x338df3[_0xa758('0x30')]!==_0xa758('0x41')){var _0x1f0c10={};_0x1f0c10[_0x338df3['name']]={'$like':'%'+_0x3c79ca[_0xa758('0x34')]['filter']+'%'};return _0x1f0c10;}})});}_0xf5117e=_[_0xa758('0x40')]({},_0xf5117e,_0x3c79ca[_0xa758('0x42')]);var _0x56fb8a={'where':_0xf5117e[_0xa758('0x3c')]};return db[_0xa758('0x2d')][_0xa758('0x20')](_0x56fb8a)[_0xa758('0x25')](function(_0x3d60b0){_0x98b85c['count']=_0x3d60b0;if(_0x3c79ca[_0xa758('0x34')][_0xa758('0x43')]){_0xf5117e[_0xa758('0x44')]=[{'all':!![]}];}return db['VoiceDialReport'][_0xa758('0x45')](_0xf5117e);})[_0xa758('0x25')](function(_0x25449d){_0x98b85c['rows']=_0x25449d;return _0x98b85c;})['then'](respondWithFilteredResult(_0x1d3897,_0xf5117e))[_0xa758('0x46')](handleError(_0x1d3897,null));};exports[_0xa758('0x47')]=function(_0x5dc332,_0x56674a){var _0x490540={'raw':!![],'where':{'id':_0x5dc332[_0xa758('0x48')]['id']}},_0x5d23ee={};_0x5d23ee[_0xa758('0x32')]=_['keys'](db['VoiceDialReport'][_0xa758('0x2e')]);_0x5d23ee[_0xa758('0x34')]=_['keys'](_0x5dc332['query']);_0x5d23ee[_0xa758('0x3d')]=_[_0xa758('0x35')](_0x5d23ee['model'],_0x5d23ee[_0xa758('0x34')]);_0x490540[_0xa758('0x37')]=_[_0xa758('0x35')](_0x5d23ee[_0xa758('0x32')],qs[_0xa758('0x36')](_0x5dc332[_0xa758('0x34')][_0xa758('0x36')]));_0x490540['attributes']=_0x490540[_0xa758('0x37')]['length']?_0x490540[_0xa758('0x37')]:_0x5d23ee['model'];if(_0x5dc332[_0xa758('0x34')][_0xa758('0x43')]){_0x490540[_0xa758('0x44')]=[{'all':!![]}];}_0x490540=_[_0xa758('0x40')]({},_0x490540,_0x5dc332[_0xa758('0x42')]);return db[_0xa758('0x2d')][_0xa758('0x49')](_0x490540)[_0xa758('0x25')](handleEntityNotFound(_0x56674a,null))[_0xa758('0x25')](respondWithResult(_0x56674a,null))['catch'](handleError(_0x56674a,null));};exports['create']=function(_0x1f9667,_0x5008db){return db[_0xa758('0x2d')][_0xa758('0x4a')](_0x1f9667[_0xa758('0x4b')],{})[_0xa758('0x25')](respondWithResult(_0x5008db,0xc9))['catch'](handleError(_0x5008db,null));};exports[_0xa758('0x24')]=function(_0x347d3d,_0xa19f60){if(_0x347d3d[_0xa758('0x4b')]['id']){delete _0x347d3d[_0xa758('0x4b')]['id'];}return db[_0xa758('0x2d')][_0xa758('0x49')]({'where':{'id':_0x347d3d['params']['id']}})[_0xa758('0x25')](handleEntityNotFound(_0xa19f60,null))['then'](saveUpdates(_0x347d3d[_0xa758('0x4b')],null))[_0xa758('0x25')](respondWithResult(_0xa19f60,null))[_0xa758('0x46')](handleError(_0xa19f60,null));};exports['destroy']=function(_0x2d9ccc,_0x462065){return db[_0xa758('0x2d')][_0xa758('0x49')]({'where':{'id':_0x2d9ccc[_0xa758('0x48')]['id']}})[_0xa758('0x25')](handleEntityNotFound(_0x462065,null))[_0xa758('0x25')](removeEntity(_0x462065,null))[_0xa758('0x46')](handleError(_0x462065,null));};exports[_0xa758('0x4c')]=function(_0x177d04,_0x40c79e){return db[_0xa758('0x2d')][_0xa758('0x4c')]()[_0xa758('0x25')](respondWithResult(_0x40c79e,null))[_0xa758('0x46')](handleError(_0x40c79e,null));};