Skip to content

Commit

Permalink
SHOP: return name of purchased item (#198)
Browse files Browse the repository at this point in the history
* nit for mobile

* return only name

* fix docs

* fix format

* oops
  • Loading branch information
lasyaneti committed Feb 15, 2024
1 parent 5dc48db commit 47532ac
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/services/shop/shop-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ shopRouter.get("/item/qr/:ITEMID", strongJwtVerification, async (req: Request, r
});

/**
* @api {post} /shop/item/buy/:ITEMID/ POST /shop/item/buy/:ITEMID/
* @api {post} /shop/item/buy/ POST /shop/item/buy/
* @apiGroup Shop
* @apiDescription Purchase item at the point shop using provided QR code.
*
Expand All @@ -278,7 +278,7 @@ shopRouter.get("/item/qr/:ITEMID", strongJwtVerification, async (req: Request, r
* }
*
* @apiUse strongVerifyErrors
* @apiError (200: Success) {String} Success Purchase was successful.
* @apiError (200: Success) {String} Success Purchase was successful. Returns purchased item name on success.
* @apiError (404: Forbidden) {String} AttendeeProfileNotFound User has no attendee profile.
* @apiError (404: Not Found) {String} ItemNotFound Item with itemId not found or already purchased.
* @apiError (404: Not Found) {String} InvalidUniqueItem This unique item is already purchased or doesn't exist.
Expand Down Expand Up @@ -321,11 +321,15 @@ shopRouter.post("/item/buy", strongJwtVerification, async (req: Request, res: Re
},
);

const targetItem = await Models.ShopItem.findOne({ itemId: itemId });

// decrement attendee coins
if (updatedShopQuantity) {
await updateCoins(userId, -itemFormat.price).then(console.error);
}
return res.status(StatusCode.SuccessOK).send({ success: true });
return res
.status(StatusCode.SuccessOK)
.send({ success: true, itemName: targetItem ? targetItem["name"] : "Item Doesn't Exist :(" });
}

return next(new RouterError(StatusCode.ClientErrorNotFound, "InvalidUniqueItem"));
Expand Down

0 comments on commit 47532ac

Please sign in to comment.