wrbapp/frontend/stores/usersStore.js
Xeovalyte 6fb439a754
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
large backend recreation
2023-03-20 11:23:46 +01:00

39 lines
918 B
JavaScript

import { getDocs, collection, getFirestore } from 'firebase/firestore'
export const useUsersStore = defineStore('users', () => {
const ledenlijst = ref([])
const users = ref([])
const db = getFirestore()
const getLedenlijst = async () => {
if (ledenlijst[0]) return;
try {
const querySnapshot = await getDocs(collection(db, "ledenlijst"));
querySnapshot.forEach((doc) => {
ledenlijst.value.push(doc.data())
});
} catch (e) {
console.log(e)
}
ledenlijst.value.sort((a, b) => a.fullName.localeCompare(b.fullName))
}
const getUsers = async () => {
if (users[0]) return
try {
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
users.value.push(doc.data())
});
} catch (e) {
console.log(e)
}
}
return { ledenlijst, users, getLedenlijst, getUsers }
});