forked from fossasia/open-event-checkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processRegistration.js
67 lines (61 loc) · 2.5 KB
/
processRegistration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { useAttendeesStore } from '@/stores/attendees'
import { useCameraStore } from '@/stores/camera'
import { useLoadingStore } from '@/stores/loading'
import { useNotificationStore } from '@/stores/notification'
import { usePrintModalStore } from '@/stores/printModal'
import { useTicketsStore } from '@/stores/tickets'
import extractAttendeeId from '@/utils/extractAttendeeId'
import extractOrderId from '@/utils/extractOrderId'
import isValidTicketQR from '@/utils/isValidTicketQR'
import { defineStore } from 'pinia'
export const useProcessRegistrationStore = defineStore('processRegistration', () => {
const loadingStore = useLoadingStore()
const cameraStore = useCameraStore()
const ticketsStore = useTicketsStore()
const attendeesStore = useAttendeesStore()
const notificationStore = useNotificationStore()
const printModalStore = usePrintModalStore()
async function processRegistrationCheckin(attendeeId, stationId) {
try {
const checkedIn = await attendeesStore.registerAttendee(attendeeId, stationId)
if (checkedIn) {
// update state of attendee if search is being used
if (attendeesStore.attendees.length > 0) {
const attendeeIndex = attendeesStore.attendees.findIndex((item) => item.id === attendeeId)
if (attendeeIndex > -1) {
attendeesStore.attendees[attendeeIndex].checkedIn = true
}
}
notificationStore.addNotification(['Success', 'Checked In'], 'success')
// end
} else {
notificationStore.addNotification(['Error', 'Already checked in'], 'error')
}
} catch (error) {
console.log(error)
return Promise.reject(error)
}
}
async function registerAttendeeScanner(stationId) {
if (!isValidTicketQR(cameraStore.qrCodeValue)) {
notificationStore.addNotification(['Error', 'Invalid QR Code'], 'error')
return
}
const attendeeId = extractAttendeeId(cameraStore.qrCodeValue)
const orderId = extractOrderId(cameraStore.qrCodeValue)
loadingStore.contentLoading()
try {
const attendee = await ticketsStore.getTicketAttendee(orderId)
await processRegistrationCheckin(attendeeId, stationId)
printModalStore.setPrintDetails(attendee.attributes['ticket-id'], attendeeId)
} catch (error) {
console.log(error)
loadingStore.contentLoaded()
notificationStore.addNotification(['Error', 'Unable to retrieve badge details'], 'error')
}
}
return {
processRegistrationCheckin,
registerAttendeeScanner
}
})