Update upgrading to use the inventory item DB id

This commit is contained in:
Joseph Ferano 2023-03-21 10:40:49 +07:00
parent 406a0e0c89
commit 87a188a814
4 changed files with 5 additions and 7 deletions

2
.gitignore vendored
View File

@ -38,4 +38,4 @@ next-env.d.ts
# vscode # vscode
.vscode .vscode
database.db /database.db

Binary file not shown.

View File

@ -50,9 +50,8 @@ export default async function handler(
const { itemId } = req.body; const { itemId } = req.body;
const db = await dbConnection; const db = await dbConnection;
const invSql = "SELECT id,tier,store_item_id FROM inventory_item WHERE id = ? AND user_id = ?"; const invItem = await db.get(`SELECT id,tier,store_item_id FROM inventory_item
WHERE id = ? AND user_id = ?`, [itemId, userId]);
const invItem = await db.get(invSql, [itemId, userId]);
const storeItem = gameConfig.store.find((item) => item.id == invItem.store_item_id); const storeItem = gameConfig.store.find((item) => item.id == invItem.store_item_id);
if (storeItem == undefined) { if (storeItem == undefined) {
@ -71,8 +70,7 @@ export default async function handler(
await db.run("BEGIN"); await db.run("BEGIN");
await db.run(`UPDATE bank_account SET balance = balance - ? await db.run(`UPDATE bank_account SET balance = balance - ?
WHERE user_id = ?`, [upgradePrice, userId]); WHERE user_id = ?`, [upgradePrice, userId]);
await db.run(`UPDATE inventory_item SET tier = tier + 1 await db.run(`UPDATE inventory_item SET tier = tier + 1 WHERE id = ?`, [itemId]);
WHERE user_id = ? AND store_item_id = ?;`, [userId, itemId]);
await db.run("INSERT INTO upgrade_event(inventory_item_id) VALUES ( ? )", [invItem.store_item_id]); await db.run("INSERT INTO upgrade_event(inventory_item_id) VALUES ( ? )", [invItem.store_item_id]);
await db.run("COMMIT"); await db.run("COMMIT");
} catch (error) { } catch (error) {

View File

@ -35,7 +35,7 @@ POST http://localhost:3000/api/user/1/inventory-items/
# Upgrade an owned item # Upgrade an owned item
PUT http://localhost:3000/api/user/1/inventory-items/ PUT http://localhost:3000/api/user/1/inventory-items/
:headers :headers
{ "itemId" : "item1" } { "itemId" : 1 }
# Get stakes # Get stakes
GET http://localhost:3000/api/user/1/stakes/ GET http://localhost:3000/api/user/1/stakes/