update nice visuel
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { Router } from 'express';
|
||||
import { requireAuth } from '../middleware.js';
|
||||
import {
|
||||
getJackpotState,
|
||||
listJackpotBattles,
|
||||
getJackpotRound,
|
||||
createJackpotBattle,
|
||||
placeJackpotBet,
|
||||
withdrawJackpotBet,
|
||||
} from '../services/jackpot.js';
|
||||
@@ -16,25 +18,58 @@ function handleError(res, err) {
|
||||
|
||||
router.get('/', async (_req, res) => {
|
||||
try {
|
||||
const state = await getJackpotState();
|
||||
res.json({ round: state });
|
||||
const battles = await listJackpotBattles();
|
||||
res.json({ battles });
|
||||
} catch (err) {
|
||||
handleError(res, err);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const round = await getJackpotRound(req.params.id);
|
||||
if (!round) {
|
||||
return res.status(404).json({ error: 'Battle not found' });
|
||||
}
|
||||
res.json({ round });
|
||||
} catch (err) {
|
||||
handleError(res, err);
|
||||
}
|
||||
});
|
||||
|
||||
/** Create a battle by placing the first bet (no round id). */
|
||||
router.post('/bet', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const state = await placeJackpotBet(req.session.userId, req.body.inventoryItemIds);
|
||||
const state = await createJackpotBattle(
|
||||
req.session.userId,
|
||||
req.body.inventoryItemIds
|
||||
);
|
||||
res.json({ round: state });
|
||||
} catch (err) {
|
||||
handleError(res, err);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/withdraw', requireAuth, async (req, res) => {
|
||||
router.post('/:id/bet', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const state = await withdrawJackpotBet(req.session.userId, req.body.inventoryItemIds);
|
||||
const state = await placeJackpotBet(
|
||||
req.params.id,
|
||||
req.session.userId,
|
||||
req.body.inventoryItemIds
|
||||
);
|
||||
res.json({ round: state });
|
||||
} catch (err) {
|
||||
handleError(res, err);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:id/withdraw', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const state = await withdrawJackpotBet(
|
||||
req.params.id,
|
||||
req.session.userId,
|
||||
req.body.inventoryItemIds
|
||||
);
|
||||
res.json({ round: state });
|
||||
} catch (err) {
|
||||
handleError(res, err);
|
||||
|
||||
Reference in New Issue
Block a user