2f94d482f414de7e19ce7e8af475c15d379895c5
[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 _0x667f=['zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','squel','crypto','desk.js','ioredis','../../components/auth/service','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','status','json','count','offset','limit','Content-Range','reject','save','destroy','error','stack','name','send','index','map','VoiceDialReport','rawAttributes','fieldName','type','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','then','includeAll','include','findAll','rows','catch','show','params','create','body','update','find','describe','html-pdf','eml-format','rimraf'];(function(_0x1f76ff,_0xd47cbe){var _0x8f87a0=function(_0x54838f){while(--_0x54838f){_0x1f76ff['push'](_0x1f76ff['shift']());}};_0x8f87a0(++_0xd47cbe);}(_0x667f,0x8d));var _0xf667=function(_0x4476f2,_0x3f5c4b){_0x4476f2=_0x4476f2-0x0;var _0x2b7018=_0x667f[_0x4476f2];return _0x2b7018;};'use strict';var pdf=require(_0xf667('0x0'));var emlformat=require(_0xf667('0x1'));var rimraf=require(_0xf667('0x2'));var zipdir=require(_0xf667('0x3'));var jsonpatch=require(_0xf667('0x4'));var rp=require('request-promise');var moment=require(_0xf667('0x5'));var BPromise=require(_0xf667('0x6'));var Mustache=require(_0xf667('0x7'));var util=require(_0xf667('0x8'));var path=require('path');var sox=require(_0xf667('0x9'));var csv=require(_0xf667('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xf667('0xb'));var crypto=require(_0xf667('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf667('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf667('0xe'));var authService=require(_0xf667('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf667('0x10'));var utils=require(_0xf667('0x11'));var config=require(_0xf667('0x12'));var db=require(_0xf667('0x13'))['db'];function respondWithStatusCode(_0x212fea,_0x5415c3){_0x5415c3=_0x5415c3||0xcc;return function(_0x21e78b){if(_0x21e78b){return _0x212fea[_0xf667('0x14')](_0x5415c3);}return _0x212fea['status'](_0x5415c3)[_0xf667('0x15')]();};}function respondWithResult(_0x2fe06f,_0x2440f3){_0x2440f3=_0x2440f3||0xc8;return function(_0x3d2f31){if(_0x3d2f31){return _0x2fe06f[_0xf667('0x16')](_0x2440f3)[_0xf667('0x17')](_0x3d2f31);}};}function respondWithFilteredResult(_0x4fe106,_0x1e741a){return function(_0x7f7511){if(_0x7f7511){var _0x422cfc=_0x7f7511[_0xf667('0x18')],_0x46595c=_0x1e741a[_0xf667('0x19')],_0x11391a=_0x1e741a[_0xf667('0x19')]+_0x1e741a[_0xf667('0x1a')],_0x328140;if(_0x11391a>=_0x422cfc){_0x11391a=_0x422cfc;_0x328140=0xc8;}else{_0x328140=0xce;}_0x4fe106[_0xf667('0x16')](_0x328140);return _0x4fe106['set'](_0xf667('0x1b'),_0x46595c+'-'+_0x11391a+'/'+_0x422cfc)['json'](_0x7f7511);}return null;};}function patchUpdates(_0x3f107b){return function(_0x3b8175){try{jsonpatch['apply'](_0x3b8175,_0x3f107b,!![]);}catch(_0x44d17b){return BPromise[_0xf667('0x1c')](_0x44d17b);}return _0x3b8175[_0xf667('0x1d')]();};}function saveUpdates(_0x309c64,_0x1dab6d){return function(_0x5b3c0b){if(_0x5b3c0b){return _0x5b3c0b['update'](_0x309c64)['then'](function(_0x2d4078){return _0x2d4078;});}return null;};}function removeEntity(_0x3f12e3,_0x4ca424){return function(_0x4fd7fc){if(_0x4fd7fc){return _0x4fd7fc[_0xf667('0x1e')]()['then'](function(){_0x3f12e3['status'](0xcc)[_0xf667('0x15')]();});}};}function handleEntityNotFound(_0x226c1e,_0x41b352){return function(_0x4455f0){if(!_0x4455f0){_0x226c1e[_0xf667('0x14')](0x194);}return _0x4455f0;};}function handleError(_0x155a27,_0x230d7a){_0x230d7a=_0x230d7a||0x1f4;return function(_0x26fc5d){logger[_0xf667('0x1f')](_0x26fc5d[_0xf667('0x20')]);if(_0x26fc5d[_0xf667('0x21')]){delete _0x26fc5d[_0xf667('0x21')];}_0x155a27['status'](_0x230d7a)[_0xf667('0x22')](_0x26fc5d);};}exports[_0xf667('0x23')]=function(_0x40b475,_0x575dbc){var _0x2a865d={},_0x13b8cd={},_0x18a416={'count':0x0,'rows':[]};var _0x146526=_[_0xf667('0x24')](db[_0xf667('0x25')][_0xf667('0x26')],function(_0x49223b){return{'name':_0x49223b[_0xf667('0x27')],'type':_0x49223b[_0xf667('0x28')]['key']};});_0x13b8cd['model']=_[_0xf667('0x24')](_0x146526,'name');_0x13b8cd[_0xf667('0x29')]=_[_0xf667('0x2a')](_0x40b475['query']);_0x13b8cd[_0xf667('0x2b')]=_[_0xf667('0x2c')](_0x13b8cd[_0xf667('0x2d')],_0x13b8cd[_0xf667('0x29')]);_0x2a865d[_0xf667('0x2e')]=_[_0xf667('0x2c')](_0x13b8cd['model'],qs['fields'](_0x40b475['query'][_0xf667('0x2f')]));_0x2a865d[_0xf667('0x2e')]=_0x2a865d[_0xf667('0x2e')][_0xf667('0x30')]?_0x2a865d[_0xf667('0x2e')]:_0x13b8cd[_0xf667('0x2d')];if(!_0x40b475[_0xf667('0x29')][_0xf667('0x31')](_0xf667('0x32'))){_0x2a865d['limit']=qs['limit'](_0x40b475[_0xf667('0x29')]['limit']);_0x2a865d[_0xf667('0x19')]=qs[_0xf667('0x19')](_0x40b475[_0xf667('0x29')][_0xf667('0x19')]);}_0x2a865d[_0xf667('0x33')]=qs['sort'](_0x40b475[_0xf667('0x29')][_0xf667('0x34')]);_0x2a865d[_0xf667('0x35')]=qs[_0xf667('0x2b')](_[_0xf667('0x36')](_0x40b475[_0xf667('0x29')],_0x13b8cd[_0xf667('0x2b')]));if(_0x40b475[_0xf667('0x29')][_0xf667('0x37')]){_0x2a865d[_0xf667('0x35')]=_[_0xf667('0x38')](_0x2a865d[_0xf667('0x35')],{'$or':_[_0xf667('0x24')](_0x146526,function(_0x44a11f){if(_0x44a11f[_0xf667('0x28')]!==_0xf667('0x39')){var _0x41dfbb={};_0x41dfbb[_0x44a11f['name']]={'$like':'%'+_0x40b475[_0xf667('0x29')][_0xf667('0x37')]+'%'};return _0x41dfbb;}})});}_0x2a865d=_[_0xf667('0x38')]({},_0x2a865d,_0x40b475[_0xf667('0x3a')]);var _0x1e9896={'where':_0x2a865d[_0xf667('0x35')]};return db[_0xf667('0x25')]['count'](_0x1e9896)[_0xf667('0x3b')](function(_0x2b71f7){_0x18a416['count']=_0x2b71f7;if(_0x40b475[_0xf667('0x29')][_0xf667('0x3c')]){_0x2a865d[_0xf667('0x3d')]=[{'all':!![]}];}return db[_0xf667('0x25')][_0xf667('0x3e')](_0x2a865d);})[_0xf667('0x3b')](function(_0x6cbe02){_0x18a416[_0xf667('0x3f')]=_0x6cbe02;return _0x18a416;})[_0xf667('0x3b')](respondWithFilteredResult(_0x575dbc,_0x2a865d))[_0xf667('0x40')](handleError(_0x575dbc,null));};exports[_0xf667('0x41')]=function(_0x3f1ca9,_0xeec665){var _0x3c6433={'raw':!![],'where':{'id':_0x3f1ca9[_0xf667('0x42')]['id']}},_0x113c1e={};_0x113c1e[_0xf667('0x2d')]=_['keys'](db[_0xf667('0x25')]['rawAttributes']);_0x113c1e[_0xf667('0x29')]=_[_0xf667('0x2a')](_0x3f1ca9[_0xf667('0x29')]);_0x113c1e[_0xf667('0x2b')]=_[_0xf667('0x2c')](_0x113c1e[_0xf667('0x2d')],_0x113c1e[_0xf667('0x29')]);_0x3c6433[_0xf667('0x2e')]=_['intersection'](_0x113c1e[_0xf667('0x2d')],qs[_0xf667('0x2f')](_0x3f1ca9['query'][_0xf667('0x2f')]));_0x3c6433['attributes']=_0x3c6433['attributes'][_0xf667('0x30')]?_0x3c6433[_0xf667('0x2e')]:_0x113c1e[_0xf667('0x2d')];if(_0x3f1ca9[_0xf667('0x29')][_0xf667('0x3c')]){_0x3c6433['include']=[{'all':!![]}];}_0x3c6433=_[_0xf667('0x38')]({},_0x3c6433,_0x3f1ca9[_0xf667('0x3a')]);return db[_0xf667('0x25')]['find'](_0x3c6433)[_0xf667('0x3b')](handleEntityNotFound(_0xeec665,null))[_0xf667('0x3b')](respondWithResult(_0xeec665,null))[_0xf667('0x40')](handleError(_0xeec665,null));};exports['create']=function(_0x47bb39,_0x1a5ec2){return db['VoiceDialReport'][_0xf667('0x43')](_0x47bb39[_0xf667('0x44')],{})[_0xf667('0x3b')](respondWithResult(_0x1a5ec2,0xc9))[_0xf667('0x40')](handleError(_0x1a5ec2,null));};exports[_0xf667('0x45')]=function(_0x1c3707,_0x4174f9){if(_0x1c3707[_0xf667('0x44')]['id']){delete _0x1c3707[_0xf667('0x44')]['id'];}return db['VoiceDialReport'][_0xf667('0x46')]({'where':{'id':_0x1c3707[_0xf667('0x42')]['id']}})[_0xf667('0x3b')](handleEntityNotFound(_0x4174f9,null))[_0xf667('0x3b')](saveUpdates(_0x1c3707['body'],null))[_0xf667('0x3b')](respondWithResult(_0x4174f9,null))[_0xf667('0x40')](handleError(_0x4174f9,null));};exports[_0xf667('0x1e')]=function(_0x958dc3,_0x2e428a){return db[_0xf667('0x25')][_0xf667('0x46')]({'where':{'id':_0x958dc3[_0xf667('0x42')]['id']}})[_0xf667('0x3b')](handleEntityNotFound(_0x2e428a,null))[_0xf667('0x3b')](removeEntity(_0x2e428a,null))[_0xf667('0x40')](handleError(_0x2e428a,null));};exports[_0xf667('0x47')]=function(_0x19f580,_0x39d50a){return db[_0xf667('0x25')]['describe']()[_0xf667('0x3b')](respondWithResult(_0x39d50a,null))[_0xf667('0x40')](handleError(_0x39d50a,null));};