@@ -658,6 +668,7 @@ const mapStalls = obj => {
}
const mapProducts = obj => {
obj._data = _.clone(obj)
+ console.log(obj)
return obj
}
const mapZone = obj => {
@@ -744,7 +755,8 @@ new Vue({
'Technology (Phones and Computers)',
'Home (furniture and accessories)',
'Gifts (flowers, cards, etc)',
- 'Adult'
+ 'Adult',
+ 'Other'
],
relayOptions: [
'wss://nostr-relay.herokuapp.com/ws',
@@ -924,6 +936,10 @@ new Vue({
}
},
methods: {
+ resetDialog(dialog){
+ this[dialog].show = false
+ this[dialog].data = {}
+ },
generateKeys: function(){
var self = this
LNbits.api
@@ -967,6 +983,7 @@ new Vue({
////////////////STALLS//////////////////
////////////////////////////////////////
getStalls: function () {
+ console.log(this.g.user)
var self = this
LNbits.api
.request(
@@ -1037,9 +1054,7 @@ new Vue({
return obj.id == data.id
})
self.stalls.push(mapStalls(response.data))
- self.stallDialog.show = false
- self.stallDialog.data = {}
- data = {}
+ self.resetDialog('stallDialog')
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
@@ -1058,9 +1073,10 @@ new Vue({
)
.then(function (response) {
self.stalls.push(mapStalls(response.data))
- self.stallDialog.show = false
- self.stallDialog.data = {}
- data = {}
+ self.resetDialog('stallDialog')
+ //self.stallDialog.show = false
+ //self.stallDialog.data = {}
+ //data = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
@@ -1105,7 +1121,7 @@ new Vue({
self.g.user.wallets[0].inkey
)
.then(function (response) {
- console.log(response.data)
+ console.log("RESP DATA", response.data)
if (response.data) {
self.products = response.data.map(mapProducts)
}
@@ -1119,22 +1135,24 @@ new Vue({
var link = _.findWhere(self.products, {id: linkId})
self.productDialog.data = _.clone(link._data)
+ self.productDialog.data.categories = self.productDialog.data.categories.split(",")
+
self.productDialog.show = true
},
sendProductFormData: function () {
+ let _data = {...this.productDialog.data}
var data = {
- stall: this.productDialog.data.stall,
- product: this.productDialog.data.product,
- categories:
- this.productDialog.data.categories +
- this.productDialog.categoriesextra,
- description: this.productDialog.data.description,
- image: this.productDialog.data.image,
- price: this.productDialog.data.price,
- quantity: this.productDialog.data.quantity
+ stall: _data.stall,
+ product: _data.product,
+ categories: _data.categories && _data.categories.toString(),
+ description: _data.description,
+ image: _data.image,
+ price: _data.price,
+ quantity: _data.quantity
}
- if (this.productDialog.data.id) {
- this.updateProduct({...this.productDialog.data, ...data})
+ if (_data.id) {
+ data.id = _data.id
+ this.updateProduct(data)
} else {
this.createProduct(data)
}
@@ -1163,80 +1181,72 @@ new Vue({
this.productDialog = {...this.productDialog}
},
updateProduct: function (data) {
- var self = this
- LNbits.api
- .request(
- 'PUT',
- '/diagonalley/api/v1/products' + data.id,
- _.findWhere(self.g.user.wallets, {
- id: self.productDialog.data.wallet
- }).inkey,
- _.pick(
- data,
- 'shopname',
- 'relayaddress',
- 'shippingzone1',
- 'zone1cost',
- 'shippingzone2',
- 'zone2cost',
- 'email'
- )
- )
- .then(function (response) {
- self.products = _.reject(self.products, function (obj) {
- return obj.id == data.id
- })
- self.products.push(mapProducts(response.data))
- self.productDialog.show = false
- self.productDialog.data = {}
- })
- .catch(function (error) {
- LNbits.utils.notifyApiError(error)
- })
- },
- createProduct: function (data) {
var self = this
let wallet = _.findWhere(this.stalls, {
id: self.productDialog.data.stall
}).wallet
- console.log(wallet)
LNbits.api
.request(
- 'POST',
- '/diagonalley/api/v1/products',
+ 'PUT',
+ '/diagonalley/api/v1/products/' + data.id,
_.findWhere(self.g.user.wallets, {
id: wallet
}).inkey,
data
)
.then(function (response) {
+ self.products = _.reject(self.products, function (obj) {
+ return obj.id == data.id
+ })
self.products.push(mapProducts(response.data))
- self.productDialog.show = false
- self.productDialog.data = {}
+ self.resetDialog('productDialog')
+ //self.productDialog.show = false
+ //self.productDialog.data = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
+ createProduct: function (data) {
+ let self = this
+ const walletId = _.findWhere(this.stalls, {id: data.stall}).wallet
+
+ console.log("DATA", walletId, data)
+ LNbits.api
+ .request(
+ 'POST',
+ '/diagonalley/api/v1/products',
+ _.findWhere(self.g.user.wallets, {id: walletId}).inkey,
+ data
+ )
+ .then((response) => {
+ console.log(response)
+ self.products.push(mapProducts(response.data))
+ self.resetDialog('productDialog')
+ })
+ .catch((error) => {
+ LNbits.utils.notifyApiError(error)
+ })
+ },
deleteProduct: function (productId) {
- var self = this
- var product = _.findWhere(this.products, {id: productId})
-
+ const product = _.findWhere(this.products, {id: productId})
+ const walletId = _.findWhere(this.stalls, {id: product.stall}).wallet
+
LNbits.utils
.confirmDialog('Are you sure you want to delete this products link?')
- .onOk(function () {
+ .onOk(() => {
LNbits.api
.request(
'DELETE',
'/diagonalley/api/v1/products/' + productId,
- _.findWhere(self.g.user.wallets, {id: product.wallet}).inkey
+ _.findWhere(this.g.user.wallets, {id: walletId}).adminkey
)
- .then(function (response) {
- self.products = _.reject(self.products, function (obj) {
+ .then(() => {
+ this.products = _.reject(this.products, (obj) => {
return obj.id == productId
})
})
- .catch(function (error) {
+ .catch((error) => {
LNbits.utils.notifyApiError(error)
})
})
@@ -1368,7 +1378,7 @@ new Vue({
LNbits.api
.request(
'GET',
- '/diagonalley/api/v1/shops?all_wallets',
+ '/diagonalley/api/v1/shops?all_wallets=true',
this.g.user.wallets[0].inkey
)
.then(function (response) {
diff --git a/lnbits/extensions/diagonalley/views_api.py b/lnbits/extensions/diagonalley/views_api.py
index d5e5e382..4630b321 100644
--- a/lnbits/extensions/diagonalley/views_api.py
+++ b/lnbits/extensions/diagonalley/views_api.py
@@ -82,7 +82,10 @@ async def api_diagonalley_products(
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
stalls = [stall.id for stall in await get_diagonalley_stalls(wallet_ids)]
-
+
+ if not stalls:
+ return
+
return [product.dict() for product in await get_diagonalley_products(stalls)]
@@ -93,18 +96,18 @@ async def api_diagonalley_product_create(
):
if product_id:
- product = await get_diagonalley_product(product_id)
-
+ product = await get_diagonalley_product(product_id)
if not product:
return {"message": "Withdraw product does not exist."}
-
- if product.wallet != wallet.wallet.id:
+
+ stall = await get_diagonalley_stall(stall_id = product.stall)
+ if stall.wallet != wallet.wallet.id:
return {"message": "Not your withdraw product."}
product = await update_diagonalley_product(product_id, **data.dict())
else:
product = await create_diagonalley_product(data=data)
-
+ print("PRODUCT", product)
return product.dict()
@@ -117,7 +120,8 @@ async def api_diagonalley_products_delete(
if not product:
return {"message": "Product does not exist."}
- if product.wallet != wallet.wallet.id:
+ stall = await get_diagonalley_stall(product.stall)
+ if stall.wallet != wallet.wallet.id:
return {"message": "Not your Diagon Alley."}
await delete_diagonalley_product(product_id)
@@ -144,7 +148,7 @@ async def api_diagonalley_zone_create(
@diagonalley_ext.post("/api/v1/zones/{zone_id}")
async def api_diagonalley_zone_update(
data: createZones,
- zone_id: str = Query(None),
+ zone_id: str,
wallet: WalletTypeInfo = Depends(require_admin_key),
):
zone = await get_diagonalley_zone(zone_id)
@@ -191,13 +195,13 @@ async def api_diagonalley_stalls(
@diagonalley_ext.put("/api/v1/stalls/{stall_id}")
async def api_diagonalley_stall_create(
data: createStalls,
- stall_id: str = Query(None),
+ stall_id: str = None,
wallet: WalletTypeInfo = Depends(require_invoice_key),
):
if stall_id:
stall = await get_diagonalley_stall(stall_id)
-
+ print("ID", stall_id)
if not stall:
return {"message": "Withdraw stall does not exist."}
@@ -213,7 +217,7 @@ async def api_diagonalley_stall_create(
@diagonalley_ext.delete("/api/v1/stalls/{stall_id}")
async def api_diagonalley_stall_delete(
- stall_id: str = Query(None), wallet: WalletTypeInfo = Depends(require_admin_key)
+ stall_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
stall = await get_diagonalley_stall(stall_id)
@@ -255,7 +259,7 @@ async def api_diagonalley_order_create(
@diagonalley_ext.delete("/api/v1/orders/{order_id}")
async def api_diagonalley_order_delete(
- order_id: str = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
+ order_id: str, wallet: WalletTypeInfo = Depends(get_key_type)
):
order = await get_diagonalley_order(order_id)
@@ -272,7 +276,7 @@ async def api_diagonalley_order_delete(
@diagonalley_ext.get("/api/v1/orders/paid/{order_id}")
async def api_diagonalley_order_paid(
- order_id: str = Query(None), wallet: WalletTypeInfo = Depends(require_admin_key)
+ order_id, wallet: WalletTypeInfo = Depends(require_admin_key)
):
await db.execute(
"UPDATE diagonalley.orders SET paid = ? WHERE id = ?",
@@ -286,7 +290,7 @@ async def api_diagonalley_order_paid(
@diagonalley_ext.get("/api/v1/orders/shipped/{order_id}")
async def api_diagonalley_order_shipped(
- order_id: str = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
+ order_id, wallet: WalletTypeInfo = Depends(get_key_type)
):
await db.execute(
"UPDATE diagonalley.orders SET shipped = ? WHERE id = ?",
@@ -307,7 +311,7 @@ async def api_diagonalley_order_shipped(
@diagonalley_ext.get("/api/v1/stall/products/{stall_id}")
async def api_diagonalley_stall_products(
- stall_id: str = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
+ stall_id, wallet: WalletTypeInfo = Depends(get_key_type)
):
rows = await db.fetchone(