Skip to content

Commit

Permalink
Merge branch 'revert-to-avatar-page-paginate'
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 16, 2024
2 parents 5b41e69 + 27a92a5 commit 1ef0a27
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions server/functions/api/routes/shirt.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,27 @@ router.get('/user', authenticateToken, async (req, res) => {

// Fetch shirts created by user
const createdShirts = await Asset.find({
<<<<<<< HEAD
creator: user.userId,
AssetType: 'Shirt',
});
=======
creator: user._id,
AssetType: 'Shirt',
}).populate('creator', 'username');
>>>>>>> revert-to-avatar-page-paginate

console.log('Created shirts found:', createdShirts.length);

// Fetch shirts owned by user
const ownedShirts = await Asset.find({
_id: { $in: user.inventory },
AssetType: 'Shirt',
<<<<<<< HEAD
});
=======
}).populate('creator', 'username');
>>>>>>> revert-to-avatar-page-paginate

console.log('Owned shirts found:', ownedShirts.length);

Expand Down Expand Up @@ -132,6 +142,7 @@ router.get('/user', authenticateToken, async (req, res) => {
router.get('/:id', async (req, res) => {
try {
const id = req.params.id;
<<<<<<< HEAD
const shirt = await Asset.findOne({ assetId: id, AssetType: 'Shirt' });
if (!shirt) {
return res.status(404).json({ error: 'Shirt not found' });
Expand All @@ -145,6 +156,21 @@ router.get('/:id', async (req, res) => {
} catch (error) {
console.error('Error fetching shirt:', error);
res.status(500).json({ error: 'Error fetching shirt', details: error.message });
=======
const shirt = await Asset.findOne({ _id: id, AssetType: 'Shirt' }).populate(
'creator',
'username'
);
if (!shirt) {
return res.status(404).json({ error: 'Shirt not found' });
}
res.json(shirt);
} catch (error) {
console.error('Error fetching shirt:', error);
res
.status(500)
.json({ error: 'Error fetching shirt', details: error.message });
>>>>>>> revert-to-avatar-page-paginate
}
});

Expand Down Expand Up @@ -267,8 +293,13 @@ router.post(

await thumbnailQueue.addToQueue(shirtassetId, 'Shirt');

<<<<<<< HEAD
await User.findOneAndUpdate({ userId: req.user.userId }, {
$push: { shirts: shirt.assetId },
=======
await User.findByIdAndUpdate(req.user._id, {
$push: { shirts: shirt._id },
>>>>>>> revert-to-avatar-page-paginate
});

res.status(201).json({ shirtId: shirt.assetId, assetId: shirt.assetId });
Expand Down

0 comments on commit 1ef0a27

Please sign in to comment.