Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / voiceMailMessage / voiceMailMessage.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 _0xf98b=['fast-json-patch','request-promise','bluebird','mustache','path','sox','ejs','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','json','offset','status','set','apply','reject','save','update','then','stack','name','send','index','VoiceMailMessage','rawAttributes','model','keys','query','filters','intersection','attributes','length','nolimit','limit','order','sort','where','map','type','VIRTUAL','merge','options','count','includeAll','include','findAll','rows','catch','show','params','fields','find','create','body','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','attachment','msg_id','.wav\x22','html-pdf','eml-format','rimraf','zip-dir'];(function(_0x3350d7,_0x31e7a6){var _0x3888d5=function(_0x17ff3b){while(--_0x17ff3b){_0x3350d7['push'](_0x3350d7['shift']());}};_0x3888d5(++_0x31e7a6);}(_0xf98b,0xe9));var _0xbf98=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0xf98b[_0x3b380d];return _0x54502b;};'use strict';var pdf=require(_0xbf98('0x0'));var emlformat=require(_0xbf98('0x1'));var rimraf=require(_0xbf98('0x2'));var zipdir=require(_0xbf98('0x3'));var jsonpatch=require(_0xbf98('0x4'));var rp=require(_0xbf98('0x5'));var moment=require('moment');var BPromise=require(_0xbf98('0x6'));var Mustache=require(_0xbf98('0x7'));var util=require('util');var path=require(_0xbf98('0x8'));var sox=require(_0xbf98('0x9'));var csv=require('to-csv');var ejs=require(_0xbf98('0xa'));var fs=require('fs');var _=require(_0xbf98('0xb'));var squel=require(_0xbf98('0xc'));var crypto=require(_0xbf98('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xbf98('0xe'));var toCsv=require(_0xbf98('0xf'));var querystring=require(_0xbf98('0x10'));var Papa=require(_0xbf98('0x11'));var Redis=require(_0xbf98('0x12'));var authService=require(_0xbf98('0x13'));var qs=require(_0xbf98('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbf98('0x15'))(_0xbf98('0x16'));var utils=require(_0xbf98('0x17'));var config=require(_0xbf98('0x18'));var db=require(_0xbf98('0x19'))['db'];function respondWithStatusCode(_0x2c302f,_0xf063de){_0xf063de=_0xf063de||0xcc;return function(_0x4a10b4){if(_0x4a10b4){return _0x2c302f[_0xbf98('0x1a')](_0xf063de);}return _0x2c302f['status'](_0xf063de)[_0xbf98('0x1b')]();};}function respondWithResult(_0x1ae8b8,_0x28f006){_0x28f006=_0x28f006||0xc8;return function(_0x21a30e){if(_0x21a30e){return _0x1ae8b8['status'](_0x28f006)[_0xbf98('0x1c')](_0x21a30e);}};}function respondWithFilteredResult(_0x50113e,_0xe8d92d){return function(_0x39657d){if(_0x39657d){var _0x32add4=_0x39657d['count'],_0x9756f6=_0xe8d92d['offset'],_0x3ee122=_0xe8d92d[_0xbf98('0x1d')]+_0xe8d92d['limit'],_0x186dec;if(_0x3ee122>=_0x32add4){_0x3ee122=_0x32add4;_0x186dec=0xc8;}else{_0x186dec=0xce;}_0x50113e[_0xbf98('0x1e')](_0x186dec);return _0x50113e[_0xbf98('0x1f')]('Content-Range',_0x9756f6+'-'+_0x3ee122+'/'+_0x32add4)[_0xbf98('0x1c')](_0x39657d);}return null;};}function patchUpdates(_0x8228ce){return function(_0x205394){try{jsonpatch[_0xbf98('0x20')](_0x205394,_0x8228ce,!![]);}catch(_0x2b2e14){return BPromise[_0xbf98('0x21')](_0x2b2e14);}return _0x205394[_0xbf98('0x22')]();};}function saveUpdates(_0x2e18d0,_0x1757af){return function(_0x28623a){if(_0x28623a){return _0x28623a[_0xbf98('0x23')](_0x2e18d0)[_0xbf98('0x24')](function(_0x43e9db){return _0x43e9db;});}return null;};}function removeEntity(_0x303eec,_0x24aeec){return function(_0x49e317){if(_0x49e317){return _0x49e317['destroy']()[_0xbf98('0x24')](function(){_0x303eec[_0xbf98('0x1e')](0xcc)[_0xbf98('0x1b')]();});}};}function handleEntityNotFound(_0x2fe4f1,_0x59f1dc){return function(_0x1876aa){if(!_0x1876aa){_0x2fe4f1[_0xbf98('0x1a')](0x194);}return _0x1876aa;};}function handleError(_0x5def02,_0x403047){_0x403047=_0x403047||0x1f4;return function(_0x259aed){logger['error'](_0x259aed[_0xbf98('0x25')]);if(_0x259aed[_0xbf98('0x26')]){delete _0x259aed[_0xbf98('0x26')];}_0x5def02[_0xbf98('0x1e')](_0x403047)[_0xbf98('0x27')](_0x259aed);};}exports[_0xbf98('0x28')]=function(_0x38d81d,_0x38dacc){var _0x28d77a={},_0x347c62={},_0x5947b3={'count':0x0,'rows':[]};var _0x22675e=db[_0xbf98('0x29')][_0xbf98('0x2a')];_0x347c62[_0xbf98('0x2b')]=_['differenceBy'](_[_0xbf98('0x2c')](_0x22675e),[_0xbf98('0x26')]);_0x347c62['query']=_[_0xbf98('0x2c')](_0x38d81d[_0xbf98('0x2d')]);_0x347c62[_0xbf98('0x2e')]=_[_0xbf98('0x2f')](_0x347c62[_0xbf98('0x2b')],_0x347c62[_0xbf98('0x2d')]);_0x28d77a['attributes']=_[_0xbf98('0x2f')](_0x347c62[_0xbf98('0x2b')],qs['fields'](_0x38d81d[_0xbf98('0x2d')]['fields']));_0x28d77a[_0xbf98('0x30')]=_0x28d77a['attributes'][_0xbf98('0x31')]?_0x28d77a['attributes']:_0x347c62[_0xbf98('0x2b')];if(!_0x38d81d[_0xbf98('0x2d')]['hasOwnProperty'](_0xbf98('0x32'))){_0x28d77a['limit']=qs[_0xbf98('0x33')](_0x38d81d['query'][_0xbf98('0x33')]);_0x28d77a[_0xbf98('0x1d')]=qs['offset'](_0x38d81d['query'][_0xbf98('0x1d')]);}_0x28d77a[_0xbf98('0x34')]=qs[_0xbf98('0x35')](_0x38d81d['query']['sort']);_0x28d77a[_0xbf98('0x36')]=qs['filters'](_['pick'](_0x38d81d[_0xbf98('0x2d')],_0x347c62[_0xbf98('0x2e')]));if(_0x38d81d[_0xbf98('0x2d')]['filter']){_0x28d77a[_0xbf98('0x36')]=_['merge'](_0x28d77a['where'],{'$or':_[_0xbf98('0x37')](_0x22675e,function(_0x2cfd54){if(_0x2cfd54[_0xbf98('0x38')]['key']!==_0xbf98('0x39')){var _0x59e347={};_0x59e347[_0x2cfd54['field']]={'$like':'%'+_0x38d81d[_0xbf98('0x2d')]['filter']+'%'};return _0x59e347;}})});}_0x28d77a=_[_0xbf98('0x3a')]({},_0x28d77a,_0x38d81d[_0xbf98('0x3b')]);var _0x4d85e9={'where':_0x28d77a[_0xbf98('0x36')]};return db['VoiceMailMessage'][_0xbf98('0x3c')](_0x4d85e9)[_0xbf98('0x24')](function(_0x24d2e2){_0x5947b3[_0xbf98('0x3c')]=_0x24d2e2;if(_0x38d81d[_0xbf98('0x2d')][_0xbf98('0x3d')]){_0x28d77a[_0xbf98('0x3e')]=[{'all':!![]}];}return db[_0xbf98('0x29')][_0xbf98('0x3f')](_0x28d77a);})[_0xbf98('0x24')](function(_0x1c6e9a){_0x5947b3[_0xbf98('0x40')]=_0x1c6e9a;return _0x5947b3;})['then'](respondWithFilteredResult(_0x38dacc,_0x28d77a))[_0xbf98('0x41')](handleError(_0x38dacc,null));};exports[_0xbf98('0x42')]=function(_0x40948d,_0x8d9e30){var _0x1844f3={'raw':!![],'where':{'id':_0x40948d[_0xbf98('0x43')]['id']}},_0xf8e3d9={};_0xf8e3d9['model']=_['keys'](db['VoiceMailMessage'][_0xbf98('0x2a')]);_0xf8e3d9[_0xbf98('0x2d')]=_[_0xbf98('0x2c')](_0x40948d[_0xbf98('0x2d')]);_0xf8e3d9['filters']=_[_0xbf98('0x2f')](_0xf8e3d9[_0xbf98('0x2b')],_0xf8e3d9[_0xbf98('0x2d')]);_0x1844f3['attributes']=_['intersection'](_0xf8e3d9[_0xbf98('0x2b')],qs[_0xbf98('0x44')](_0x40948d[_0xbf98('0x2d')]['fields']));_0x1844f3['attributes']=_0x1844f3[_0xbf98('0x30')][_0xbf98('0x31')]?_0x1844f3[_0xbf98('0x30')]:_0xf8e3d9[_0xbf98('0x2b')];if(_0x40948d[_0xbf98('0x2d')][_0xbf98('0x3d')]){_0x1844f3['include']=[{'all':!![]}];}_0x1844f3=_[_0xbf98('0x3a')]({},_0x1844f3,_0x40948d[_0xbf98('0x3b')]);return db['VoiceMailMessage'][_0xbf98('0x45')](_0x1844f3)['then'](handleEntityNotFound(_0x8d9e30,null))[_0xbf98('0x24')](respondWithResult(_0x8d9e30,null))[_0xbf98('0x41')](handleError(_0x8d9e30,null));};exports[_0xbf98('0x46')]=function(_0x52a450,_0x158b4c){return db[_0xbf98('0x29')][_0xbf98('0x46')](_0x52a450['body'],{})[_0xbf98('0x24')](respondWithResult(_0x158b4c,0xc9))[_0xbf98('0x41')](handleError(_0x158b4c,null));};exports[_0xbf98('0x23')]=function(_0x24ce1f,_0xdad300){if(_0x24ce1f[_0xbf98('0x47')]['id']){delete _0x24ce1f[_0xbf98('0x47')]['id'];}return db['VoiceMailMessage']['find']({'where':{'id':_0x24ce1f[_0xbf98('0x43')]['id']}})['then'](handleEntityNotFound(_0xdad300,null))[_0xbf98('0x24')](saveUpdates(_0x24ce1f[_0xbf98('0x47')],null))[_0xbf98('0x24')](respondWithResult(_0xdad300,null))['catch'](handleError(_0xdad300,null));};exports['destroy']=function(_0x41686a,_0x4d72ba){return db[_0xbf98('0x29')][_0xbf98('0x45')]({'where':{'id':_0x41686a[_0xbf98('0x43')]['id']}})[_0xbf98('0x24')](handleEntityNotFound(_0x4d72ba,null))[_0xbf98('0x24')](removeEntity(_0x4d72ba,null))['catch'](handleError(_0x4d72ba,null));};exports['download']=function(_0x5cce15,_0x1ce90b,_0x1adb13){return db[_0xbf98('0x29')][_0xbf98('0x45')]({'where':{'id':_0x5cce15[_0xbf98('0x43')]['id']},'attributes':['id',_0xbf98('0x48'),'msg_id']})[_0xbf98('0x24')](handleEntityNotFound(_0x1ce90b,null))[_0xbf98('0x24')](function(_0x315e03){if(_0x315e03){if(!_0x315e03['recording']){throw new db[(_0xbf98('0x49'))][(_0xbf98('0x4a'))](_0xbf98('0x4b'));}var _0x4e1df2={'Content-Type':'audio/wav','Content-Disposition':_0xbf98('0x4c')};if(_0x315e03[_0xbf98('0x4d')]){_0x4e1df2['Content-Disposition']='attachment;\x20filename=\x22'+_0x315e03['msg_id']+_0xbf98('0x4e');}_0x1ce90b[_0xbf98('0x1f')](_0x4e1df2);return _0x1ce90b['send'](new Buffer(_0x315e03[_0xbf98('0x48')]));}})[_0xbf98('0x41')](handleError(_0x1ce90b,null));};