fix budget
This commit is contained in:
parent
0518e6f7d0
commit
a366dbce33
2 changed files with 8 additions and 6 deletions
11
crud.py
11
crud.py
|
|
@ -12,7 +12,8 @@ from .models import (
|
||||||
NWCBudget,
|
NWCBudget,
|
||||||
NWCKey,
|
NWCKey,
|
||||||
TrackedSpendNWC,
|
TrackedSpendNWC,
|
||||||
GetNWC
|
GetNWC,
|
||||||
|
NWCNewBudget
|
||||||
)
|
)
|
||||||
|
|
||||||
db = Database("ext_nwcprovider")
|
db = Database("ext_nwcprovider")
|
||||||
|
|
@ -31,7 +32,7 @@ async def create_nwc(data: CreateNWCKey) -> NWCKey:
|
||||||
await db.insert("nwcprovider.keys", nwckey_entry)
|
await db.insert("nwcprovider.keys", nwckey_entry)
|
||||||
if data.budgets:
|
if data.budgets:
|
||||||
for budget in data.budgets:
|
for budget in data.budgets:
|
||||||
budget_entry = NWCBudget( # fixme
|
budget_entry = NWCNewBudget( # fixme
|
||||||
pubkey=data.pubkey,
|
pubkey=data.pubkey,
|
||||||
budget_msats=budget.budget_msats,
|
budget_msats=budget.budget_msats,
|
||||||
refresh_window=budget.refresh_window,
|
refresh_window=budget.refresh_window,
|
||||||
|
|
@ -123,15 +124,15 @@ async def get_budgets_nwc(data: GetBudgetsNWC) -> Optional[NWCBudget]:
|
||||||
"""
|
"""
|
||||||
SELECT SUM(amount_msats) FROM nwcprovider.spent
|
SELECT SUM(amount_msats) FROM nwcprovider.spent
|
||||||
WHERE pubkey = :pubkey AND created_at >=
|
WHERE pubkey = :pubkey AND created_at >=
|
||||||
:last_cycle AND created_at < next_cycle
|
:last_cycle AND created_at < :next_cycle
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"pubkey": data.pubkey,
|
"pubkey": data.pubkey,
|
||||||
"last_cycle": last_cycle,
|
"last_cycle": last_cycle,
|
||||||
"next_cycle": next_cycle,
|
"next_cycle": next_cycle,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
tot_spent_in_range_msats = tot_spent_in_range_msats[0] or 0
|
tot_spent_in_range_msats = next(iter(tot_spent_in_range_msats.values())) or 0
|
||||||
budget.used_budget_msats = tot_spent_in_range_msats
|
budget.used_budget_msats = tot_spent_in_range_msats
|
||||||
return budgets
|
return budgets
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,11 @@ class NWCBudget(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class NWCNewBudget(BaseModel):
|
class NWCNewBudget(BaseModel):
|
||||||
|
pubkey: Optional[str]
|
||||||
budget_msats: int
|
budget_msats: int
|
||||||
refresh_window: int
|
refresh_window: int
|
||||||
created_at: int
|
created_at: int
|
||||||
|
|
||||||
|
|
||||||
# CRUD models
|
# CRUD models
|
||||||
class CreateNWCKey(BaseModel):
|
class CreateNWCKey(BaseModel):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue