feat: update product

This commit is contained in:
Vlad Stan 2023-03-02 18:38:06 +02:00
parent 1e6aaf8436
commit 62e7d439c7
4 changed files with 84 additions and 35 deletions

View file

@ -203,6 +203,7 @@ async function stallDetails(path) {
sendProductFormData: function () {
var data = {
stall_id: this.stall.id,
id: this.productDialog.data.id,
name: this.productDialog.data.name,
description: this.productDialog.data.description,
categories: this.productDialog.data.categories,
@ -218,39 +219,27 @@ async function stallDetails(path) {
this.createProduct(data)
}
},
updateProduct: function (data) {
var self = this
let wallet = _.findWhere(this.stalls, {
id: self.productDialog.data.stall
}).wallet
LNbits.api
.request(
'PUT',
'/nostrmarket/api/v1/products/' + data.id,
_.findWhere(self.g.user.wallets, {
id: wallet
}).inkey,
data
updateProduct: async function (product) {
try {
const {data} = await LNbits.api.request(
'PATCH',
'/nostrmarket/api/v1/product/' + product.id,
this.adminkey,
product
)
.then(async function (response) {
self.products = _.reject(self.products, function (obj) {
return obj.id == data.id
})
let productData = mapProducts(response.data)
self.products.push(productData)
//SEND Nostr data
try {
await self.sendToRelays(productData, 'product', 'update')
} catch (e) {
console.error(e)
}
self.resetDialog('productDialog')
//self.productDialog.show = false
//self.productDialog.data = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
const index = this.products.findIndex(r => r.id === product.id)
if (index !== -1) {
this.products.splice(index, 1, data)
}
this.$q.notify({
type: 'positive',
message: 'Product Updated',
timeout: 5000
})
} catch (error) {
console.warn(error)
LNbits.utils.notifyApiError(error)
}
},
createProduct: async function (payload) {
try {
@ -271,6 +260,10 @@ async function stallDetails(path) {
LNbits.utils.notifyApiError(error)
}
},
editProduct: async function (product) {
this.productDialog.data = {...product}
this.productDialog.showDialog = true
},
deleteProduct: async function (productId) {
LNbits.utils
.confirmDialog('Are you sure you want to delete this product?')
@ -296,6 +289,15 @@ async function stallDetails(path) {
})
},
showNewProductDialog: async function () {
this.productDialog.data = {
id: null,
name: '',
description: '',
categories: [],
image: null,
price: 0,
quantity: 0
}
this.productDialog.showDialog = true
}
},