From d167bdb1779092a64616603cc512abd732e13a67 Mon Sep 17 00:00:00 2001 From: Milo Date: Tue, 13 May 2025 14:22:28 +0200 Subject: [PATCH] buy coins --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index 1a490ee..fe5a394 100644 --- a/index.js +++ b/index.js @@ -2824,6 +2824,22 @@ app.post('/add-coins', (req, res) => { res.status(200).json({ message : `+1000` }); }); +app.post('/buy-coins', (req, res) => { + const { commandUserId, coins } = req.body; + + const commandUser = getUser.get(commandUserId); + + if (!commandUser) return res.status(404).json({ error: 'User not found' }); + + updateUserCoins.run({ + id: commandUserId, + coins: commandUser.coins + coins, + }) + io.emit('data-updated', { table: 'users', action: 'update' }); + + res.status(200).json({ message : `+${coins}` }); +}); + import http from 'http'; import { Server } from 'socket.io'; const server = http.createServer(app);