wrbapp/frontend/stores/usersStore.js

39 lines
924 B
JavaScript
Raw Permalink Normal View History

2023-03-20 11:23:46 +01:00
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 () => {
2023-06-03 11:22:17 +02:00
if (users.value[0]) return
2023-03-20 11:23:46 +01:00
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 }
});