0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-15 17:02:38 +00:00

Apply asyncHandler to getBrewFromId

This commit is contained in:
Trevor Buckner
2021-03-26 22:55:46 -04:00
parent 83c444ce11
commit ab473b12da

View File

@@ -11,22 +11,20 @@ const sanitizeFilename = require('sanitize-filename');
const asyncHandler = require('express-async-handler'); const asyncHandler = require('express-async-handler');
//Get the brew object from the HB database or Google Drive //Get the brew object from the HB database or Google Drive
const getBrewFromId = async (id, accessType)=>{ const getBrewFromId = asyncHandler(async (id, accessType)=>{
if(accessType !== 'edit' && accessType !== 'share') if(accessType !== 'edit' && accessType !== 'share')
throw ('Invalid Access Type when getting brew'); throw ('Invalid Access Type when getting brew');
let brew; let brew;
if(id.length > 12) { if(id.length > 12) {
const googleId = id.slice(0, -12); const googleId = id.slice(0, -12);
id = id.slice(-12); id = id.slice(-12);
brew = await GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, id, accessType) brew = await GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, id, accessType);
.catch((err)=>{throw err;});
} else { } else {
brew = await HomebrewModel.get(accessType == 'edit' ? { editId: id } : { shareId: id }) brew = await HomebrewModel.get(accessType == 'edit' ? { editId: id } : { shareId: id });
.catch((err)=>{throw err;});
brew.sanatize(true); brew.sanatize(true);
} }
return brew; return brew;
}; });
app.use('/', serveCompressedStaticAssets(`${__dirname}/build`)); app.use('/', serveCompressedStaticAssets(`${__dirname}/build`));