Built motion from commit (unavailable).|2.5.6
[motion2.git] / server / api / voiceMail / voiceMail.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 _0x23db=['Content-Range','apply','reject','save','then','destroy','get','Voicemails','UserProfileResource','end','stack','name','send','index','map','fieldName','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','type','VIRTUAL','options','VoiceMail','include','findAll','rows','catch','rawAttributes','length','includeAll','merge','create','body','role','user','find','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','findOne','VoiceMailMessage','mailbox','findAndCountAll','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','set'];(function(_0x332632,_0xf7ad49){var _0x199ffb=function(_0x3e3357){while(--_0x3e3357){_0x332632['push'](_0x332632['shift']());}};_0x199ffb(++_0xf7ad49);}(_0x23db,0x141));var _0xb23d=function(_0x13b8f3,_0x442821){_0x13b8f3=_0x13b8f3-0x0;var _0x1a6d06=_0x23db[_0x13b8f3];return _0x1a6d06;};'use strict';var pdf=require(_0xb23d('0x0'));var emlformat=require(_0xb23d('0x1'));var rimraf=require(_0xb23d('0x2'));var zipdir=require(_0xb23d('0x3'));var jsonpatch=require(_0xb23d('0x4'));var rp=require(_0xb23d('0x5'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xb23d('0x6'));var util=require(_0xb23d('0x7'));var path=require('path');var sox=require(_0xb23d('0x8'));var csv=require(_0xb23d('0x9'));var ejs=require(_0xb23d('0xa'));var fs=require('fs');var _=require(_0xb23d('0xb'));var squel=require(_0xb23d('0xc'));var crypto=require(_0xb23d('0xd'));var jsforce=require(_0xb23d('0xe'));var deskjs=require(_0xb23d('0xf'));var toCsv=require(_0xb23d('0x9'));var querystring=require('querystring');var Papa=require(_0xb23d('0x10'));var Redis=require(_0xb23d('0x11'));var authService=require(_0xb23d('0x12'));var qs=require(_0xb23d('0x13'));var as=require(_0xb23d('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xb23d('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xb23d('0x16'));var db=require(_0xb23d('0x17'))['db'];function respondWithStatusCode(_0x191c69,_0x4112b5){_0x4112b5=_0x4112b5||0xcc;return function(_0x13e918){if(_0x13e918){return _0x191c69[_0xb23d('0x18')](_0x4112b5);}return _0x191c69[_0xb23d('0x19')](_0x4112b5)['end']();};}function respondWithResult(_0x627cc1,_0x2da615){_0x2da615=_0x2da615||0xc8;return function(_0x2fa37a){if(_0x2fa37a){return _0x627cc1[_0xb23d('0x19')](_0x2da615)[_0xb23d('0x1a')](_0x2fa37a);}};}function respondWithFilteredResult(_0x2f18b2,_0x57f725){return function(_0x5a8364){if(_0x5a8364){var _0x2fba80=_0x5a8364[_0xb23d('0x1b')],_0x45f0d1=_0x57f725[_0xb23d('0x1c')],_0x1b35d7=_0x57f725['offset']+_0x57f725[_0xb23d('0x1d')],_0x9e5eb3;if(_0x1b35d7>=_0x2fba80){_0x1b35d7=_0x2fba80;_0x9e5eb3=0xc8;}else{_0x9e5eb3=0xce;}_0x2f18b2[_0xb23d('0x19')](_0x9e5eb3);return _0x2f18b2[_0xb23d('0x1e')](_0xb23d('0x1f'),_0x45f0d1+'-'+_0x1b35d7+'/'+_0x2fba80)['json'](_0x5a8364);}return null;};}function patchUpdates(_0x237442){return function(_0x5baf53){try{jsonpatch[_0xb23d('0x20')](_0x5baf53,_0x237442,!![]);}catch(_0x2cb813){return BPromise[_0xb23d('0x21')](_0x2cb813);}return _0x5baf53[_0xb23d('0x22')]();};}function saveUpdates(_0x3cb3ee,_0x45d7b5){return function(_0x331838){if(_0x331838){return _0x331838['update'](_0x3cb3ee)[_0xb23d('0x23')](function(_0x52e94d){return _0x52e94d;});}return null;};}function removeEntity(_0x5e8ff8,_0x20329a){return function(_0x29cacf){if(_0x29cacf){return _0x29cacf[_0xb23d('0x24')]()[_0xb23d('0x23')](function(){var _0x9348e1=_0x29cacf[_0xb23d('0x25')]({'plain':!![]});var _0x921fc=_0xb23d('0x26');return db[_0xb23d('0x27')][_0xb23d('0x24')]({'where':{'type':_0x921fc,'resourceId':_0x9348e1['id']}})[_0xb23d('0x23')](function(){return _0x29cacf;});})['then'](function(){_0x5e8ff8[_0xb23d('0x19')](0xcc)[_0xb23d('0x28')]();});}};}function handleEntityNotFound(_0x243416,_0x4e1538){return function(_0x4919dc){if(!_0x4919dc){_0x243416[_0xb23d('0x18')](0x194);}return _0x4919dc;};}function handleError(_0x2e758e,_0xba0e97){_0xba0e97=_0xba0e97||0x1f4;return function(_0x33e7bc){logger['error'](_0x33e7bc[_0xb23d('0x29')]);if(_0x33e7bc[_0xb23d('0x2a')]){delete _0x33e7bc[_0xb23d('0x2a')];}_0x2e758e[_0xb23d('0x19')](_0xba0e97)[_0xb23d('0x2b')](_0x33e7bc);};}exports[_0xb23d('0x2c')]=function(_0x26990e,_0x867d69){var _0x2f039f={},_0x349ba6={},_0x2931a2={'count':0x0,'rows':[]};var _0x269e9a=_[_0xb23d('0x2d')](db['VoiceMail']['rawAttributes'],function(_0x536be6){return{'name':_0x536be6[_0xb23d('0x2e')],'type':_0x536be6['type']['key']};});_0x349ba6[_0xb23d('0x2f')]=_['map'](_0x269e9a,_0xb23d('0x2a'));_0x349ba6[_0xb23d('0x30')]=_[_0xb23d('0x31')](_0x26990e[_0xb23d('0x30')]);_0x349ba6[_0xb23d('0x32')]=_[_0xb23d('0x33')](_0x349ba6[_0xb23d('0x2f')],_0x349ba6[_0xb23d('0x30')]);_0x2f039f[_0xb23d('0x34')]=_[_0xb23d('0x33')](_0x349ba6[_0xb23d('0x2f')],qs[_0xb23d('0x35')](_0x26990e[_0xb23d('0x30')][_0xb23d('0x35')]));_0x2f039f[_0xb23d('0x34')]=_0x2f039f[_0xb23d('0x34')]['length']?_0x2f039f[_0xb23d('0x34')]:_0x349ba6[_0xb23d('0x2f')];if(!_0x26990e[_0xb23d('0x30')][_0xb23d('0x36')](_0xb23d('0x37'))){_0x2f039f[_0xb23d('0x1d')]=qs[_0xb23d('0x1d')](_0x26990e[_0xb23d('0x30')]['limit']);_0x2f039f[_0xb23d('0x1c')]=qs[_0xb23d('0x1c')](_0x26990e[_0xb23d('0x30')][_0xb23d('0x1c')]);}_0x2f039f[_0xb23d('0x38')]=qs[_0xb23d('0x39')](_0x26990e[_0xb23d('0x30')][_0xb23d('0x39')]);_0x2f039f[_0xb23d('0x3a')]=qs[_0xb23d('0x32')](_[_0xb23d('0x3b')](_0x26990e[_0xb23d('0x30')],_0x349ba6['filters']),_0x269e9a);if(_0x26990e[_0xb23d('0x30')][_0xb23d('0x3c')]){_0x2f039f[_0xb23d('0x3a')]=_['merge'](_0x2f039f[_0xb23d('0x3a')],{'$or':_[_0xb23d('0x2d')](_0x269e9a,function(_0x252721){if(_0x252721[_0xb23d('0x3d')]!==_0xb23d('0x3e')){var _0x3812c3={};_0x3812c3[_0x252721[_0xb23d('0x2a')]]={'$like':'%'+_0x26990e[_0xb23d('0x30')][_0xb23d('0x3c')]+'%'};return _0x3812c3;}})});}_0x2f039f=_['merge']({},_0x2f039f,_0x26990e[_0xb23d('0x3f')]);var _0x188a1c={'where':_0x2f039f[_0xb23d('0x3a')]};return db[_0xb23d('0x40')]['count'](_0x188a1c)[_0xb23d('0x23')](function(_0x55fddd){_0x2931a2['count']=_0x55fddd;if(_0x26990e[_0xb23d('0x30')]['includeAll']){_0x2f039f[_0xb23d('0x41')]=[{'all':!![]}];}return db[_0xb23d('0x40')][_0xb23d('0x42')](_0x2f039f);})[_0xb23d('0x23')](function(_0x510947){_0x2931a2[_0xb23d('0x43')]=_0x510947;return _0x2931a2;})['then'](respondWithFilteredResult(_0x867d69,_0x2f039f))[_0xb23d('0x44')](handleError(_0x867d69,null));};exports['show']=function(_0x1ab20b,_0x53030d){var _0x496ab6={'raw':!![],'where':{'id':_0x1ab20b['params']['id']}},_0x4f60e0={};_0x4f60e0[_0xb23d('0x2f')]=_[_0xb23d('0x31')](db['VoiceMail'][_0xb23d('0x45')]);_0x4f60e0[_0xb23d('0x30')]=_[_0xb23d('0x31')](_0x1ab20b[_0xb23d('0x30')]);_0x4f60e0['filters']=_['intersection'](_0x4f60e0[_0xb23d('0x2f')],_0x4f60e0[_0xb23d('0x30')]);_0x496ab6[_0xb23d('0x34')]=_[_0xb23d('0x33')](_0x4f60e0['model'],qs[_0xb23d('0x35')](_0x1ab20b[_0xb23d('0x30')][_0xb23d('0x35')]));_0x496ab6[_0xb23d('0x34')]=_0x496ab6['attributes'][_0xb23d('0x46')]?_0x496ab6['attributes']:_0x4f60e0[_0xb23d('0x2f')];if(_0x1ab20b[_0xb23d('0x30')][_0xb23d('0x47')]){_0x496ab6['include']=[{'all':!![]}];}_0x496ab6=_[_0xb23d('0x48')]({},_0x496ab6,_0x1ab20b['options']);return db[_0xb23d('0x40')]['find'](_0x496ab6)[_0xb23d('0x23')](handleEntityNotFound(_0x53030d,null))[_0xb23d('0x23')](respondWithResult(_0x53030d,null))[_0xb23d('0x44')](handleError(_0x53030d,null));};exports[_0xb23d('0x49')]=function(_0x217f49,_0x2382b5){return db[_0xb23d('0x40')][_0xb23d('0x49')](_0x217f49[_0xb23d('0x4a')],{})['then'](function(_0x1911ab){var _0x22e818=_0x217f49['user'][_0xb23d('0x25')]({'plain':!![]});if(!_0x22e818)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x22e818[_0xb23d('0x4b')]===_0xb23d('0x4c')){var _0x17b37d=_0x1911ab['get']({'plain':!![]});var _0xc78b28=_0xb23d('0x26');return db['UserProfileSection'][_0xb23d('0x4d')]({'where':{'name':_0xc78b28,'userProfileId':_0x22e818[_0xb23d('0x4e')]},'raw':!![]})[_0xb23d('0x23')](function(_0xbfcf00){if(_0xbfcf00&&_0xbfcf00[_0xb23d('0x4f')]===0x0){return db[_0xb23d('0x27')][_0xb23d('0x49')]({'name':_0x17b37d[_0xb23d('0x2a')],'resourceId':_0x17b37d['id'],'type':_0xbfcf00['name'],'sectionId':_0xbfcf00['id']},{})['then'](function(){return _0x1911ab;});}else{return _0x1911ab;}})[_0xb23d('0x44')](function(_0x4ba49c){logger[_0xb23d('0x50')](_0xb23d('0x51'),_0x4ba49c);throw _0x4ba49c;});}return _0x1911ab;})[_0xb23d('0x23')](respondWithResult(_0x2382b5,0xc9))['catch'](handleError(_0x2382b5,null));};exports[_0xb23d('0x52')]=function(_0x25f467,_0x6b2c92){if(_0x25f467['body']['id']){delete _0x25f467[_0xb23d('0x4a')]['id'];}return db['VoiceMail'][_0xb23d('0x4d')]({'where':{'id':_0x25f467[_0xb23d('0x53')]['id']}})[_0xb23d('0x23')](handleEntityNotFound(_0x6b2c92,null))[_0xb23d('0x23')](saveUpdates(_0x25f467[_0xb23d('0x4a')],null))['then'](respondWithResult(_0x6b2c92,null))[_0xb23d('0x44')](handleError(_0x6b2c92,null));};exports['destroy']=function(_0x26f4a3,_0x357925){return db[_0xb23d('0x40')][_0xb23d('0x4d')]({'where':{'id':_0x26f4a3[_0xb23d('0x53')]['id']}})[_0xb23d('0x23')](handleEntityNotFound(_0x357925,null))['then'](removeEntity(_0x357925,null))['catch'](handleError(_0x357925,null));};exports['getMessages']=function(_0x419160,_0x15aab8,_0x304d21){return db['VoiceMail'][_0xb23d('0x54')]({'where':{'id':_0x419160[_0xb23d('0x53')]['id']}})[_0xb23d('0x23')](handleEntityNotFound(_0x15aab8,null))['then'](function(_0xeac880){var _0x3eda50;var _0x994008={},_0xefd2ee={};_0xefd2ee[_0xb23d('0x2f')]=_['keys'](db[_0xb23d('0x55')][_0xb23d('0x45')]);_0xefd2ee['query']=_[_0xb23d('0x31')](_0x419160[_0xb23d('0x30')]);_0xefd2ee['filters']=_[_0xb23d('0x33')](_0xefd2ee[_0xb23d('0x2f')],_0xefd2ee[_0xb23d('0x30')]);_0x994008[_0xb23d('0x34')]=_[_0xb23d('0x33')](_0xefd2ee[_0xb23d('0x2f')],qs[_0xb23d('0x35')](_0x419160['query'][_0xb23d('0x35')]));_0x994008['attributes']=_0x994008['attributes'][_0xb23d('0x46')]?_0x994008[_0xb23d('0x34')]:_0xefd2ee[_0xb23d('0x2f')];if(!_0x419160[_0xb23d('0x30')][_0xb23d('0x36')](_0xb23d('0x37'))){_0x994008['limit']=qs[_0xb23d('0x1d')](_0x419160[_0xb23d('0x30')][_0xb23d('0x1d')]);_0x994008[_0xb23d('0x1c')]=qs[_0xb23d('0x1c')](_0x419160['query'][_0xb23d('0x1c')]);}_0x994008['order']=qs[_0xb23d('0x39')](_0x419160[_0xb23d('0x30')][_0xb23d('0x39')]);_0x994008['where']=qs[_0xb23d('0x32')](_[_0xb23d('0x3b')](_0x419160['query'],_0xefd2ee[_0xb23d('0x32')]));if(_0x419160[_0xb23d('0x30')][_0xb23d('0x3c')]){_0x994008['where']=_[_0xb23d('0x48')](_0x994008['where'],{'$or':_[_0xb23d('0x2d')](_0x994008[_0xb23d('0x34')],function(_0x45716c){var _0x5a0817={};_0x5a0817[_0x45716c]={'$like':'%'+_0x419160['query'][_0xb23d('0x3c')]+'%'};return _0x5a0817;})});}_0x994008[_0xb23d('0x3a')]=_[_0xb23d('0x48')](_0x994008[_0xb23d('0x3a')],{'mailboxuser':_0xeac880[_0xb23d('0x56')]});_0x994008=_[_0xb23d('0x48')]({},_0x994008,_0x419160['options']);return db[_0xb23d('0x55')][_0xb23d('0x57')](_0x994008)[_0xb23d('0x23')](respondWithFilteredResult(_0x15aab8,_0x994008));})['catch'](handleError(_0x15aab8,null));};