Change user to user_id in satspay settings table and fixed first use bug
This commit is contained in:
parent
b51bc492fb
commit
72cf6b9b79
|
@ -100,17 +100,6 @@ async def get_charges(user: str) -> List[Charges]:
|
|||
return [Charges.from_row(row) for row in rows]
|
||||
|
||||
|
||||
async def get_settings(user: str) -> SatsPaySettings:
|
||||
row = await db.fetchone(
|
||||
"""SELECT * FROM satspay.settings WHERE "user" = ?""",
|
||||
(user,),
|
||||
)
|
||||
if row:
|
||||
return SatsPaySettings.from_row(row)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
async def delete_charge(charge_id: str) -> None:
|
||||
await db.execute("DELETE FROM satspay.charges WHERE id = ?", (charge_id,))
|
||||
|
||||
|
@ -135,30 +124,41 @@ async def check_address_balance(charge_id: str) -> Optional[Charges]:
|
|||
|
||||
|
||||
################## SETTINGS ###################
|
||||
async def save_settings(user: str, data: SatsPaySettings):
|
||||
async def save_settings(user_id: str, data: SatsPaySettings):
|
||||
# insert or update
|
||||
row = await db.fetchone(
|
||||
"""SELECT user FROM satspay.settings WHERE user = ?""", (user,)
|
||||
"""SELECT user_id FROM satspay.settings WHERE user_id = ?""", (user_id,)
|
||||
)
|
||||
if row:
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satspay.settings SET custom_css = ? WHERE user = ?
|
||||
UPDATE satspay.settings SET custom_css = ? WHERE user_id = ?
|
||||
""",
|
||||
(data.custom_css, user),
|
||||
(data.custom_css, user_id),
|
||||
)
|
||||
else:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satspay.settings (
|
||||
user,
|
||||
user_id,
|
||||
custom_css
|
||||
)
|
||||
VALUES (?, ?)
|
||||
""",
|
||||
(
|
||||
user,
|
||||
user_id,
|
||||
data.custom_css,
|
||||
),
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def get_settings(user_id: str) -> SatsPaySettings:
|
||||
row = await db.fetchone(
|
||||
"""SELECT * FROM satspay.settings WHERE user_id = ?""",
|
||||
(user_id,),
|
||||
)
|
||||
if row:
|
||||
return SatsPaySettings.from_row(row)
|
||||
else:
|
||||
return None
|
|
@ -46,7 +46,7 @@ async def m002_add_settings_table(db):
|
|||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE satspay.settings (
|
||||
"user" TEXT,
|
||||
user_id TEXT,
|
||||
custom_css TEXT
|
||||
);
|
||||
"""
|
||||
|
|
|
@ -630,7 +630,9 @@
|
|||
'/satspay/api/v1/settings',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
this.formDialogSettings.data = data
|
||||
if(data) {
|
||||
this.formDialogSettings.data.custom_css = data.custom_css
|
||||
}
|
||||
} catch (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ async def api_charge_balance(charge_id):
|
|||
async def api_settings_save(
|
||||
data: SatsPaySettings, wallet: WalletTypeInfo = Depends(require_invoice_key)
|
||||
):
|
||||
await save_settings(user=wallet.wallet.user, data=data)
|
||||
await save_settings(user_id=wallet.wallet.user, data=data)
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user