- New Postgres table schemas - Using Stored Procedures with transactions that validate business logic - User Ids now use UUID - Updated and simplified all endpoints to call the stored procedures Notes: There are still a few things missing that broke because of the migration, in particular, because we moved a lot of the business logic into the database, we now require that certain data that lived in the game-config.json to be present in the database as well, to prevent cheating and truly have a single source of truth.
31 lines
856 B
TypeScript
31 lines
856 B
TypeScript
import { postgresConnection } from "db";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import { IInventoryItem } from "typings";
|
|
import {
|
|
calculateRemainingTime,
|
|
} from "../../../../../utils/helpers";
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
try {
|
|
if (req.method === "POST") {
|
|
const { userId } = req.query;
|
|
const { stakingEventId } = req.body;
|
|
|
|
try {
|
|
const db = postgresConnection;
|
|
const result = await db.query("SELECT * FROM claim($1, $2)", [userId, stakingEventId]);
|
|
|
|
// console.log(result.rows[0].claim);
|
|
return res.status(200).json({claimEventId: result.rows[0].claim});
|
|
} catch (error) {
|
|
return res.status(400).json({error: error.message});
|
|
}
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json(error);
|
|
}
|
|
}
|