mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
feat: market place foundations
This commit is contained in:
@@ -157,6 +157,21 @@ export const getMarketOfferById = flopoDB.prepare(`
|
||||
WHERE market_offers.id = ?
|
||||
`);
|
||||
|
||||
export const getMarketOffersBySkin = flopoDB.prepare(`
|
||||
SELECT market_offers.*,
|
||||
skins.displayName AS skinName,
|
||||
skins.displayIcon AS skinIcon,
|
||||
seller.username AS sellerName,
|
||||
seller.globalName AS sellerGlobalName,
|
||||
buyer.username AS buyerName,
|
||||
buyer.globalName AS buyerGlobalName
|
||||
FROM market_offers
|
||||
JOIN skins ON skins.uuid = market_offers.skin_uuid
|
||||
JOIN users AS seller ON seller.id = market_offers.seller_id
|
||||
LEFT JOIN users AS buyer ON buyer.id = market_offers.buyer_id
|
||||
WHERE market_offers.skin_uuid = ?
|
||||
`);
|
||||
|
||||
export const insertMarketOffer = flopoDB.prepare(`
|
||||
INSERT INTO market_offers (id, skin_uuid, seller_id, starting_price, buyout_price, status, opening_at, closing_at)
|
||||
VALUES (@id, @skin_uuid, @seller_id, @starting_price, @buyout_price, @status, @opening_at, @closing_at)
|
||||
|
||||
@@ -6,6 +6,9 @@ import {
|
||||
getAllAkhys,
|
||||
getAllUsers,
|
||||
getLogs,
|
||||
getMarketOffersBySkin,
|
||||
getOfferBids,
|
||||
getSkin,
|
||||
getUser,
|
||||
getUserElo,
|
||||
getUserGames,
|
||||
@@ -219,6 +222,19 @@ export function apiRoutes(client, io) {
|
||||
router.get("/user/:id/inventory", (req, res) => {
|
||||
try {
|
||||
const inventory = getUserInventory.all({ user_id: req.params.id });
|
||||
inventory.forEach((skin) => {
|
||||
const marketOffers = getMarketOffersBySkin.all(skin.uuid);
|
||||
marketOffers.forEach((offer) => {
|
||||
offer.skin = getSkin.get(offer.skin_uuid);
|
||||
offer.seller = getUser.get(offer.seller_id);
|
||||
offer.buyer = getUser.get(offer.buyer_id) || null;
|
||||
offer.bids = getOfferBids.all(offer.id) || {};
|
||||
offer.bids.forEach((bid) => {
|
||||
bid.bidder = getUser.get(bid.bidder_id);
|
||||
});
|
||||
});
|
||||
skin.offers = marketOffers || {};
|
||||
});
|
||||
res.json({ inventory });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to fetch inventory." });
|
||||
|
||||
Reference in New Issue
Block a user