Built motion from commit ab870f9e.|2.5.44
[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 _0xb5ef=['json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy','sendStatus','error','stack','send','index','map','VoiceMailMessage','fieldName','type','differenceBy','name','query','keys','filters','intersection','model','fields','attributes','length','hasOwnProperty','order','sort','where','pick','filter','VIRTUAL','merge','options','findAll','rows','show','params','rawAttributes','include','find','catch','create','body','recording','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','attachment','msg_id','attachment;\x20filename=\x22','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','status','end'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0xb5ef,0x18e));var _0xfb5e=function(_0x3a07c4,_0x13ab5e){_0x3a07c4=_0x3a07c4-0x0;var _0x59a7fd=_0xb5ef[_0x3a07c4];return _0x59a7fd;};'use strict';var emlformat=require(_0xfb5e('0x0'));var rimraf=require(_0xfb5e('0x1'));var zipdir=require(_0xfb5e('0x2'));var jsonpatch=require(_0xfb5e('0x3'));var rp=require('request-promise');var moment=require(_0xfb5e('0x4'));var BPromise=require(_0xfb5e('0x5'));var Mustache=require('mustache');var util=require(_0xfb5e('0x6'));var path=require(_0xfb5e('0x7'));var sox=require(_0xfb5e('0x8'));var csv=require('to-csv');var ejs=require(_0xfb5e('0x9'));var fs=require('fs');var fs_extra=require(_0xfb5e('0xa'));var _=require(_0xfb5e('0xb'));var squel=require(_0xfb5e('0xc'));var crypto=require(_0xfb5e('0xd'));var jsforce=require(_0xfb5e('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xfb5e('0xf'));var querystring=require(_0xfb5e('0x10'));var Papa=require('papaparse');var Redis=require(_0xfb5e('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xfb5e('0x12'));var as=require(_0xfb5e('0x13'));var hardwareService=require(_0xfb5e('0x14'));var logger=require(_0xfb5e('0x15'))(_0xfb5e('0x16'));var utils=require(_0xfb5e('0x17'));var config=require(_0xfb5e('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x39f36b,_0x307c52){_0x307c52=_0x307c52||0xcc;return function(_0x3d9ac6){if(_0x3d9ac6){return _0x39f36b['sendStatus'](_0x307c52);}return _0x39f36b[_0xfb5e('0x19')](_0x307c52)[_0xfb5e('0x1a')]();};}function respondWithResult(_0x1c1d98,_0x1a9840){_0x1a9840=_0x1a9840||0xc8;return function(_0xd10351){if(_0xd10351){return _0x1c1d98[_0xfb5e('0x19')](_0x1a9840)[_0xfb5e('0x1b')](_0xd10351);}};}function respondWithFilteredResult(_0x145d98,_0x24acd8){return function(_0x58f6f3){if(_0x58f6f3){var _0x1b898d=typeof _0x24acd8['offset']===_0xfb5e('0x1c')&&typeof _0x24acd8[_0xfb5e('0x1d')]==='undefined';var _0x4db6f9=_0x58f6f3[_0xfb5e('0x1e')];var _0x384926=_0x1b898d?0x0:_0x24acd8[_0xfb5e('0x1f')];var _0x583f48=_0x1b898d?_0x58f6f3[_0xfb5e('0x1e')]:_0x24acd8[_0xfb5e('0x1f')]+_0x24acd8[_0xfb5e('0x1d')];var _0x4a688d;if(_0x583f48>=_0x4db6f9){_0x583f48=_0x4db6f9;_0x4a688d=0xc8;}else{_0x4a688d=0xce;}_0x145d98[_0xfb5e('0x19')](_0x4a688d);return _0x145d98[_0xfb5e('0x20')](_0xfb5e('0x21'),_0x384926+'-'+_0x583f48+'/'+_0x4db6f9)['json'](_0x58f6f3);}return null;};}function patchUpdates(_0x187458){return function(_0x457ab8){try{jsonpatch[_0xfb5e('0x22')](_0x457ab8,_0x187458,!![]);}catch(_0x1b49fd){return BPromise[_0xfb5e('0x23')](_0x1b49fd);}return _0x457ab8[_0xfb5e('0x24')]();};}function saveUpdates(_0x39faf4,_0x3a1084){return function(_0x249b16){if(_0x249b16){return _0x249b16[_0xfb5e('0x25')](_0x39faf4)[_0xfb5e('0x26')](function(_0x364dea){return _0x364dea;});}return null;};}function removeEntity(_0x102d68,_0x1ebc63){return function(_0x300f9f){if(_0x300f9f){return _0x300f9f[_0xfb5e('0x27')]()[_0xfb5e('0x26')](function(){_0x102d68[_0xfb5e('0x19')](0xcc)[_0xfb5e('0x1a')]();});}};}function handleEntityNotFound(_0x44cc62,_0x2abcc2){return function(_0x286fc6){if(!_0x286fc6){_0x44cc62[_0xfb5e('0x28')](0x194);}return _0x286fc6;};}function handleError(_0x1e73f0,_0x2978e8){_0x2978e8=_0x2978e8||0x1f4;return function(_0x15b1b9){logger[_0xfb5e('0x29')](_0x15b1b9[_0xfb5e('0x2a')]);if(_0x15b1b9['name']){delete _0x15b1b9['name'];}_0x1e73f0[_0xfb5e('0x19')](_0x2978e8)[_0xfb5e('0x2b')](_0x15b1b9);};}exports[_0xfb5e('0x2c')]=function(_0x59475a,_0x559aee){var _0x36550d={},_0x581148={},_0x34aeec={'count':0x0,'rows':[]};var _0x4a4ffa=_[_0xfb5e('0x2d')](db[_0xfb5e('0x2e')]['rawAttributes'],function(_0x559420){return{'name':_0x559420[_0xfb5e('0x2f')],'type':_0x559420[_0xfb5e('0x30')]['key']};});_0x581148['model']=_[_0xfb5e('0x31')](_[_0xfb5e('0x2d')](_0x4a4ffa,_0xfb5e('0x32')),[_0xfb5e('0x32')]);_0x581148[_0xfb5e('0x33')]=_[_0xfb5e('0x34')](_0x59475a[_0xfb5e('0x33')]);_0x581148[_0xfb5e('0x35')]=_[_0xfb5e('0x36')](_0x581148[_0xfb5e('0x37')],_0x581148[_0xfb5e('0x33')]);_0x36550d['attributes']=_['intersection'](_0x581148[_0xfb5e('0x37')],qs['fields'](_0x59475a[_0xfb5e('0x33')][_0xfb5e('0x38')]));_0x36550d[_0xfb5e('0x39')]=_0x36550d['attributes'][_0xfb5e('0x3a')]?_0x36550d[_0xfb5e('0x39')]:_0x581148[_0xfb5e('0x37')];if(!_0x59475a[_0xfb5e('0x33')][_0xfb5e('0x3b')]('nolimit')){_0x36550d[_0xfb5e('0x1d')]=qs[_0xfb5e('0x1d')](_0x59475a[_0xfb5e('0x33')]['limit']);_0x36550d['offset']=qs[_0xfb5e('0x1f')](_0x59475a['query'][_0xfb5e('0x1f')]);}_0x36550d[_0xfb5e('0x3c')]=qs[_0xfb5e('0x3d')](_0x59475a['query']['sort']);_0x36550d[_0xfb5e('0x3e')]=qs['filters'](_[_0xfb5e('0x3f')](_0x59475a[_0xfb5e('0x33')],_0x581148[_0xfb5e('0x35')]),_0x4a4ffa);if(_0x59475a[_0xfb5e('0x33')][_0xfb5e('0x40')]){_0x36550d[_0xfb5e('0x3e')]=_['merge'](_0x36550d[_0xfb5e('0x3e')],{'$or':_[_0xfb5e('0x2d')](_0x4a4ffa,function(_0x5e75fe){if(_0x5e75fe['type']!==_0xfb5e('0x41')){var _0x5bad30={};_0x5bad30[_0x5e75fe[_0xfb5e('0x32')]]={'$like':'%'+_0x59475a['query'][_0xfb5e('0x40')]+'%'};return _0x5bad30;}})});}_0x36550d=_[_0xfb5e('0x42')]({},_0x36550d,_0x59475a[_0xfb5e('0x43')]);var _0x2ea4ff={'where':_0x36550d[_0xfb5e('0x3e')]};return db['VoiceMailMessage']['count'](_0x2ea4ff)[_0xfb5e('0x26')](function(_0x10fa5d){_0x34aeec[_0xfb5e('0x1e')]=_0x10fa5d;if(_0x59475a['query']['includeAll']){_0x36550d['include']=[{'all':!![]}];}return db[_0xfb5e('0x2e')][_0xfb5e('0x44')](_0x36550d);})['then'](function(_0x287e7e){_0x34aeec[_0xfb5e('0x45')]=_0x287e7e;return _0x34aeec;})['then'](respondWithFilteredResult(_0x559aee,_0x36550d))['catch'](handleError(_0x559aee,null));};exports[_0xfb5e('0x46')]=function(_0x47bf24,_0x3256f8){var _0x29bc50={'raw':!![],'where':{'id':_0x47bf24[_0xfb5e('0x47')]['id']}},_0x2cd6c4={};_0x2cd6c4[_0xfb5e('0x37')]=_['keys'](db[_0xfb5e('0x2e')][_0xfb5e('0x48')]);_0x2cd6c4[_0xfb5e('0x33')]=_[_0xfb5e('0x34')](_0x47bf24[_0xfb5e('0x33')]);_0x2cd6c4[_0xfb5e('0x35')]=_[_0xfb5e('0x36')](_0x2cd6c4[_0xfb5e('0x37')],_0x2cd6c4[_0xfb5e('0x33')]);_0x29bc50['attributes']=_[_0xfb5e('0x36')](_0x2cd6c4[_0xfb5e('0x37')],qs[_0xfb5e('0x38')](_0x47bf24[_0xfb5e('0x33')]['fields']));_0x29bc50[_0xfb5e('0x39')]=_0x29bc50[_0xfb5e('0x39')]['length']?_0x29bc50['attributes']:_0x2cd6c4[_0xfb5e('0x37')];if(_0x47bf24[_0xfb5e('0x33')]['includeAll']){_0x29bc50[_0xfb5e('0x49')]=[{'all':!![]}];}_0x29bc50=_[_0xfb5e('0x42')]({},_0x29bc50,_0x47bf24[_0xfb5e('0x43')]);return db[_0xfb5e('0x2e')][_0xfb5e('0x4a')](_0x29bc50)[_0xfb5e('0x26')](handleEntityNotFound(_0x3256f8,null))[_0xfb5e('0x26')](respondWithResult(_0x3256f8,null))[_0xfb5e('0x4b')](handleError(_0x3256f8,null));};exports[_0xfb5e('0x4c')]=function(_0x2dbb75,_0x21b94a){return db['VoiceMailMessage'][_0xfb5e('0x4c')](_0x2dbb75['body'],{})[_0xfb5e('0x26')](respondWithResult(_0x21b94a,0xc9))[_0xfb5e('0x4b')](handleError(_0x21b94a,null));};exports[_0xfb5e('0x25')]=function(_0x484146,_0x138ef1){if(_0x484146[_0xfb5e('0x4d')]['id']){delete _0x484146['body']['id'];}return db[_0xfb5e('0x2e')][_0xfb5e('0x4a')]({'where':{'id':_0x484146[_0xfb5e('0x47')]['id']}})[_0xfb5e('0x26')](handleEntityNotFound(_0x138ef1,null))['then'](saveUpdates(_0x484146[_0xfb5e('0x4d')],null))[_0xfb5e('0x26')](respondWithResult(_0x138ef1,null))[_0xfb5e('0x4b')](handleError(_0x138ef1,null));};exports[_0xfb5e('0x27')]=function(_0x3f4f1c,_0x5e0348){return db[_0xfb5e('0x2e')][_0xfb5e('0x4a')]({'where':{'id':_0x3f4f1c[_0xfb5e('0x47')]['id']}})[_0xfb5e('0x26')](handleEntityNotFound(_0x5e0348,null))[_0xfb5e('0x26')](removeEntity(_0x5e0348,null))[_0xfb5e('0x4b')](handleError(_0x5e0348,null));};exports['download']=function(_0x50377d,_0x51886b,_0xfbeb70){return db[_0xfb5e('0x2e')][_0xfb5e('0x4a')]({'where':{'id':_0x50377d['params']['id']},'attributes':['id',_0xfb5e('0x4e'),'msg_id']})['then'](handleEntityNotFound(_0x51886b,null))[_0xfb5e('0x26')](function(_0x5e8c33){if(_0x5e8c33){if(!_0x5e8c33[_0xfb5e('0x4e')]){throw new db[(_0xfb5e('0x4f'))][(_0xfb5e('0x50'))](_0xfb5e('0x51'));}var _0x5bbd5b={'Content-Type':'audio/wav','Content-Disposition':_0xfb5e('0x52')};if(_0x5e8c33[_0xfb5e('0x53')]){_0x5bbd5b['Content-Disposition']=_0xfb5e('0x54')+_0x5e8c33['msg_id']+'.wav\x22';}_0x51886b['set'](_0x5bbd5b);return _0x51886b[_0xfb5e('0x2b')](new Buffer(_0x5e8c33['recording']));}})[_0xfb5e('0x4b')](handleError(_0x51886b,null));};