Built motion from commit fe909640.|2.6.8
[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 _0x25f8=['set','Content-Range','apply','reject','save','then','destroy','error','name','map','VoiceMailMessage','rawAttributes','model','differenceBy','query','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','keys','length','find','create','body','update','recording','msg_id','Sequelize','ValidationError','VoiceMailMessage\x20not\x20found','attachment','attachment;\x20filename=\x22','.wav\x22','send','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','fs-extra','lodash','squel','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','undefined','limit','count','offset'];(function(_0x592e40,_0x2ed011){var _0x5d4288=function(_0x366e87){while(--_0x366e87){_0x592e40['push'](_0x592e40['shift']());}};_0x5d4288(++_0x2ed011);}(_0x25f8,0x83));var _0x825f=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0x25f8[_0x1cc8fe];return _0x230054;};'use strict';var emlformat=require(_0x825f('0x0'));var rimraf=require(_0x825f('0x1'));var zipdir=require(_0x825f('0x2'));var jsonpatch=require(_0x825f('0x3'));var rp=require(_0x825f('0x4'));var moment=require(_0x825f('0x5'));var BPromise=require(_0x825f('0x6'));var Mustache=require('mustache');var util=require(_0x825f('0x7'));var path=require(_0x825f('0x8'));var sox=require('sox');var csv=require(_0x825f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x825f('0xa'));var _=require(_0x825f('0xb'));var squel=require(_0x825f('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x825f('0x9'));var querystring=require(_0x825f('0xd'));var Papa=require('papaparse');var Redis=require(_0x825f('0xe'));var authService=require(_0x825f('0xf'));var qs=require(_0x825f('0x10'));var as=require(_0x825f('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x825f('0x12'))(_0x825f('0x13'));var utils=require(_0x825f('0x14'));var config=require(_0x825f('0x15'));var licenseUtil=require(_0x825f('0x16'));var db=require(_0x825f('0x17'))['db'];function respondWithStatusCode(_0x43eed0,_0x5c972e){_0x5c972e=_0x5c972e||0xcc;return function(_0x660e91){if(_0x660e91){return _0x43eed0[_0x825f('0x18')](_0x5c972e);}return _0x43eed0[_0x825f('0x19')](_0x5c972e)[_0x825f('0x1a')]();};}function respondWithResult(_0x4113f4,_0xbe98bc){_0xbe98bc=_0xbe98bc||0xc8;return function(_0x2f1759){if(_0x2f1759){return _0x4113f4[_0x825f('0x19')](_0xbe98bc)['json'](_0x2f1759);}};}function respondWithFilteredResult(_0x8acbb0,_0x4e96d5){return function(_0x237676){if(_0x237676){var _0x1992b5=typeof _0x4e96d5['offset']===_0x825f('0x1b')&&typeof _0x4e96d5[_0x825f('0x1c')]===_0x825f('0x1b');var _0x41e315=_0x237676[_0x825f('0x1d')];var _0x16ffb8=_0x1992b5?0x0:_0x4e96d5[_0x825f('0x1e')];var _0x3a851e=_0x1992b5?_0x237676[_0x825f('0x1d')]:_0x4e96d5[_0x825f('0x1e')]+_0x4e96d5[_0x825f('0x1c')];var _0x399416;if(_0x3a851e>=_0x41e315){_0x3a851e=_0x41e315;_0x399416=0xc8;}else{_0x399416=0xce;}_0x8acbb0[_0x825f('0x19')](_0x399416);return _0x8acbb0[_0x825f('0x1f')](_0x825f('0x20'),_0x16ffb8+'-'+_0x3a851e+'/'+_0x41e315)['json'](_0x237676);}return null;};}function patchUpdates(_0x5a34b1){return function(_0x3fe443){try{jsonpatch[_0x825f('0x21')](_0x3fe443,_0x5a34b1,!![]);}catch(_0x5c4d9b){return BPromise[_0x825f('0x22')](_0x5c4d9b);}return _0x3fe443[_0x825f('0x23')]();};}function saveUpdates(_0x10a620,_0xe4b0b7){return function(_0x28da75){if(_0x28da75){return _0x28da75['update'](_0x10a620)[_0x825f('0x24')](function(_0x2942a4){return _0x2942a4;});}return null;};}function removeEntity(_0x3893fa,_0x511d8a){return function(_0x1c6043){if(_0x1c6043){return _0x1c6043[_0x825f('0x25')]()['then'](function(){_0x3893fa[_0x825f('0x19')](0xcc)[_0x825f('0x1a')]();});}};}function handleEntityNotFound(_0x2a5c5e,_0x336f8f){return function(_0x1b3863){if(!_0x1b3863){_0x2a5c5e[_0x825f('0x18')](0x194);}return _0x1b3863;};}function handleError(_0x44655d,_0xe2d92f){_0xe2d92f=_0xe2d92f||0x1f4;return function(_0x4a9e65){logger[_0x825f('0x26')](_0x4a9e65['stack']);if(_0x4a9e65['name']){delete _0x4a9e65[_0x825f('0x27')];}_0x44655d['status'](_0xe2d92f)['send'](_0x4a9e65);};}exports['index']=function(_0x588220,_0x3f329f){var _0x2b5e37={},_0x2b59c3={},_0xf422f5={'count':0x0,'rows':[]};var _0x22f7cc=_[_0x825f('0x28')](db[_0x825f('0x29')][_0x825f('0x2a')],function(_0x132d3c){return{'name':_0x132d3c['fieldName'],'type':_0x132d3c['type']['key']};});_0x2b59c3[_0x825f('0x2b')]=_[_0x825f('0x2c')](_[_0x825f('0x28')](_0x22f7cc,_0x825f('0x27')),[_0x825f('0x27')]);_0x2b59c3[_0x825f('0x2d')]=_['keys'](_0x588220[_0x825f('0x2d')]);_0x2b59c3[_0x825f('0x2e')]=_['intersection'](_0x2b59c3[_0x825f('0x2b')],_0x2b59c3[_0x825f('0x2d')]);_0x2b5e37[_0x825f('0x2f')]=_[_0x825f('0x30')](_0x2b59c3['model'],qs['fields'](_0x588220[_0x825f('0x2d')][_0x825f('0x31')]));_0x2b5e37[_0x825f('0x2f')]=_0x2b5e37[_0x825f('0x2f')]['length']?_0x2b5e37[_0x825f('0x2f')]:_0x2b59c3['model'];if(!_0x588220[_0x825f('0x2d')][_0x825f('0x32')](_0x825f('0x33'))){_0x2b5e37[_0x825f('0x1c')]=qs[_0x825f('0x1c')](_0x588220[_0x825f('0x2d')][_0x825f('0x1c')]);_0x2b5e37[_0x825f('0x1e')]=qs[_0x825f('0x1e')](_0x588220['query']['offset']);}_0x2b5e37[_0x825f('0x34')]=qs[_0x825f('0x35')](_0x588220[_0x825f('0x2d')][_0x825f('0x35')]);_0x2b5e37[_0x825f('0x36')]=qs['filters'](_[_0x825f('0x37')](_0x588220['query'],_0x2b59c3['filters']),_0x22f7cc);if(_0x588220[_0x825f('0x2d')][_0x825f('0x38')]){_0x2b5e37['where']=_[_0x825f('0x39')](_0x2b5e37[_0x825f('0x36')],{'$or':_[_0x825f('0x28')](_0x22f7cc,function(_0x1fe13d){if(_0x1fe13d['type']!==_0x825f('0x3a')){var _0x4849ce={};_0x4849ce[_0x1fe13d[_0x825f('0x27')]]={'$like':'%'+_0x588220[_0x825f('0x2d')][_0x825f('0x38')]+'%'};return _0x4849ce;}})});}_0x2b5e37=_[_0x825f('0x39')]({},_0x2b5e37,_0x588220[_0x825f('0x3b')]);var _0x25900d={'where':_0x2b5e37[_0x825f('0x36')]};return db['VoiceMailMessage'][_0x825f('0x1d')](_0x25900d)['then'](function(_0x34e46e){_0xf422f5['count']=_0x34e46e;if(_0x588220[_0x825f('0x2d')][_0x825f('0x3c')]){_0x2b5e37[_0x825f('0x3d')]=[{'all':!![]}];}return db[_0x825f('0x29')][_0x825f('0x3e')](_0x2b5e37);})['then'](function(_0x5cd997){_0xf422f5['rows']=_0x5cd997;return _0xf422f5;})[_0x825f('0x24')](respondWithFilteredResult(_0x3f329f,_0x2b5e37))[_0x825f('0x3f')](handleError(_0x3f329f,null));};exports[_0x825f('0x40')]=function(_0x137aad,_0x372518){var _0x5cd031={'raw':!![],'where':{'id':_0x137aad[_0x825f('0x41')]['id']}},_0x13b7d9={};_0x13b7d9[_0x825f('0x2b')]=_[_0x825f('0x42')](db[_0x825f('0x29')][_0x825f('0x2a')]);_0x13b7d9['query']=_[_0x825f('0x42')](_0x137aad[_0x825f('0x2d')]);_0x13b7d9[_0x825f('0x2e')]=_[_0x825f('0x30')](_0x13b7d9[_0x825f('0x2b')],_0x13b7d9[_0x825f('0x2d')]);_0x5cd031['attributes']=_[_0x825f('0x30')](_0x13b7d9['model'],qs[_0x825f('0x31')](_0x137aad[_0x825f('0x2d')][_0x825f('0x31')]));_0x5cd031[_0x825f('0x2f')]=_0x5cd031[_0x825f('0x2f')][_0x825f('0x43')]?_0x5cd031[_0x825f('0x2f')]:_0x13b7d9[_0x825f('0x2b')];if(_0x137aad['query'][_0x825f('0x3c')]){_0x5cd031[_0x825f('0x3d')]=[{'all':!![]}];}_0x5cd031=_[_0x825f('0x39')]({},_0x5cd031,_0x137aad[_0x825f('0x3b')]);return db[_0x825f('0x29')][_0x825f('0x44')](_0x5cd031)[_0x825f('0x24')](handleEntityNotFound(_0x372518,null))[_0x825f('0x24')](respondWithResult(_0x372518,null))[_0x825f('0x3f')](handleError(_0x372518,null));};exports[_0x825f('0x45')]=function(_0x3e64e5,_0x299fbf){return db['VoiceMailMessage']['create'](_0x3e64e5[_0x825f('0x46')],{})['then'](respondWithResult(_0x299fbf,0xc9))[_0x825f('0x3f')](handleError(_0x299fbf,null));};exports[_0x825f('0x47')]=function(_0x58809e,_0x4cfc5c){if(_0x58809e[_0x825f('0x46')]['id']){delete _0x58809e[_0x825f('0x46')]['id'];}return db[_0x825f('0x29')][_0x825f('0x44')]({'where':{'id':_0x58809e[_0x825f('0x41')]['id']}})[_0x825f('0x24')](handleEntityNotFound(_0x4cfc5c,null))[_0x825f('0x24')](saveUpdates(_0x58809e[_0x825f('0x46')],null))[_0x825f('0x24')](respondWithResult(_0x4cfc5c,null))[_0x825f('0x3f')](handleError(_0x4cfc5c,null));};exports[_0x825f('0x25')]=function(_0x5d2513,_0x55000b){return db['VoiceMailMessage'][_0x825f('0x44')]({'where':{'id':_0x5d2513[_0x825f('0x41')]['id']}})[_0x825f('0x24')](handleEntityNotFound(_0x55000b,null))[_0x825f('0x24')](removeEntity(_0x55000b,null))[_0x825f('0x3f')](handleError(_0x55000b,null));};exports['download']=function(_0x1fbed6,_0x39d8af,_0x21cfe0){return db[_0x825f('0x29')][_0x825f('0x44')]({'where':{'id':_0x1fbed6['params']['id']},'attributes':['id',_0x825f('0x48'),_0x825f('0x49')]})[_0x825f('0x24')](handleEntityNotFound(_0x39d8af,null))['then'](function(_0x37da10){if(_0x37da10){if(!_0x37da10[_0x825f('0x48')]){throw new db[(_0x825f('0x4a'))][(_0x825f('0x4b'))](_0x825f('0x4c'));}var _0x1a2932={'Content-Type':'audio/wav','Content-Disposition':_0x825f('0x4d')};if(_0x37da10[_0x825f('0x49')]){_0x1a2932['Content-Disposition']=_0x825f('0x4e')+_0x37da10[_0x825f('0x49')]+_0x825f('0x4f');}_0x39d8af['set'](_0x1a2932);return _0x39d8af[_0x825f('0x50')](new Buffer(_0x37da10['recording']));}})[_0x825f('0x3f')](handleError(_0x39d8af,null));};