Built motion from commit f7863d46.|2.5.41
[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 _0x1970=['apply','reject','save','update','then','destroy','error','stack','name','send','index','map','rawAttributes','key','query','keys','filters','intersection','attributes','model','fields','length','nolimit','sort','filter','merge','where','type','VIRTUAL','options','SquareRecording','includeAll','include','findAll','rows','params','catch','create','find','body','uniqueid','savePath','filename','format','%s.cypher','existsSync','secrets','recording','Sequelize','download','extname','unlink','message','SquareRecording\x20not\x20found','isNil','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','unlinkSync','.cypher','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','json','undefined','limit','count','offset','status','set','Content-Range'];(function(_0xd0cd0b,_0x490956){var _0x59cced=function(_0x567251){while(--_0x567251){_0xd0cd0b['push'](_0xd0cd0b['shift']());}};_0x59cced(++_0x490956);}(_0x1970,0xfe));var _0x0197=function(_0x1883b1,_0x32447c){_0x1883b1=_0x1883b1-0x0;var _0x11595c=_0x1970[_0x1883b1];return _0x11595c;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0197('0x0'));var zipdir=require(_0x0197('0x1'));var jsonpatch=require(_0x0197('0x2'));var rp=require(_0x0197('0x3'));var moment=require(_0x0197('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x0197('0x5'));var util=require('util');var path=require('path');var sox=require(_0x0197('0x6'));var csv=require(_0x0197('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x0197('0x8'));var _=require(_0x0197('0x9'));var squel=require(_0x0197('0xa'));var crypto=require(_0x0197('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x0197('0xc'));var toCsv=require(_0x0197('0x7'));var querystring=require(_0x0197('0xd'));var Papa=require(_0x0197('0xe'));var Redis=require('ioredis');var authService=require(_0x0197('0xf'));var qs=require(_0x0197('0x10'));var as=require(_0x0197('0x11'));var hardwareService=require(_0x0197('0x12'));var logger=require('../../config/logger')(_0x0197('0x13'));var utils=require(_0x0197('0x14'));var config=require(_0x0197('0x15'));var licenseUtil=require(_0x0197('0x16'));var db=require(_0x0197('0x17'))['db'];function respondWithStatusCode(_0xdcbba0,_0x19011b){_0x19011b=_0x19011b||0xcc;return function(_0x378280){if(_0x378280){return _0xdcbba0[_0x0197('0x18')](_0x19011b);}return _0xdcbba0['status'](_0x19011b)[_0x0197('0x19')]();};}function respondWithResult(_0x20fc68,_0x33f6f4){_0x33f6f4=_0x33f6f4||0xc8;return function(_0x9e5db7){if(_0x9e5db7){return _0x20fc68['status'](_0x33f6f4)[_0x0197('0x1a')](_0x9e5db7);}};}function respondWithFilteredResult(_0x27fe30,_0x57c91c){return function(_0x5a9792){if(_0x5a9792){var _0x155e42=typeof _0x57c91c['offset']===_0x0197('0x1b')&&typeof _0x57c91c[_0x0197('0x1c')]===_0x0197('0x1b');var _0x1fefba=_0x5a9792[_0x0197('0x1d')];var _0x5b83dc=_0x155e42?0x0:_0x57c91c[_0x0197('0x1e')];var _0x1b3a0a=_0x155e42?_0x5a9792[_0x0197('0x1d')]:_0x57c91c[_0x0197('0x1e')]+_0x57c91c[_0x0197('0x1c')];var _0x56c683;if(_0x1b3a0a>=_0x1fefba){_0x1b3a0a=_0x1fefba;_0x56c683=0xc8;}else{_0x56c683=0xce;}_0x27fe30[_0x0197('0x1f')](_0x56c683);return _0x27fe30[_0x0197('0x20')](_0x0197('0x21'),_0x5b83dc+'-'+_0x1b3a0a+'/'+_0x1fefba)[_0x0197('0x1a')](_0x5a9792);}return null;};}function patchUpdates(_0x2c8484){return function(_0x36fb9e){try{jsonpatch[_0x0197('0x22')](_0x36fb9e,_0x2c8484,!![]);}catch(_0x5a1de8){return BPromise[_0x0197('0x23')](_0x5a1de8);}return _0x36fb9e[_0x0197('0x24')]();};}function saveUpdates(_0x1e83b1,_0x3eb66b){return function(_0x3d4dbc){if(_0x3d4dbc){return _0x3d4dbc[_0x0197('0x25')](_0x1e83b1)[_0x0197('0x26')](function(_0x43e672){return _0x43e672;});}return null;};}function removeEntity(_0x3bf0c7,_0x7b9877){return function(_0x3c4251){if(_0x3c4251){return _0x3c4251[_0x0197('0x27')]()[_0x0197('0x26')](function(){_0x3bf0c7['status'](0xcc)[_0x0197('0x19')]();});}};}function handleEntityNotFound(_0x4a8a34,_0x4085de){return function(_0x5c17be){if(!_0x5c17be){_0x4a8a34[_0x0197('0x18')](0x194);}return _0x5c17be;};}function handleError(_0x3a2d95,_0x49bb00){_0x49bb00=_0x49bb00||0x1f4;return function(_0x13b406){logger[_0x0197('0x28')](_0x13b406[_0x0197('0x29')]);if(_0x13b406[_0x0197('0x2a')]){delete _0x13b406[_0x0197('0x2a')];}_0x3a2d95[_0x0197('0x1f')](_0x49bb00)[_0x0197('0x2b')](_0x13b406);};}exports[_0x0197('0x2c')]=function(_0x16b5c1,_0xdf1e0e){var _0x1e685a={},_0x24edba={},_0x8709={'count':0x0,'rows':[]};var _0x228394=_[_0x0197('0x2d')](db['SquareRecording'][_0x0197('0x2e')],function(_0x444f04){return{'name':_0x444f04['fieldName'],'type':_0x444f04['type'][_0x0197('0x2f')]};});_0x24edba['model']=_[_0x0197('0x2d')](_0x228394,_0x0197('0x2a'));_0x24edba[_0x0197('0x30')]=_[_0x0197('0x31')](_0x16b5c1[_0x0197('0x30')]);_0x24edba[_0x0197('0x32')]=_[_0x0197('0x33')](_0x24edba['model'],_0x24edba[_0x0197('0x30')]);_0x1e685a[_0x0197('0x34')]=_[_0x0197('0x33')](_0x24edba[_0x0197('0x35')],qs['fields'](_0x16b5c1['query'][_0x0197('0x36')]));_0x1e685a[_0x0197('0x34')]=_0x1e685a[_0x0197('0x34')][_0x0197('0x37')]?_0x1e685a[_0x0197('0x34')]:_0x24edba[_0x0197('0x35')];if(!_0x16b5c1[_0x0197('0x30')]['hasOwnProperty'](_0x0197('0x38'))){_0x1e685a[_0x0197('0x1c')]=qs[_0x0197('0x1c')](_0x16b5c1[_0x0197('0x30')][_0x0197('0x1c')]);_0x1e685a[_0x0197('0x1e')]=qs[_0x0197('0x1e')](_0x16b5c1[_0x0197('0x30')][_0x0197('0x1e')]);}_0x1e685a['order']=qs[_0x0197('0x39')](_0x16b5c1['query'][_0x0197('0x39')]);_0x1e685a['where']=qs['filters'](_['pick'](_0x16b5c1[_0x0197('0x30')],_0x24edba[_0x0197('0x32')]),_0x228394);if(_0x16b5c1[_0x0197('0x30')][_0x0197('0x3a')]){_0x1e685a['where']=_[_0x0197('0x3b')](_0x1e685a[_0x0197('0x3c')],{'$or':_[_0x0197('0x2d')](_0x228394,function(_0x4f5725){if(_0x4f5725[_0x0197('0x3d')]!==_0x0197('0x3e')){var _0x444786={};_0x444786[_0x4f5725[_0x0197('0x2a')]]={'$like':'%'+_0x16b5c1['query'][_0x0197('0x3a')]+'%'};return _0x444786;}})});}_0x1e685a=_['merge']({},_0x1e685a,_0x16b5c1[_0x0197('0x3f')]);var _0x35157c={'where':_0x1e685a[_0x0197('0x3c')]};return db[_0x0197('0x40')][_0x0197('0x1d')](_0x35157c)['then'](function(_0x22306d){_0x8709['count']=_0x22306d;if(_0x16b5c1['query'][_0x0197('0x41')]){_0x1e685a[_0x0197('0x42')]=[{'all':!![]}];}return db['SquareRecording'][_0x0197('0x43')](_0x1e685a);})['then'](function(_0x542a3c){_0x8709[_0x0197('0x44')]=_0x542a3c;return _0x8709;})[_0x0197('0x26')](respondWithFilteredResult(_0xdf1e0e,_0x1e685a))['catch'](handleError(_0xdf1e0e,null));};exports['show']=function(_0x2e1d42,_0x20dd3c){var _0x44f3a6={'raw':!![],'where':{'id':_0x2e1d42[_0x0197('0x45')]['id']}},_0x21ae3c={};_0x21ae3c[_0x0197('0x35')]=_[_0x0197('0x31')](db['SquareRecording'][_0x0197('0x2e')]);_0x21ae3c[_0x0197('0x30')]=_[_0x0197('0x31')](_0x2e1d42[_0x0197('0x30')]);_0x21ae3c[_0x0197('0x32')]=_[_0x0197('0x33')](_0x21ae3c[_0x0197('0x35')],_0x21ae3c[_0x0197('0x30')]);_0x44f3a6[_0x0197('0x34')]=_[_0x0197('0x33')](_0x21ae3c[_0x0197('0x35')],qs[_0x0197('0x36')](_0x2e1d42[_0x0197('0x30')][_0x0197('0x36')]));_0x44f3a6['attributes']=_0x44f3a6[_0x0197('0x34')][_0x0197('0x37')]?_0x44f3a6[_0x0197('0x34')]:_0x21ae3c[_0x0197('0x35')];if(_0x2e1d42['query'][_0x0197('0x41')]){_0x44f3a6[_0x0197('0x42')]=[{'all':!![]}];}_0x44f3a6=_[_0x0197('0x3b')]({},_0x44f3a6,_0x2e1d42[_0x0197('0x3f')]);return db[_0x0197('0x40')]['find'](_0x44f3a6)['then'](handleEntityNotFound(_0x20dd3c,null))[_0x0197('0x26')](respondWithResult(_0x20dd3c,null))[_0x0197('0x46')](handleError(_0x20dd3c,null));};exports[_0x0197('0x47')]=function(_0x3cc4c3,_0x22d58f){return db['SquareRecording']['create'](_0x3cc4c3['body'],{})[_0x0197('0x26')](respondWithResult(_0x22d58f,0xc9))[_0x0197('0x46')](handleError(_0x22d58f,null));};exports[_0x0197('0x25')]=function(_0x3a952c,_0x1dea7a){if(_0x3a952c['body']['id']){delete _0x3a952c['body']['id'];}return db[_0x0197('0x40')][_0x0197('0x48')]({'where':{'id':_0x3a952c['params']['id']}})['then'](handleEntityNotFound(_0x1dea7a,null))[_0x0197('0x26')](saveUpdates(_0x3a952c[_0x0197('0x49')],null))[_0x0197('0x26')](respondWithResult(_0x1dea7a,null))[_0x0197('0x46')](handleError(_0x1dea7a,null));};exports['download']=function(_0x5c7107,_0x52bcee,_0x30e503){var _0x504dff=require('../../components/encryptor');var _0x104fb4=![];var _0x181f28={};if(_0x5c7107['query'][_0x0197('0x3d')]&&_0x5c7107[_0x0197('0x30')][_0x0197('0x3d')]===_0x0197('0x4a')){_0x181f28['uniqueid']=_0x5c7107[_0x0197('0x45')]['id'];}else{_0x181f28['id']=_0x5c7107[_0x0197('0x45')]['id'];}return db[_0x0197('0x40')][_0x0197('0x48')]({'where':_0x181f28,'attributes':['id',_0x0197('0x4b'),_0x0197('0x4c')],'raw':!![]})[_0x0197('0x26')](handleEntityNotFound(_0x52bcee,null))[_0x0197('0x26')](function(_0x2c6a79){if(_0x2c6a79){var _0x3c0101=_0x2c6a79[_0x0197('0x4b')];var _0x151952=util[_0x0197('0x4d')](_0x0197('0x4e'),_0x3c0101);if(fs[_0x0197('0x4f')](_0x151952)){_0x104fb4=!![];return _0x504dff['decryptFile'](_0x151952,_0x3c0101,config[_0x0197('0x50')][_0x0197('0x51')])['then'](function(){return _0x2c6a79;});}return _0x2c6a79;}})['then'](function(_0x5e8799){if(_0x5e8799){var _0x509912=_0x5e8799[_0x0197('0x4b')];if(!fs['existsSync'](_0x509912)){throw new db[(_0x0197('0x52'))]['ValidationError']('SquareRecording\x20not\x20found');}if(_0x5e8799[_0x0197('0x4c')]){return _0x52bcee[_0x0197('0x53')](_0x509912,_0x5e8799[_0x0197('0x4c')]+path[_0x0197('0x54')](_0x509912),function(){if(_0x104fb4){fs[_0x0197('0x55')](_0x509912);}});}else{return _0x52bcee[_0x0197('0x53')](_0x509912,function(_0x551e5a){if(_0x104fb4){fs[_0x0197('0x55')](_0x509912);}});}}})['catch'](function(_0x35d0aa){if(_0x35d0aa[_0x0197('0x56')]===_0x0197('0x57')){_0x52bcee[_0x0197('0x1f')](0x194)[_0x0197('0x2b')]('Not\x20found');}else{return handleError(_0x52bcee,null);}});};exports['destroy']=function(_0x7d7aca,_0x29178c){return db[_0x0197('0x40')][_0x0197('0x48')]({'where':{'id':_0x7d7aca[_0x0197('0x45')]['id']}})[_0x0197('0x26')](function(_0x3b0966){if(_[_0x0197('0x58')](_0x3b0966)){throw new ReferenceError(_0x0197('0x59'));}return _0x3b0966;})[_0x0197('0x26')](function(_0x330e8a){var _0x3713b0=_0x330e8a[_0x0197('0x4b')];logger[_0x0197('0x5a')](_0x0197('0x5b'),_0x3713b0);if(!_['isNil'](_0x330e8a[_0x0197('0x4b')])&&fs[_0x0197('0x4f')](_0x3713b0)){logger[_0x0197('0x5a')](_0x0197('0x5c')+_0x3713b0+_0x0197('0x5d'));fs[_0x0197('0x5e')](_0x3713b0);}_0x3713b0=_0x3713b0+_0x0197('0x5f');if(!_[_0x0197('0x58')](_0x330e8a[_0x0197('0x4b')])&&fs[_0x0197('0x4f')](_0x3713b0)){logger[_0x0197('0x5a')](_0x0197('0x5c')+_0x3713b0+_0x0197('0x5d'));fs[_0x0197('0x5e')](_0x3713b0);}return _0x330e8a;})['then'](function(_0x43441e){if(!_0x43441e)throw new InternalError();return _0x43441e[_0x0197('0x27')]();})['then'](function(){_0x29178c[_0x0197('0x1f')](0xcc)[_0x0197('0x19')]();})['catch'](handleError(_0x29178c,null));};