Skip to content

Commit

Permalink
fixed update
Browse files Browse the repository at this point in the history
  • Loading branch information
arcbtc committed Nov 19, 2024
1 parent 90f1086 commit 9ba8a0f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async def get_myextensions(wallet_ids: Union[str, List[str]]) -> List[MyExtensio
)


async def update_myextension(data: MyExtension) -> MyExtension:
async def update_myextension(data: CreateMyExtensionData) -> MyExtension:
await db.update("myextension.maintable", data)
return data
return MyExtension(**data.dict())


async def delete_myextension(myextension_id: str) -> None:
Expand Down
11 changes: 8 additions & 3 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ window.app = Vue.createApp({
},

async updateMyExtension(wallet, data) {
data.wallet = wallet.id
await LNbits.api
.request(
'PUT',
Expand All @@ -126,18 +127,22 @@ window.app = Vue.createApp({
},
async deleteMyExtension(tempId) {
var myextension = _.findWhere(this.myex, {id: tempId})
const wallet = _.findWhere(this.g.user.wallets, {
id: myextension.wallet
})
await LNbits.utils
.confirmDialog('Are you sure you want to delete this MyExtension?')
.onOk(function () {
LNbits.api
.request(
'DELETE',
'/myextension/api/v1/myex/' + tempId,
_.findWhere(this.g.user.wallets, {id: myextension.wallet})
.adminkey
wallet.adminkey
)
.then(() => {
this.myex = _.reject(this.myex, obj => obj.id == tempId)
this.myex = _.reject(this.myex, function (obj) {
return obj.id === myextension.id
})
})
.catch(error => {
LNbits.utils.notifyApiError(error)
Expand Down
3 changes: 2 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lnbits.tasks import register_invoice_listener

from .crud import get_myextension, update_myextension
from .models import CreateMyExtensionData

#######################################
########## RUN YOUR TASKS HERE ########
Expand Down Expand Up @@ -40,7 +41,7 @@ async def on_invoice_paid(payment: Payment) -> None:
total = myextension.total + payment.amount

myextension.total = total
await update_myextension(myextension)
await update_myextension(CreateMyExtensionData(**myextension.dict()))

# here we could send some data to a websocket on
# wss://<your-lnbits>/api/v1/ws/<myextension_id> and then listen to it on
Expand Down
3 changes: 2 additions & 1 deletion views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def api_myextension_create(
@myextension_api_router.put("/api/v1/myex/{myextension_id}")
async def api_myextension_update(
req: Request, # Withoutthe lnurl stuff this wouldnt be needed
data: MyExtension,
data: CreateMyExtensionData,
myextension_id: str,
wallet: WalletTypeInfo = Depends(require_admin_key),
) -> MyExtension:
Expand Down Expand Up @@ -140,6 +140,7 @@ async def api_myextension_delete(
)

await delete_myextension(myextension_id)
return


# ANY OTHER ENDPOINTS YOU NEED
Expand Down

0 comments on commit 9ba8a0f

Please sign in to comment.