diff --git a/.gitignore b/.gitignore index 7f4adb8..e14b93f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,4 @@ next-env.d.ts # vscode .vscode -database.db \ No newline at end of file +/database.db \ No newline at end of file diff --git a/database.db b/database.db deleted file mode 100644 index 8f668b0..0000000 Binary files a/database.db and /dev/null differ diff --git a/src/pages/api/user/[userId]/inventory-items.ts b/src/pages/api/user/[userId]/inventory-items.ts index d693f63..4dcc3f3 100644 --- a/src/pages/api/user/[userId]/inventory-items.ts +++ b/src/pages/api/user/[userId]/inventory-items.ts @@ -50,9 +50,8 @@ export default async function handler( const { itemId } = req.body; 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(invSql, [itemId, userId]); + const invItem = await db.get(`SELECT id,tier,store_item_id FROM inventory_item + WHERE id = ? AND user_id = ?`, [itemId, userId]); const storeItem = gameConfig.store.find((item) => item.id == invItem.store_item_id); if (storeItem == undefined) { @@ -71,8 +70,7 @@ export default async function handler( await db.run("BEGIN"); await db.run(`UPDATE bank_account SET balance = balance - ? WHERE user_id = ?`, [upgradePrice, userId]); - await db.run(`UPDATE inventory_item SET tier = tier + 1 - WHERE user_id = ? AND store_item_id = ?;`, [userId, itemId]); + await db.run(`UPDATE inventory_item SET tier = tier + 1 WHERE id = ?`, [itemId]); await db.run("INSERT INTO upgrade_event(inventory_item_id) VALUES ( ? )", [invItem.store_item_id]); await db.run("COMMIT"); } catch (error) { diff --git a/test-endpoints.rest b/test-endpoints.restclient similarity index 95% rename from test-endpoints.rest rename to test-endpoints.restclient index 66b1d1c..dc7a390 100644 --- a/test-endpoints.rest +++ b/test-endpoints.restclient @@ -35,7 +35,7 @@ POST http://localhost:3000/api/user/1/inventory-items/ # Upgrade an owned item PUT http://localhost:3000/api/user/1/inventory-items/ :headers -{ "itemId" : "item1" } +{ "itemId" : 1 } # Get stakes GET http://localhost:3000/api/user/1/stakes/