79d29a77df2e531c2a60d4b322f2164c50654a9d
[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 _0x64f3=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','save','destroy','then','error','stack','send','map','SquareRecording','fieldName','type','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','name','filter','merge','options','includeAll','include','findAll','rows','show','params','keys','rawAttributes','find','catch','create','body','../../components/encryptor','uniqueid','savePath','filename','format','decryptFile','secrets','recording','existsSync','Sequelize','ValidationError','SquareRecording\x20not\x20found','download','extname','unlink','message','Not\x20found','Entity\x20not\x20found','info','cancellazione\x20fisica\x20documento\x20%s','isNil','File:\x20\x22','\x22\x20trovato\x20eseguo\x20la\x20cancellazione','.cypher','eml-format','rimraf','util','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs'];(function(_0x18a203,_0x10430e){var _0x1b0743=function(_0x283fe9){while(--_0x283fe9){_0x18a203['push'](_0x18a203['shift']());}};_0x1b0743(++_0x10430e);}(_0x64f3,0x160));var _0x364f=function(_0x36e3cd,_0x4ff225){_0x36e3cd=_0x36e3cd-0x0;var _0x19f9d6=_0x64f3[_0x36e3cd];return _0x19f9d6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x364f('0x0'));var rimraf=require(_0x364f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x364f('0x2'));var path=require('path');var sox=require(_0x364f('0x3'));var csv=require(_0x364f('0x4'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x364f('0x5'));var squel=require(_0x364f('0x6'));var crypto=require(_0x364f('0x7'));var jsforce=require(_0x364f('0x8'));var deskjs=require(_0x364f('0x9'));var toCsv=require(_0x364f('0x4'));var querystring=require('querystring');var Papa=require(_0x364f('0xa'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x364f('0xb'));var as=require(_0x364f('0xc'));var hardwareService=require(_0x364f('0xd'));var logger=require(_0x364f('0xe'))('api');var utils=require(_0x364f('0xf'));var config=require(_0x364f('0x10'));var db=require(_0x364f('0x11'))['db'];function respondWithStatusCode(_0x20ff84,_0x3c47b2){_0x3c47b2=_0x3c47b2||0xcc;return function(_0x5d341f){if(_0x5d341f){return _0x20ff84[_0x364f('0x12')](_0x3c47b2);}return _0x20ff84[_0x364f('0x13')](_0x3c47b2)[_0x364f('0x14')]();};}function respondWithResult(_0x56d9ab,_0x5e5f9b){_0x5e5f9b=_0x5e5f9b||0xc8;return function(_0x5ee894){if(_0x5ee894){return _0x56d9ab[_0x364f('0x13')](_0x5e5f9b)[_0x364f('0x15')](_0x5ee894);}};}function respondWithFilteredResult(_0x228df1,_0x1890fa){return function(_0x25a8f5){if(_0x25a8f5){var _0xce7505=_0x25a8f5[_0x364f('0x16')],_0x3ed3af=_0x1890fa[_0x364f('0x17')],_0x3e1d74=_0x1890fa[_0x364f('0x17')]+_0x1890fa[_0x364f('0x18')],_0x4b55ab;if(_0x3e1d74>=_0xce7505){_0x3e1d74=_0xce7505;_0x4b55ab=0xc8;}else{_0x4b55ab=0xce;}_0x228df1[_0x364f('0x13')](_0x4b55ab);return _0x228df1[_0x364f('0x19')]('Content-Range',_0x3ed3af+'-'+_0x3e1d74+'/'+_0xce7505)[_0x364f('0x15')](_0x25a8f5);}return null;};}function patchUpdates(_0x5a1654){return function(_0x22c437){try{jsonpatch[_0x364f('0x1a')](_0x22c437,_0x5a1654,!![]);}catch(_0x5da2ff){return BPromise['reject'](_0x5da2ff);}return _0x22c437[_0x364f('0x1b')]();};}function saveUpdates(_0x2437a3,_0x5db011){return function(_0x36422c){if(_0x36422c){return _0x36422c['update'](_0x2437a3)['then'](function(_0x4b1abe){return _0x4b1abe;});}return null;};}function removeEntity(_0x4cf407,_0x47e4a3){return function(_0x1dc799){if(_0x1dc799){return _0x1dc799[_0x364f('0x1c')]()[_0x364f('0x1d')](function(){_0x4cf407[_0x364f('0x13')](0xcc)[_0x364f('0x14')]();});}};}function handleEntityNotFound(_0x4ea6ae,_0x2103a2){return function(_0x1dae8f){if(!_0x1dae8f){_0x4ea6ae[_0x364f('0x12')](0x194);}return _0x1dae8f;};}function handleError(_0x36838b,_0x4fe691){_0x4fe691=_0x4fe691||0x1f4;return function(_0x3d384d){logger[_0x364f('0x1e')](_0x3d384d[_0x364f('0x1f')]);if(_0x3d384d['name']){delete _0x3d384d['name'];}_0x36838b['status'](_0x4fe691)[_0x364f('0x20')](_0x3d384d);};}exports['index']=function(_0x400cb9,_0x57d81e){var _0x46b641={},_0x261b33={},_0x20b437={'count':0x0,'rows':[]};var _0x244798=_[_0x364f('0x21')](db[_0x364f('0x22')]['rawAttributes'],function(_0x33ecae){return{'name':_0x33ecae[_0x364f('0x23')],'type':_0x33ecae[_0x364f('0x24')]['key']};});_0x261b33['model']=_['map'](_0x244798,'name');_0x261b33[_0x364f('0x25')]=_['keys'](_0x400cb9[_0x364f('0x25')]);_0x261b33[_0x364f('0x26')]=_[_0x364f('0x27')](_0x261b33[_0x364f('0x28')],_0x261b33[_0x364f('0x25')]);_0x46b641['attributes']=_[_0x364f('0x27')](_0x261b33[_0x364f('0x28')],qs[_0x364f('0x29')](_0x400cb9[_0x364f('0x25')][_0x364f('0x29')]));_0x46b641[_0x364f('0x2a')]=_0x46b641[_0x364f('0x2a')][_0x364f('0x2b')]?_0x46b641[_0x364f('0x2a')]:_0x261b33['model'];if(!_0x400cb9[_0x364f('0x25')][_0x364f('0x2c')](_0x364f('0x2d'))){_0x46b641[_0x364f('0x18')]=qs[_0x364f('0x18')](_0x400cb9[_0x364f('0x25')]['limit']);_0x46b641['offset']=qs[_0x364f('0x17')](_0x400cb9[_0x364f('0x25')]['offset']);}_0x46b641[_0x364f('0x2e')]=qs[_0x364f('0x2f')](_0x400cb9[_0x364f('0x25')][_0x364f('0x2f')]);_0x46b641[_0x364f('0x30')]=qs['filters'](_[_0x364f('0x31')](_0x400cb9['query'],_0x261b33['filters']),_0x244798);if(_0x400cb9['query']['filter']){_0x46b641[_0x364f('0x30')]=_['merge'](_0x46b641[_0x364f('0x30')],{'$or':_[_0x364f('0x21')](_0x244798,function(_0x24e826){if(_0x24e826[_0x364f('0x24')]!==_0x364f('0x32')){var _0x3e5903={};_0x3e5903[_0x24e826[_0x364f('0x33')]]={'$like':'%'+_0x400cb9['query'][_0x364f('0x34')]+'%'};return _0x3e5903;}})});}_0x46b641=_[_0x364f('0x35')]({},_0x46b641,_0x400cb9[_0x364f('0x36')]);var _0x454197={'where':_0x46b641[_0x364f('0x30')]};return db[_0x364f('0x22')][_0x364f('0x16')](_0x454197)[_0x364f('0x1d')](function(_0xdd7130){_0x20b437[_0x364f('0x16')]=_0xdd7130;if(_0x400cb9[_0x364f('0x25')][_0x364f('0x37')]){_0x46b641[_0x364f('0x38')]=[{'all':!![]}];}return db[_0x364f('0x22')][_0x364f('0x39')](_0x46b641);})[_0x364f('0x1d')](function(_0x412bed){_0x20b437[_0x364f('0x3a')]=_0x412bed;return _0x20b437;})[_0x364f('0x1d')](respondWithFilteredResult(_0x57d81e,_0x46b641))['catch'](handleError(_0x57d81e,null));};exports[_0x364f('0x3b')]=function(_0x2bd58d,_0x5e2e36){var _0x1b6173={'raw':!![],'where':{'id':_0x2bd58d[_0x364f('0x3c')]['id']}},_0x4dfd04={};_0x4dfd04[_0x364f('0x28')]=_[_0x364f('0x3d')](db['SquareRecording'][_0x364f('0x3e')]);_0x4dfd04[_0x364f('0x25')]=_[_0x364f('0x3d')](_0x2bd58d['query']);_0x4dfd04[_0x364f('0x26')]=_[_0x364f('0x27')](_0x4dfd04[_0x364f('0x28')],_0x4dfd04['query']);_0x1b6173[_0x364f('0x2a')]=_[_0x364f('0x27')](_0x4dfd04[_0x364f('0x28')],qs[_0x364f('0x29')](_0x2bd58d[_0x364f('0x25')][_0x364f('0x29')]));_0x1b6173[_0x364f('0x2a')]=_0x1b6173['attributes']['length']?_0x1b6173[_0x364f('0x2a')]:_0x4dfd04[_0x364f('0x28')];if(_0x2bd58d[_0x364f('0x25')][_0x364f('0x37')]){_0x1b6173[_0x364f('0x38')]=[{'all':!![]}];}_0x1b6173=_['merge']({},_0x1b6173,_0x2bd58d[_0x364f('0x36')]);return db[_0x364f('0x22')][_0x364f('0x3f')](_0x1b6173)['then'](handleEntityNotFound(_0x5e2e36,null))[_0x364f('0x1d')](respondWithResult(_0x5e2e36,null))[_0x364f('0x40')](handleError(_0x5e2e36,null));};exports[_0x364f('0x41')]=function(_0xdc0bc9,_0x291f4a){return db[_0x364f('0x22')]['create'](_0xdc0bc9[_0x364f('0x42')],{})['then'](respondWithResult(_0x291f4a,0xc9))['catch'](handleError(_0x291f4a,null));};exports['update']=function(_0x143f39,_0x1445e6){if(_0x143f39[_0x364f('0x42')]['id']){delete _0x143f39[_0x364f('0x42')]['id'];}return db[_0x364f('0x22')][_0x364f('0x3f')]({'where':{'id':_0x143f39[_0x364f('0x3c')]['id']}})[_0x364f('0x1d')](handleEntityNotFound(_0x1445e6,null))['then'](saveUpdates(_0x143f39[_0x364f('0x42')],null))[_0x364f('0x1d')](respondWithResult(_0x1445e6,null))[_0x364f('0x40')](handleError(_0x1445e6,null));};exports['download']=function(_0x9372ef,_0x323aa6,_0x337890){var _0x3514e4=require(_0x364f('0x43'));var _0x58542b=![];var _0x279d31={};if(_0x9372ef['query']['type']&&_0x9372ef[_0x364f('0x25')][_0x364f('0x24')]===_0x364f('0x44')){_0x279d31[_0x364f('0x44')]=_0x9372ef[_0x364f('0x3c')]['id'];}else{_0x279d31['id']=_0x9372ef['params']['id'];}return db[_0x364f('0x22')][_0x364f('0x3f')]({'where':_0x279d31,'attributes':['id',_0x364f('0x45'),_0x364f('0x46')],'raw':!![]})[_0x364f('0x1d')](handleEntityNotFound(_0x323aa6,null))[_0x364f('0x1d')](function(_0xf3328){if(_0xf3328){var _0x2969a4=_0xf3328[_0x364f('0x45')];var _0x3999fc=util[_0x364f('0x47')]('%s.cypher',_0x2969a4);if(fs['existsSync'](_0x3999fc)){_0x58542b=!![];return _0x3514e4[_0x364f('0x48')](_0x3999fc,_0x2969a4,config[_0x364f('0x49')][_0x364f('0x4a')])[_0x364f('0x1d')](function(){return _0xf3328;});}return _0xf3328;}})[_0x364f('0x1d')](function(_0x47617e){if(_0x47617e){var _0x102e9e=_0x47617e[_0x364f('0x45')];if(!fs[_0x364f('0x4b')](_0x102e9e)){throw new db[(_0x364f('0x4c'))][(_0x364f('0x4d'))](_0x364f('0x4e'));}if(_0x47617e[_0x364f('0x46')]){return _0x323aa6[_0x364f('0x4f')](_0x102e9e,_0x47617e[_0x364f('0x46')]+path[_0x364f('0x50')](_0x102e9e),function(){if(_0x58542b){fs[_0x364f('0x51')](_0x102e9e);}});}else{return _0x323aa6['download'](_0x102e9e,function(_0x9d3d03){if(_0x58542b){fs[_0x364f('0x51')](_0x102e9e);}});}}})[_0x364f('0x40')](function(_0x284c53){if(_0x284c53[_0x364f('0x52')]===_0x364f('0x4e')){_0x323aa6['status'](0x194)[_0x364f('0x20')](_0x364f('0x53'));}else{return handleError(_0x323aa6,null);}});};exports['destroy']=function(_0x15078e,_0x5533af){return db[_0x364f('0x22')]['find']({'where':{'id':_0x15078e[_0x364f('0x3c')]['id']}})[_0x364f('0x1d')](function(_0x1efe3a){if(!_0x1efe3a)throw new ReferenceError(_0x364f('0x54'));return _0x1efe3a;})[_0x364f('0x1d')](function(_0x111611){var _0x302448=_0x111611['savePath'];logger[_0x364f('0x55')](_0x364f('0x56'),_0x302448);if(!_[_0x364f('0x57')](_0x111611[_0x364f('0x45')])&&fs[_0x364f('0x4b')](_0x302448)){logger[_0x364f('0x55')](_0x364f('0x58')+_0x302448+_0x364f('0x59'));fs['unlinkSync'](_0x302448);}_0x302448=_0x302448+_0x364f('0x5a');if(!_[_0x364f('0x57')](_0x111611[_0x364f('0x45')])&&fs['existsSync'](_0x302448)){logger['info'](_0x364f('0x58')+_0x302448+_0x364f('0x59'));fs['unlinkSync'](_0x302448);}return _0x111611;})[_0x364f('0x1d')](function(_0xb0d01a){if(!_0xb0d01a)throw new InternalError();return _0xb0d01a[_0x364f('0x1c')]();})[_0x364f('0x1d')](function(){_0x5533af[_0x364f('0x13')](0xcc)[_0x364f('0x14')]();})[_0x364f('0x40')](handleError(_0x5533af,null));};