Built motion from commit f0b1811d.|2.6.6
[motion2.git] / server / api / squareRecording / squareRecording.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 _0x774b=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','set','json','apply','then','destroy','sendStatus','error','name','send','SquareRecording','rawAttributes','fieldName','type','key','model','map','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','includeAll','findAll','params','include','find','catch','create','body','update','../../components/encryptor','uniqueid','savePath','filename','%s.cypher','existsSync','secrets','recording','Sequelize','ValidationError','SquareRecording\x20not\x20found','download','extname','unlink','message','Not\x20found','isNil','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','.cypher','unlinkSync','eml-format','rimraf','zip-dir','request-promise','util','path','to-csv','ejs','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs'];(function(_0x57d7f7,_0x335c81){var _0x1a6800=function(_0x251345){while(--_0x251345){_0x57d7f7['push'](_0x57d7f7['shift']());}};_0x1a6800(++_0x335c81);}(_0x774b,0x10d));var _0xb774=function(_0x65fe34,_0x21cbe5){_0x65fe34=_0x65fe34-0x0;var _0x249c22=_0x774b[_0x65fe34];return _0x249c22;};'use strict';var emlformat=require(_0xb774('0x0'));var rimraf=require(_0xb774('0x1'));var zipdir=require(_0xb774('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb774('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xb774('0x4'));var path=require(_0xb774('0x5'));var sox=require('sox');var csv=require(_0xb774('0x6'));var ejs=require(_0xb774('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb774('0x8'));var squel=require('squel');var crypto=require(_0xb774('0x9'));var jsforce=require(_0xb774('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xb774('0x6'));var querystring=require(_0xb774('0xb'));var Papa=require(_0xb774('0xc'));var Redis=require(_0xb774('0xd'));var authService=require(_0xb774('0xe'));var qs=require(_0xb774('0xf'));var as=require(_0xb774('0x10'));var hardwareService=require(_0xb774('0x11'));var logger=require(_0xb774('0x12'))('api');var utils=require(_0xb774('0x13'));var config=require(_0xb774('0x14'));var licenseUtil=require(_0xb774('0x15'));var db=require(_0xb774('0x16'))['db'];function respondWithStatusCode(_0x10c53d,_0x43feb6){_0x43feb6=_0x43feb6||0xcc;return function(_0x2aae0b){if(_0x2aae0b){return _0x10c53d['sendStatus'](_0x43feb6);}return _0x10c53d[_0xb774('0x17')](_0x43feb6)[_0xb774('0x18')]();};}function respondWithResult(_0x53f07b,_0x274c5b){_0x274c5b=_0x274c5b||0xc8;return function(_0x9417ea){if(_0x9417ea){return _0x53f07b['status'](_0x274c5b)['json'](_0x9417ea);}};}function respondWithFilteredResult(_0x286214,_0x155489){return function(_0x11325f){if(_0x11325f){var _0x2edcd4=typeof _0x155489[_0xb774('0x19')]===_0xb774('0x1a')&&typeof _0x155489[_0xb774('0x1b')]===_0xb774('0x1a');var _0x537f04=_0x11325f[_0xb774('0x1c')];var _0x2531f=_0x2edcd4?0x0:_0x155489[_0xb774('0x19')];var _0x4228c4=_0x2edcd4?_0x11325f[_0xb774('0x1c')]:_0x155489[_0xb774('0x19')]+_0x155489['limit'];var _0x2946f8;if(_0x4228c4>=_0x537f04){_0x4228c4=_0x537f04;_0x2946f8=0xc8;}else{_0x2946f8=0xce;}_0x286214[_0xb774('0x17')](_0x2946f8);return _0x286214[_0xb774('0x1d')]('Content-Range',_0x2531f+'-'+_0x4228c4+'/'+_0x537f04)[_0xb774('0x1e')](_0x11325f);}return null;};}function patchUpdates(_0x55f67a){return function(_0x28d6e2){try{jsonpatch[_0xb774('0x1f')](_0x28d6e2,_0x55f67a,!![]);}catch(_0x42154e){return BPromise['reject'](_0x42154e);}return _0x28d6e2['save']();};}function saveUpdates(_0x127cef,_0x1c9f1a){return function(_0x8812ca){if(_0x8812ca){return _0x8812ca['update'](_0x127cef)[_0xb774('0x20')](function(_0x10e530){return _0x10e530;});}return null;};}function removeEntity(_0x18297a,_0x3ff23d){return function(_0x584df6){if(_0x584df6){return _0x584df6[_0xb774('0x21')]()[_0xb774('0x20')](function(){_0x18297a[_0xb774('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2eea96,_0x568b60){return function(_0x35d24f){if(!_0x35d24f){_0x2eea96[_0xb774('0x22')](0x194);}return _0x35d24f;};}function handleError(_0x124d1b,_0x420678){_0x420678=_0x420678||0x1f4;return function(_0xd4a60){logger[_0xb774('0x23')](_0xd4a60['stack']);if(_0xd4a60[_0xb774('0x24')]){delete _0xd4a60[_0xb774('0x24')];}_0x124d1b[_0xb774('0x17')](_0x420678)[_0xb774('0x25')](_0xd4a60);};}exports['index']=function(_0x1160b4,_0x42290b){var _0x5bd592={},_0x18161e={},_0x47bfac={'count':0x0,'rows':[]};var _0x510029=_['map'](db[_0xb774('0x26')][_0xb774('0x27')],function(_0x3bb6f6){return{'name':_0x3bb6f6[_0xb774('0x28')],'type':_0x3bb6f6[_0xb774('0x29')][_0xb774('0x2a')]};});_0x18161e[_0xb774('0x2b')]=_[_0xb774('0x2c')](_0x510029,_0xb774('0x24'));_0x18161e['query']=_[_0xb774('0x2d')](_0x1160b4[_0xb774('0x2e')]);_0x18161e['filters']=_[_0xb774('0x2f')](_0x18161e[_0xb774('0x2b')],_0x18161e[_0xb774('0x2e')]);_0x5bd592[_0xb774('0x30')]=_[_0xb774('0x2f')](_0x18161e[_0xb774('0x2b')],qs['fields'](_0x1160b4[_0xb774('0x2e')][_0xb774('0x31')]));_0x5bd592[_0xb774('0x30')]=_0x5bd592[_0xb774('0x30')][_0xb774('0x32')]?_0x5bd592[_0xb774('0x30')]:_0x18161e[_0xb774('0x2b')];if(!_0x1160b4[_0xb774('0x2e')][_0xb774('0x33')](_0xb774('0x34'))){_0x5bd592[_0xb774('0x1b')]=qs[_0xb774('0x1b')](_0x1160b4[_0xb774('0x2e')][_0xb774('0x1b')]);_0x5bd592['offset']=qs[_0xb774('0x19')](_0x1160b4[_0xb774('0x2e')][_0xb774('0x19')]);}_0x5bd592[_0xb774('0x35')]=qs[_0xb774('0x36')](_0x1160b4['query']['sort']);_0x5bd592[_0xb774('0x37')]=qs[_0xb774('0x38')](_[_0xb774('0x39')](_0x1160b4[_0xb774('0x2e')],_0x18161e[_0xb774('0x38')]),_0x510029);if(_0x1160b4[_0xb774('0x2e')][_0xb774('0x3a')]){_0x5bd592[_0xb774('0x37')]=_['merge'](_0x5bd592[_0xb774('0x37')],{'$or':_['map'](_0x510029,function(_0x2bacd5){if(_0x2bacd5['type']!==_0xb774('0x3b')){var _0x516ee5={};_0x516ee5[_0x2bacd5[_0xb774('0x24')]]={'$like':'%'+_0x1160b4[_0xb774('0x2e')][_0xb774('0x3a')]+'%'};return _0x516ee5;}})});}_0x5bd592=_[_0xb774('0x3c')]({},_0x5bd592,_0x1160b4[_0xb774('0x3d')]);var _0x4f268d={'where':_0x5bd592['where']};return db['SquareRecording'][_0xb774('0x1c')](_0x4f268d)['then'](function(_0x5acd2e){_0x47bfac[_0xb774('0x1c')]=_0x5acd2e;if(_0x1160b4['query'][_0xb774('0x3e')]){_0x5bd592['include']=[{'all':!![]}];}return db['SquareRecording'][_0xb774('0x3f')](_0x5bd592);})[_0xb774('0x20')](function(_0xb537bb){_0x47bfac['rows']=_0xb537bb;return _0x47bfac;})[_0xb774('0x20')](respondWithFilteredResult(_0x42290b,_0x5bd592))['catch'](handleError(_0x42290b,null));};exports['show']=function(_0x53c0bb,_0x4516ad){var _0x568d7f={'raw':!![],'where':{'id':_0x53c0bb[_0xb774('0x40')]['id']}},_0x7c3aaa={};_0x7c3aaa[_0xb774('0x2b')]=_[_0xb774('0x2d')](db[_0xb774('0x26')]['rawAttributes']);_0x7c3aaa[_0xb774('0x2e')]=_[_0xb774('0x2d')](_0x53c0bb['query']);_0x7c3aaa[_0xb774('0x38')]=_[_0xb774('0x2f')](_0x7c3aaa[_0xb774('0x2b')],_0x7c3aaa[_0xb774('0x2e')]);_0x568d7f[_0xb774('0x30')]=_['intersection'](_0x7c3aaa[_0xb774('0x2b')],qs[_0xb774('0x31')](_0x53c0bb[_0xb774('0x2e')][_0xb774('0x31')]));_0x568d7f[_0xb774('0x30')]=_0x568d7f['attributes'][_0xb774('0x32')]?_0x568d7f['attributes']:_0x7c3aaa['model'];if(_0x53c0bb['query']['includeAll']){_0x568d7f[_0xb774('0x41')]=[{'all':!![]}];}_0x568d7f=_[_0xb774('0x3c')]({},_0x568d7f,_0x53c0bb['options']);return db[_0xb774('0x26')][_0xb774('0x42')](_0x568d7f)[_0xb774('0x20')](handleEntityNotFound(_0x4516ad,null))[_0xb774('0x20')](respondWithResult(_0x4516ad,null))[_0xb774('0x43')](handleError(_0x4516ad,null));};exports[_0xb774('0x44')]=function(_0x3462a8,_0x4d7cbd){return db['SquareRecording'][_0xb774('0x44')](_0x3462a8[_0xb774('0x45')],{})[_0xb774('0x20')](respondWithResult(_0x4d7cbd,0xc9))['catch'](handleError(_0x4d7cbd,null));};exports[_0xb774('0x46')]=function(_0x10eeb9,_0x1dae6e){if(_0x10eeb9['body']['id']){delete _0x10eeb9['body']['id'];}return db['SquareRecording'][_0xb774('0x42')]({'where':{'id':_0x10eeb9[_0xb774('0x40')]['id']}})[_0xb774('0x20')](handleEntityNotFound(_0x1dae6e,null))[_0xb774('0x20')](saveUpdates(_0x10eeb9['body'],null))['then'](respondWithResult(_0x1dae6e,null))['catch'](handleError(_0x1dae6e,null));};exports['download']=function(_0x37447d,_0x4ef988,_0x3089db){var _0x27c941=require(_0xb774('0x47'));var _0x22e352=![];var _0x18701e={};if(_0x37447d[_0xb774('0x2e')][_0xb774('0x29')]&&_0x37447d[_0xb774('0x2e')][_0xb774('0x29')]===_0xb774('0x48')){_0x18701e['uniqueid']=_0x37447d[_0xb774('0x40')]['id'];}else{_0x18701e['id']=_0x37447d[_0xb774('0x40')]['id'];}return db[_0xb774('0x26')]['find']({'where':_0x18701e,'attributes':['id',_0xb774('0x49'),_0xb774('0x4a')],'raw':!![]})[_0xb774('0x20')](handleEntityNotFound(_0x4ef988,null))['then'](function(_0x23f012){if(_0x23f012){var _0x33f2d7=_0x23f012[_0xb774('0x49')];var _0xd9a0e8=util['format'](_0xb774('0x4b'),_0x33f2d7);if(fs[_0xb774('0x4c')](_0xd9a0e8)){_0x22e352=!![];return _0x27c941['decryptFile'](_0xd9a0e8,_0x33f2d7,config[_0xb774('0x4d')][_0xb774('0x4e')])[_0xb774('0x20')](function(){return _0x23f012;});}return _0x23f012;}})[_0xb774('0x20')](function(_0x56c5a1){if(_0x56c5a1){var _0x2dc0d4=_0x56c5a1[_0xb774('0x49')];if(!fs[_0xb774('0x4c')](_0x2dc0d4)){throw new db[(_0xb774('0x4f'))][(_0xb774('0x50'))](_0xb774('0x51'));}if(_0x56c5a1[_0xb774('0x4a')]){return _0x4ef988[_0xb774('0x52')](_0x2dc0d4,_0x56c5a1[_0xb774('0x4a')]+path[_0xb774('0x53')](_0x2dc0d4),function(){if(_0x22e352){fs[_0xb774('0x54')](_0x2dc0d4);}});}else{return _0x4ef988['download'](_0x2dc0d4,function(_0x24b6d6){if(_0x22e352){fs[_0xb774('0x54')](_0x2dc0d4);}});}}})['catch'](function(_0xcbdd1a){if(_0xcbdd1a[_0xb774('0x55')]===_0xb774('0x51')){_0x4ef988[_0xb774('0x17')](0x194)['send'](_0xb774('0x56'));}else{return handleError(_0x4ef988,null);}});};exports[_0xb774('0x21')]=function(_0x420e21,_0x3ddfe1){return db[_0xb774('0x26')]['find']({'where':{'id':_0x420e21['params']['id']}})['then'](function(_0x1836cb){if(_[_0xb774('0x57')](_0x1836cb)){throw new ReferenceError(_0xb774('0x58'));}return _0x1836cb;})[_0xb774('0x20')](function(_0x3e04d3){var _0x3b7eb5=_0x3e04d3[_0xb774('0x49')];logger[_0xb774('0x59')](_0xb774('0x5a'),_0x3b7eb5);if(!_[_0xb774('0x57')](_0x3e04d3[_0xb774('0x49')])&&fs[_0xb774('0x4c')](_0x3b7eb5)){logger['info'](_0xb774('0x5b')+_0x3b7eb5+_0xb774('0x5c'));fs['unlinkSync'](_0x3b7eb5);}_0x3b7eb5=_0x3b7eb5+_0xb774('0x5d');if(!_[_0xb774('0x57')](_0x3e04d3[_0xb774('0x49')])&&fs[_0xb774('0x4c')](_0x3b7eb5)){logger[_0xb774('0x59')](_0xb774('0x5b')+_0x3b7eb5+_0xb774('0x5c'));fs[_0xb774('0x5e')](_0x3b7eb5);}return _0x3e04d3;})[_0xb774('0x20')](function(_0x1da8d9){if(!_0x1da8d9)throw new InternalError();return _0x1da8d9[_0xb774('0x21')]();})[_0xb774('0x20')](function(){_0x3ddfe1['status'](0xcc)[_0xb774('0x18')]();})[_0xb774('0x43')](handleError(_0x3ddfe1,null));};