Refactor events extensions (#21)

* require admin key
* remove log
* only show paid tickets
* purge tickets
This commit is contained in:
Tiago Vasconcelos 2024-02-05 07:50:39 +00:00 committed by GitHub
parent f468183631
commit 07d2f59bc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 59 additions and 15 deletions

View file

@ -26,7 +26,8 @@
v-model.trim="formDialog.data.email"
type="email"
label="Your email "
:rules="[val => emailValidation(val)]"
:rules="[val => !!val || '* Required', val => emailValidation(val)]"
lazy-rules
></q-input>
<div class="row q-mt-lg">
@ -121,9 +122,10 @@
}
}
},
created() {
async created() {
this.info = '{{ event_info | tojson }}'
this.info = this.info.substring(1, this.info.length - 1)
await this.purgeUnpaidTickets()
},
computed: {
formatDescription() {
@ -152,8 +154,8 @@
)
},
emailValidation(val) {
let regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/g
return !regex.test(val) || 'Please enter valid email.'
let regex = /^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$/
return regex.test(val) || 'Please enter valid email.'
},
Invoice: function () {
@ -226,6 +228,14 @@
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
async purgeUnpaidTickets() {
try {
await LNbits.api.request('GET', `/events/api/v1/purge/{{ event_id }}`)
} catch (error) {
console.warn(error)
LNbits.utils.notifyApiError(error)
}
}
}
})

View file

@ -416,9 +416,11 @@
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.tickets = response.data.map(function (obj) {
return mapEvents(obj)
})
self.tickets = response.data
.map(function (obj) {
return mapEvents(obj)
})
.filter(e => e.paid)
})
},
deleteTicket: function (ticketId) {
@ -461,7 +463,6 @@
self.events = response.data.map(function (obj) {
return mapEvents(obj)
})
console.log(self.events)
})
},
sendEventData: function () {
@ -480,7 +481,7 @@
createEvent: function (wallet, data) {
var self = this
LNbits.api
.request('POST', '/events/api/v1/events', wallet.inkey, data)
.request('POST', '/events/api/v1/events', wallet.adminkey, data)
.then(function (response) {
self.events.push(mapEvents(response.data))
self.formDialog.show = false
@ -504,7 +505,7 @@
.request(
'PUT',
'/events/api/v1/events/' + data.id,
wallet.inkey,
wallet.adminkey,
data
)
.then(function (response) {
@ -530,7 +531,7 @@
.request(
'DELETE',
'/events/api/v1/events/' + eventsId,
_.findWhere(self.g.user.wallets, {id: events.wallet}).inkey
_.findWhere(self.g.user.wallets, {id: events.wallet}).adminkey
)
.then(function (response) {
self.events = _.reject(self.events, function (obj) {

View file

@ -152,7 +152,6 @@
},
getEventTickets: function () {
var self = this
console.log('obj')
LNbits.api
.request(
'GET',