Fix staking multiple times bug and csv import bugs

This commit is contained in:
Joseph Ferano 2023-04-14 15:09:02 +07:00
parent 96d6f83c1f
commit 46580c800e
3 changed files with 21 additions and 15 deletions

View File

@ -7,8 +7,8 @@ begin
description text not null, description text not null,
image text not null, image text not null,
claimAmount integer not null, claimAmount integer not null,
basePrice integer not null,
completionTimeInMins integer not null, completionTimeInMins integer not null,
basePrice integer not null,
tier_1_price integer not null, tier_1_price integer not null,
tier_1_claimboost integer not null, tier_1_claimboost integer not null,
tier_2_price integer not null, tier_2_price integer not null,
@ -33,7 +33,13 @@ begin
perform download_sheets(); perform download_sheets();
copy storeItems from '/tmp/storeItems.csv' with (delimiter ',', format csv, header true); --- For some reason if you don't explicitly set it, it just copies it in a weird order
copy storeItems(
id, name, description, image, claimAmount, completionTimeInMins, basePrice,
tier_1_price, tier_1_claimboost, tier_2_price, tier_2_claimboost,
tier_3_price, tier_3_claimboost, tier_4_price, tier_4_claimboost,
tier_5_price, tier_5_claimboost
) from '/tmp/storeItems.csv' with (delimiter ',', format csv, header true);
copy stakingSources from '/tmp/stakingSources.csv' (delimiter ',', format csv, header true); copy stakingSources from '/tmp/stakingSources.csv' (delimiter ',', format csv, header true);
copy gameConstants from '/tmp/gameConstants.csv' with (delimiter ',', format csv, header true); copy gameConstants from '/tmp/gameConstants.csv' with (delimiter ',', format csv, header true);

View File

@ -290,7 +290,7 @@ declare
inv_id uuid; inv_id uuid;
stake_id uuid; stake_id uuid;
stake_created_at timestamp; stake_created_at timestamp;
stake_amount integer; total_stake_amount integer;
begin begin
select completion_time_in_mins select completion_time_in_mins
into item_stake_duration into item_stake_duration
@ -299,12 +299,12 @@ begin
where inventory_item.id = p_inventory_item_id; where inventory_item.id = p_inventory_item_id;
select select
inventory_item.id as inv_id, inventory_item.id,
staking_event.id as stake_id, staking_event.id,
staking_event.created_at as stake_created_at staking_event.created_at
from inventory_item from inventory_item
left join staking_event left join staking_event
on staking_event.inventory_item_id = inv_id on staking_event.inventory_item_id = inventory_item.id
where inventory_item.id = p_inventory_item_id and inventory_item.user_id = p_user_id where inventory_item.id = p_inventory_item_id and inventory_item.user_id = p_user_id
order by stake_created_at desc limit 1 order by stake_created_at desc limit 1
into inv_id, stake_id, stake_created_at; into inv_id, stake_id, stake_created_at;
@ -321,16 +321,16 @@ begin
using message = 'Unable to find an inventory item that is owned and not actively staked'; using message = 'Unable to find an inventory item that is owned and not actively staked';
end if; end if;
select claim_amount + claim_boost select claim_amount
into stake_amount into total_stake_amount
from inventory_item from inventory_item
join store_item on inventory_item.store_item_id = store_item.id join store_item on inventory_item.store_item_id = store_item.id
join upgrade_item on store_item.id = upgrade_item.store_item_id left join upgrade_item on store_item.id = upgrade_item.store_item_id
and upgrade_item.tier = inventory_item.tier and upgrade_item.tier = inventory_item.tier
where inventory_item.id = p_inventory_item_id; where inventory_item.id = p_inventory_item_id;
insert into staking_event(user_id, well_id, inventory_item_id, duration_in_mins, stake_amount) insert into staking_event(user_id, well_id, inventory_item_id, duration_in_mins, stake_amount)
values (p_user_id, p_well_id, p_inventory_item_id, item_stake_duration, stake_amount) values (p_user_id, p_well_id, p_inventory_item_id, item_stake_duration, total_stake_amount)
returning id into staking_event_id; returning id into staking_event_id;
return staking_event_id; return staking_event_id;

View File

@ -40,7 +40,7 @@ PUT http://localhost:3000/api/user/:user_id/account
POST http://localhost:3000/api/user/:user_id/clear-data POST http://localhost:3000/api/user/:user_id/clear-data
:headers :headers
# Get bank account # Get leaderboards
GET http://localhost:3000/api/leaderboards GET http://localhost:3000/api/leaderboards
:headers :headers
@ -64,7 +64,7 @@ POST http://localhost:3000/api/user/:user_id/inventory-items/
# Upgrade an owned item # Upgrade an owned item
PUT http://localhost:3000/api/user/:user_id/inventory-items/ PUT http://localhost:3000/api/user/:user_id/inventory-items/
:headers :headers
{ "inventoryItemId": "26e4b397-2b01-4c73-a14e-4ea4ae3ec1a5" } { "inventoryItemId": "2bd5f846-ce1d-45be-998e-26d2e97b7f68" }
# Get stakes # Get stakes
GET http://localhost:3000/api/user/:user_id/stakes/ GET http://localhost:3000/api/user/:user_id/stakes/
@ -73,8 +73,8 @@ GET http://localhost:3000/api/user/:user_id/stakes/
# Start a stake # Start a stake
POST http://localhost:3000/api/user/:user_id/stakes/start POST http://localhost:3000/api/user/:user_id/stakes/start
:headers :headers
{ "inventoryItemId": "26e4b397-2b01-4c73-a14e-4ea4ae3ec1a5" { "inventoryItemId": "2bd5f846-ce1d-45be-998e-26d2e97b7f68"
, "wellId": "ea4ad43c-d153-4fd4-819d-3c0339102d1e" } , "wellId": "588ad177-83ca-4a5f-9672-bf97783ea42f" }
# Claim a stake # Claim a stake
POST http://localhost:3000/api/user/:user_id/stakes/claim POST http://localhost:3000/api/user/:user_id/stakes/claim