From 948f03b5b86bc9c8cc3fbdf1b2fc07726dbfb394 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 25 Oct 2024 11:18:36 +1300 Subject: [PATCH] Add admin access type to getBrew --- server/homebrew.api.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 213b341ca..c6c9ab0f8 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -87,8 +87,18 @@ const api = { // Get relevant IDs for the brew const { id, googleId } = api.getId(req); + const accessMap = { + edit : { editId: id }, + share : { shareId: id }, + admin : { + $or : [ + { editId: { $regex: req.params.id, $options: 'i' } }, + { shareId: { $regex: req.params.id, $options: 'i' } }, + ] } + }; + // Try to find the document in the Homebrewery database -- if it doesn't exist, that's fine. - let stub = await HomebrewModel.get(accessType === 'edit' ? { editId: id } : { shareId: id }) + let stub = await HomebrewModel.get(accessMap[accessType]) .catch((err)=>{ if(googleId) { console.warn(`Unable to find document stub for ${accessType}Id ${id}`);