Skip to content

Commit

Permalink
Merge pull request #94 from NovaDrake76/dev
Browse files Browse the repository at this point in the history
fix: unshifting inv while we dont have created at at items
  • Loading branch information
NovaDrake76 authored Jun 20, 2024
2 parents 8174425 + 7fc4b69 commit 8daf91d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions backend/routes/gamesRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ module.exports = (io) => {
}

// Add the entire winning items object to the user's inventory
// user.inventory.unshift(...winningItems);

await User.updateOne(
{_id: user._id},
{
$push: {inventory: winningItems}
}
)
user.inventory.unshift(...winningItems);

// await User.updateOne(
// {_id: user._id},
// {
// $push: {inventory: winningItems}
// }
// )

updateLevel(user, caseData.price * quantityToOpen);

Expand Down
40 changes: 20 additions & 20 deletions backend/routes/userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,26 @@ router.get('/ranking', authMiddleware.isAuthenticated, async (req, res) => {


// Update wallet balance
router.put("/wallet", authMiddleware.isAuthenticated, async (req, res) => {
try {
const { amount } = req.body;

const user = await User.findById(req.user._id);

if (!user) {
return res.status(404).json({ message: "User not found" });
}

// Update wallet balance
user.walletBalance += amount;
await user.save();

res.json(user.walletBalance);
} catch (err) {
console.error(err.message);
res.status(500).send("Server error");
}
});
// router.put("/wallet", authMiddleware.isAuthenticated, async (req, res) => {
// try {
// const { amount } = req.body;

// const user = await User.findById(req.user._id);

// if (!user) {
// return res.status(404).json({ message: "User not found" });
// }

// // Update wallet balance
// user.walletBalance += amount;
// await user.save();

// res.json(user.walletBalance);
// } catch (err) {
// console.error(err.message);
// res.status(500).send("Server error");
// }
// });

// Add item to user inventory
router.post("/inventory", authMiddleware.isAuthenticated, async (req, res) => {
Expand Down

0 comments on commit 8daf91d

Please sign in to comment.