feat: market place foundations

This commit is contained in:
Milo
2025-11-24 10:17:01 +01:00
parent 8672c90fe2
commit 789f7cadb7
2 changed files with 31 additions and 0 deletions

View File

@@ -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)

View File

@@ -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." });