Built motion from commit b0a9a629.|2.6.33
[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 _0xa5f5=['ValidationError','audio/wav','attachment','.wav\x22','recording','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','fs-extra','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','undefined','limit','offset','set','apply','reject','save','update','then','error','stack','name','send','map','VoiceMailMessage','rawAttributes','fieldName','key','model','query','keys','intersection','fields','attributes','nolimit','order','sort','where','filters','merge','type','VIRTUAL','filter','options','count','includeAll','include','findAll','catch','show','length','find','create','body','params','download','msg_id'];(function(_0x57d7e8,_0x3ca452){var _0x3fed0d=function(_0x2d6d90){while(--_0x2d6d90){_0x57d7e8['push'](_0x57d7e8['shift']());}};_0x3fed0d(++_0x3ca452);}(_0xa5f5,0x1d9));var _0x5a5f=function(_0x2642cb,_0x4b917f){_0x2642cb=_0x2642cb-0x0;var _0xe6e41=_0xa5f5[_0x2642cb];return _0xe6e41;};'use strict';var emlformat=require(_0x5a5f('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x5a5f('0x1'));var jsonpatch=require(_0x5a5f('0x2'));var rp=require(_0x5a5f('0x3'));var moment=require(_0x5a5f('0x4'));var BPromise=require(_0x5a5f('0x5'));var Mustache=require('mustache');var util=require(_0x5a5f('0x6'));var path=require(_0x5a5f('0x7'));var sox=require(_0x5a5f('0x8'));var csv=require(_0x5a5f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5a5f('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x5a5f('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x5a5f('0xc'));var authService=require(_0x5a5f('0xd'));var qs=require(_0x5a5f('0xe'));var as=require(_0x5a5f('0xf'));var hardwareService=require(_0x5a5f('0x10'));var logger=require(_0x5a5f('0x11'))(_0x5a5f('0x12'));var utils=require(_0x5a5f('0x13'));var config=require(_0x5a5f('0x14'));var licenseUtil=require(_0x5a5f('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x71bfc8,_0x1f5b4a){_0x1f5b4a=_0x1f5b4a||0xcc;return function(_0xd2ddb5){if(_0xd2ddb5){return _0x71bfc8[_0x5a5f('0x16')](_0x1f5b4a);}return _0x71bfc8[_0x5a5f('0x17')](_0x1f5b4a)[_0x5a5f('0x18')]();};}function respondWithResult(_0x1a012e,_0x20ddbf){_0x20ddbf=_0x20ddbf||0xc8;return function(_0x5d63aa){if(_0x5d63aa){return _0x1a012e[_0x5a5f('0x17')](_0x20ddbf)[_0x5a5f('0x19')](_0x5d63aa);}};}function respondWithFilteredResult(_0x3a346f,_0x2cc0b2){return function(_0x5161fe){if(_0x5161fe){var _0x767f12=typeof _0x2cc0b2['offset']===_0x5a5f('0x1a')&&typeof _0x2cc0b2[_0x5a5f('0x1b')]===_0x5a5f('0x1a');var _0x4d33d0=_0x5161fe['count'];var _0x5de8a6=_0x767f12?0x0:_0x2cc0b2[_0x5a5f('0x1c')];var _0x3315dc=_0x767f12?_0x5161fe['count']:_0x2cc0b2[_0x5a5f('0x1c')]+_0x2cc0b2[_0x5a5f('0x1b')];var _0x15f05b;if(_0x3315dc>=_0x4d33d0){_0x3315dc=_0x4d33d0;_0x15f05b=0xc8;}else{_0x15f05b=0xce;}_0x3a346f[_0x5a5f('0x17')](_0x15f05b);return _0x3a346f[_0x5a5f('0x1d')]('Content-Range',_0x5de8a6+'-'+_0x3315dc+'/'+_0x4d33d0)[_0x5a5f('0x19')](_0x5161fe);}return null;};}function patchUpdates(_0x41f230){return function(_0x49cf42){try{jsonpatch[_0x5a5f('0x1e')](_0x49cf42,_0x41f230,!![]);}catch(_0x27b122){return BPromise[_0x5a5f('0x1f')](_0x27b122);}return _0x49cf42[_0x5a5f('0x20')]();};}function saveUpdates(_0x3e76f6,_0x3c0c39){return function(_0x2199a2){if(_0x2199a2){return _0x2199a2[_0x5a5f('0x21')](_0x3e76f6)[_0x5a5f('0x22')](function(_0x51672b){return _0x51672b;});}return null;};}function removeEntity(_0x45454f,_0x87e9a6){return function(_0x5d6749){if(_0x5d6749){return _0x5d6749['destroy']()['then'](function(){_0x45454f[_0x5a5f('0x17')](0xcc)[_0x5a5f('0x18')]();});}};}function handleEntityNotFound(_0x40b439,_0x5c6029){return function(_0x30e099){if(!_0x30e099){_0x40b439[_0x5a5f('0x16')](0x194);}return _0x30e099;};}function handleError(_0x326550,_0x36bcfd){_0x36bcfd=_0x36bcfd||0x1f4;return function(_0x2ea3c5){logger[_0x5a5f('0x23')](_0x2ea3c5[_0x5a5f('0x24')]);if(_0x2ea3c5['name']){delete _0x2ea3c5[_0x5a5f('0x25')];}_0x326550[_0x5a5f('0x17')](_0x36bcfd)[_0x5a5f('0x26')](_0x2ea3c5);};}exports['index']=function(_0x322ec3,_0x5b2a4b){var _0x46eabc={},_0x5243ba={},_0x32ba59={'count':0x0,'rows':[]};var _0x3f3b77=_[_0x5a5f('0x27')](db[_0x5a5f('0x28')][_0x5a5f('0x29')],function(_0x5b3304){return{'name':_0x5b3304[_0x5a5f('0x2a')],'type':_0x5b3304['type'][_0x5a5f('0x2b')]};});_0x5243ba[_0x5a5f('0x2c')]=_['differenceBy'](_[_0x5a5f('0x27')](_0x3f3b77,_0x5a5f('0x25')),[_0x5a5f('0x25')]);_0x5243ba[_0x5a5f('0x2d')]=_[_0x5a5f('0x2e')](_0x322ec3[_0x5a5f('0x2d')]);_0x5243ba['filters']=_[_0x5a5f('0x2f')](_0x5243ba[_0x5a5f('0x2c')],_0x5243ba[_0x5a5f('0x2d')]);_0x46eabc['attributes']=_['intersection'](_0x5243ba[_0x5a5f('0x2c')],qs[_0x5a5f('0x30')](_0x322ec3[_0x5a5f('0x2d')][_0x5a5f('0x30')]));_0x46eabc[_0x5a5f('0x31')]=_0x46eabc['attributes']['length']?_0x46eabc['attributes']:_0x5243ba[_0x5a5f('0x2c')];if(!_0x322ec3[_0x5a5f('0x2d')]['hasOwnProperty'](_0x5a5f('0x32'))){_0x46eabc[_0x5a5f('0x1b')]=qs[_0x5a5f('0x1b')](_0x322ec3[_0x5a5f('0x2d')][_0x5a5f('0x1b')]);_0x46eabc[_0x5a5f('0x1c')]=qs[_0x5a5f('0x1c')](_0x322ec3[_0x5a5f('0x2d')][_0x5a5f('0x1c')]);}_0x46eabc[_0x5a5f('0x33')]=qs[_0x5a5f('0x34')](_0x322ec3[_0x5a5f('0x2d')][_0x5a5f('0x34')]);_0x46eabc[_0x5a5f('0x35')]=qs['filters'](_['pick'](_0x322ec3[_0x5a5f('0x2d')],_0x5243ba[_0x5a5f('0x36')]),_0x3f3b77);if(_0x322ec3[_0x5a5f('0x2d')]['filter']){_0x46eabc[_0x5a5f('0x35')]=_[_0x5a5f('0x37')](_0x46eabc['where'],{'$or':_[_0x5a5f('0x27')](_0x3f3b77,function(_0x2920e4){if(_0x2920e4[_0x5a5f('0x38')]!==_0x5a5f('0x39')){var _0x31b098={};_0x31b098[_0x2920e4['name']]={'$like':'%'+_0x322ec3['query'][_0x5a5f('0x3a')]+'%'};return _0x31b098;}})});}_0x46eabc=_[_0x5a5f('0x37')]({},_0x46eabc,_0x322ec3[_0x5a5f('0x3b')]);var _0x1c5330={'where':_0x46eabc['where']};return db[_0x5a5f('0x28')][_0x5a5f('0x3c')](_0x1c5330)[_0x5a5f('0x22')](function(_0x385cb8){_0x32ba59['count']=_0x385cb8;if(_0x322ec3['query'][_0x5a5f('0x3d')]){_0x46eabc[_0x5a5f('0x3e')]=[{'all':!![]}];}return db[_0x5a5f('0x28')][_0x5a5f('0x3f')](_0x46eabc);})[_0x5a5f('0x22')](function(_0x20afdb){_0x32ba59['rows']=_0x20afdb;return _0x32ba59;})[_0x5a5f('0x22')](respondWithFilteredResult(_0x5b2a4b,_0x46eabc))[_0x5a5f('0x40')](handleError(_0x5b2a4b,null));};exports[_0x5a5f('0x41')]=function(_0xf9eb07,_0x5a6313){var _0x5b351e={'raw':!![],'where':{'id':_0xf9eb07['params']['id']}},_0x5cb1f1={};_0x5cb1f1[_0x5a5f('0x2c')]=_['keys'](db[_0x5a5f('0x28')][_0x5a5f('0x29')]);_0x5cb1f1['query']=_[_0x5a5f('0x2e')](_0xf9eb07[_0x5a5f('0x2d')]);_0x5cb1f1[_0x5a5f('0x36')]=_[_0x5a5f('0x2f')](_0x5cb1f1['model'],_0x5cb1f1[_0x5a5f('0x2d')]);_0x5b351e[_0x5a5f('0x31')]=_['intersection'](_0x5cb1f1['model'],qs[_0x5a5f('0x30')](_0xf9eb07['query'][_0x5a5f('0x30')]));_0x5b351e[_0x5a5f('0x31')]=_0x5b351e[_0x5a5f('0x31')][_0x5a5f('0x42')]?_0x5b351e[_0x5a5f('0x31')]:_0x5cb1f1[_0x5a5f('0x2c')];if(_0xf9eb07[_0x5a5f('0x2d')][_0x5a5f('0x3d')]){_0x5b351e[_0x5a5f('0x3e')]=[{'all':!![]}];}_0x5b351e=_[_0x5a5f('0x37')]({},_0x5b351e,_0xf9eb07['options']);return db[_0x5a5f('0x28')][_0x5a5f('0x43')](_0x5b351e)[_0x5a5f('0x22')](handleEntityNotFound(_0x5a6313,null))[_0x5a5f('0x22')](respondWithResult(_0x5a6313,null))[_0x5a5f('0x40')](handleError(_0x5a6313,null));};exports['create']=function(_0x47a41d,_0x4b49ba){return db[_0x5a5f('0x28')][_0x5a5f('0x44')](_0x47a41d[_0x5a5f('0x45')],{})[_0x5a5f('0x22')](respondWithResult(_0x4b49ba,0xc9))[_0x5a5f('0x40')](handleError(_0x4b49ba,null));};exports[_0x5a5f('0x21')]=function(_0xb75a91,_0x1578b0){if(_0xb75a91[_0x5a5f('0x45')]['id']){delete _0xb75a91[_0x5a5f('0x45')]['id'];}return db['VoiceMailMessage'][_0x5a5f('0x43')]({'where':{'id':_0xb75a91[_0x5a5f('0x46')]['id']}})[_0x5a5f('0x22')](handleEntityNotFound(_0x1578b0,null))[_0x5a5f('0x22')](saveUpdates(_0xb75a91[_0x5a5f('0x45')],null))['then'](respondWithResult(_0x1578b0,null))[_0x5a5f('0x40')](handleError(_0x1578b0,null));};exports['destroy']=function(_0x443af3,_0x810c23){return db[_0x5a5f('0x28')][_0x5a5f('0x43')]({'where':{'id':_0x443af3[_0x5a5f('0x46')]['id']}})[_0x5a5f('0x22')](handleEntityNotFound(_0x810c23,null))[_0x5a5f('0x22')](removeEntity(_0x810c23,null))[_0x5a5f('0x40')](handleError(_0x810c23,null));};exports[_0x5a5f('0x47')]=function(_0x403114,_0xae6c05,_0xcd78b2){return db['VoiceMailMessage']['find']({'where':{'id':_0x403114['params']['id']},'attributes':['id','recording',_0x5a5f('0x48')]})[_0x5a5f('0x22')](handleEntityNotFound(_0xae6c05,null))['then'](function(_0x58fd7d){if(_0x58fd7d){if(!_0x58fd7d['recording']){throw new db['Sequelize'][(_0x5a5f('0x49'))]('VoiceMailMessage\x20not\x20found');}var _0x456a47={'Content-Type':_0x5a5f('0x4a'),'Content-Disposition':_0x5a5f('0x4b')};if(_0x58fd7d['msg_id']){_0x456a47['Content-Disposition']='attachment;\x20filename=\x22'+_0x58fd7d[_0x5a5f('0x48')]+_0x5a5f('0x4c');}_0xae6c05[_0x5a5f('0x1d')](_0x456a47);return _0xae6c05['send'](new Buffer(_0x58fd7d[_0x5a5f('0x4d')]));}})[_0x5a5f('0x40')](handleError(_0xae6c05,null));};