mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-31 06:32:37 +00:00
This initial commit should work
This commit is contained in:
@@ -376,6 +376,31 @@ app.put('/api/user/rename', async (req, res)=>{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Delete brews based on author
|
||||||
|
app.delete('/api/user/delete', async (req, res)=>{
|
||||||
|
const { username } = req.body;
|
||||||
|
const ownAccount = req.account && (req.account.username == username);
|
||||||
|
|
||||||
|
if(!username)
|
||||||
|
return res.status(400).json({ error: 'Username and newUsername are required.' });
|
||||||
|
if(!ownAccount)
|
||||||
|
return res.status(403).json({ error: 'Must be logged in to change your username' });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const brews = await HomebrewModel.getByUser(username, true, ['authors']);
|
||||||
|
await brews.forEach((brew)=>{
|
||||||
|
request.delete(`/api/${brew.googleId ?? ''}${brew.editId}`).send().end((err, res)=>{
|
||||||
|
if (err) reportError(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.json({ success: true, message: `Brews for ${username} renamed to ${newUsername}.` });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error renaming brews:', error);
|
||||||
|
return res.status(500).json({ error: 'Failed to rename brews.' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Edit Page
|
//Edit Page
|
||||||
app.get('/edit/:id', asyncHandler(getBrew('edit')), asyncHandler(async(req, res, next)=>{
|
app.get('/edit/:id', asyncHandler(getBrew('edit')), asyncHandler(async(req, res, next)=>{
|
||||||
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
||||||
|
|||||||
Reference in New Issue
Block a user