add storeItemId to inventory-items PUT
This commit is contained in:
parent
e90c0c9809
commit
63a92b90da
@ -5,7 +5,7 @@ import Image from "next/image";
|
|||||||
const InventoryItem = (props: {
|
const InventoryItem = (props: {
|
||||||
inventoryItem: IInventoryItem;
|
inventoryItem: IInventoryItem;
|
||||||
stakes: IStake[] | null;
|
stakes: IStake[] | null;
|
||||||
upgradeInventoryItem: (itemId: number) => void;
|
upgradeInventoryItem: (inventoryItemId: number, storeItemId: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const [currentTierIndex, setCurrentTierIndex] = useState(
|
const [currentTierIndex, setCurrentTierIndex] = useState(
|
||||||
props.inventoryItem.currentTierIndex
|
props.inventoryItem.currentTierIndex
|
||||||
@ -76,7 +76,10 @@ const InventoryItem = (props: {
|
|||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
props.upgradeInventoryItem(props.inventoryItem.id)
|
props.upgradeInventoryItem(
|
||||||
|
props.inventoryItem.id,
|
||||||
|
props.inventoryItem.storeItem.id
|
||||||
|
)
|
||||||
}
|
}
|
||||||
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold text-center"
|
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold text-center"
|
||||||
>
|
>
|
||||||
|
@ -5,7 +5,7 @@ import InventoryItem from "./InventoryItem";
|
|||||||
const InventoryItemView = (props: {
|
const InventoryItemView = (props: {
|
||||||
stakes: IStake[] | null;
|
stakes: IStake[] | null;
|
||||||
inventoryItems: IInventoryItem[] | null | undefined;
|
inventoryItems: IInventoryItem[] | null | undefined;
|
||||||
upgradeInventoryItem: (itemId: number) => void;
|
upgradeInventoryItem: (inventoryItemId: number, storeItemId: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<div className="bg-slate-800 text-white p-4 rounded-lg">
|
<div className="bg-slate-800 text-white p-4 rounded-lg">
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { IStoreItem } from "typings";
|
import { IStoreItem } from "typings";
|
||||||
import CommonCardLayout from "../Layouts/CommonCardLayout";
|
import CommonCardLayout from "../Layouts/CommonCardLayout";
|
||||||
import Chart from "./Chart";
|
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
|
||||||
const StoreItem = (props: {
|
const StoreItem = (props: {
|
||||||
|
@ -64,7 +64,8 @@ export default function RootLayout({
|
|||||||
{walletAddress.length === 0 ? (
|
{walletAddress.length === 0 ? (
|
||||||
<button
|
<button
|
||||||
onClick={connectWallet}
|
onClick={connectWallet}
|
||||||
className="p-2 m-4 bg-slate-800 rounded-lg">
|
className="p-2 m-4 bg-slate-800 rounded-lg"
|
||||||
|
>
|
||||||
Connect Wallet
|
Connect Wallet
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
|
@ -225,13 +225,17 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const upgradeInventoryItem = async (itemId: number) => {
|
const upgradeInventoryItem = async (
|
||||||
|
inventoryItemId: number,
|
||||||
|
storeItemId: string
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/user/${userId}/inventory-items`, {
|
const response = await fetch(`/api/user/${userId}/inventory-items`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
itemId: itemId,
|
inventoryItemId: inventoryItemId,
|
||||||
|
storeItemId: storeItemId,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -280,7 +284,7 @@ export default function Home() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!userId) return <p>Please login</p>;
|
if (!userId) return <p>Please login</p>;
|
||||||
//console.log(stakingSources);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{notification && (
|
{notification && (
|
||||||
|
@ -47,11 +47,11 @@ export default async function handler(
|
|||||||
} else if (req.method === "PUT") {
|
} else if (req.method === "PUT") {
|
||||||
// Upgrade an existing item
|
// Upgrade an existing item
|
||||||
const { userId } = req.query;
|
const { userId } = req.query;
|
||||||
const { itemId } = req.body;
|
const { inventoryItemId, storeItemId } = req.body;
|
||||||
const db = await dbConnection;
|
const db = await dbConnection;
|
||||||
|
|
||||||
const invItem = await db.get(`SELECT id,tier,store_item_id FROM inventory_item
|
const invItem = await db.get(`SELECT id,tier,store_item_id FROM inventory_item
|
||||||
WHERE id = ? AND user_id = ?`, [itemId, userId]);
|
WHERE id = ? AND user_id = ?`, [inventoryItemId, 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) {
|
||||||
@ -70,7 +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 WHERE id = ?`, [itemId]);
|
await db.run(`UPDATE inventory_item SET tier = tier + 1 WHERE id = ?`, [inventoryItemId]);
|
||||||
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user