Get game config endpoint
This commit is contained in:
parent
46580c800e
commit
2f809bf889
@ -119,6 +119,47 @@ begin
|
|||||||
end;
|
end;
|
||||||
$$ language plpgsql;
|
$$ language plpgsql;
|
||||||
|
|
||||||
|
create or replace function get_game_config()
|
||||||
|
returns table (
|
||||||
|
resources json,
|
||||||
|
"gameConstants" json,
|
||||||
|
"stakingSources" json,
|
||||||
|
"storeItems" json
|
||||||
|
)
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
select json_agg(name) into resources from resource;
|
||||||
|
select json_object_agg(key, value) into "gameConstants" from game_constants;
|
||||||
|
select json_agg(staking_source_item) into "stakingSources" from staking_source_item;
|
||||||
|
select json_agg(
|
||||||
|
json_build_object(
|
||||||
|
'id', store_item.id,
|
||||||
|
'name', store_item.name,
|
||||||
|
'description', store_item.description,
|
||||||
|
'price', store_item.price,
|
||||||
|
'image', store_item.image_name,
|
||||||
|
'claimAmount', store_item.claim_amount,
|
||||||
|
'completionTimeInMins', store_item.completion_time_in_mins,
|
||||||
|
'upgrades', upgrades
|
||||||
|
) order by store_item.id
|
||||||
|
) into "storeItems"
|
||||||
|
from store_item
|
||||||
|
join (
|
||||||
|
select store_item_id, json_agg(
|
||||||
|
json_build_object(
|
||||||
|
'tier', tier,
|
||||||
|
'price', upgrade_item.price,
|
||||||
|
'claimBoost', claim_boost
|
||||||
|
) order by upgrade_item.tier
|
||||||
|
) as upgrades
|
||||||
|
from upgrade_item
|
||||||
|
group by store_item_id
|
||||||
|
) u on u.store_item_id = store_item.id;
|
||||||
|
return next;
|
||||||
|
|
||||||
|
end;
|
||||||
|
$$ language plpgsql;
|
||||||
|
|
||||||
create or replace function get_staking_sources(user_id uuid)
|
create or replace function get_staking_sources(user_id uuid)
|
||||||
returns table (
|
returns table (
|
||||||
id uuid,
|
id uuid,
|
||||||
|
22
src/pages/api/get-game-config.ts
Normal file
22
src/pages/api/get-game-config.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { postgresConnection } from "db";
|
||||||
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
if (req.method === "GET") {
|
||||||
|
const db = postgresConnection;
|
||||||
|
|
||||||
|
const result = await db.query("select * from get_game_config()");
|
||||||
|
if (result.rowCount > 0) {
|
||||||
|
return res.status(200).json(result.rows[0]);
|
||||||
|
} else {
|
||||||
|
return res.status(404).json({ message: "Something went wrong" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,10 @@ POST http://localhost:3000/api/user/:user_id/clear-data
|
|||||||
GET http://localhost:3000/api/leaderboards
|
GET http://localhost:3000/api/leaderboards
|
||||||
:headers
|
:headers
|
||||||
|
|
||||||
|
# Get game config
|
||||||
|
GET http://localhost:3000/api/get-game-config
|
||||||
|
:headers
|
||||||
|
|
||||||
# Get Staking Sources
|
# Get Staking Sources
|
||||||
GET http://localhost:3000/api/user/:user_id/staking-sources
|
GET http://localhost:3000/api/user/:user_id/staking-sources
|
||||||
:headers
|
:headers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user