updating ledenlijst system
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Xeovalyte 2023-01-27 15:08:58 +01:00
parent 28ca1335ba
commit c6a44416b6

View File

@ -34,6 +34,7 @@ const toast = useToast()
const file = ref(null)
const disableButtons = ref(false)
const searchTerm = ref('')
const newLedenlijst = ref([])
onMounted(async () => {
if (!ledenlijst.value.length) {
@ -94,11 +95,13 @@ const csvToJson = (csv) => {
if (!Object.hasOwn(result[0], 'Relatiecode') || !Object.hasOwn(result[0], 'Volledige naam (1)') || !Object.hasOwn(result[0], 'E-mail') || !Object.hasOwn(result[0], '2e E-mail') || !Object.hasOwn(result[0], 'Verenigingssporten') || !Object.hasOwn(result[0], 'Diploma dropdown 1')) return toast.error('Missing properties')
ledenlijst.value = []
newLedenlijst.value = []
for (let i in result) {
let groups = []
let correctGroups = null
if (!result[i].Relatiecode) break;
if (result[i].Verenigingssporten.includes(',')) correctGroups = result[i].Verenigingssporten.split(',')
else correctGroups = [result[i].Verenigingssporten]
@ -113,31 +116,46 @@ const csvToJson = (csv) => {
if (groups[2] === 'Week') groups[2] = 'Vrijdag'
groups = groups.filter((item) => item !== "Groep")
ledenlijst.value.push({ relatiecode: result[i].Relatiecode, fullName: result[i]['Volledige naam (1)'], email: [result[i]['E-mail'], result[i]['2e E-mail']], groups: [...new Set(groups)], diploma: result[i]['Diploma dropdown 1'] })
newLedenlijst.value.push({ relatiecode: result[i].Relatiecode, fullName: result[i]['Volledige naam (1)'], email: [result[i]['E-mail'], result[i]['2e E-mail']], groups: [...new Set(groups)], diploma: result[i]['Diploma dropdown 1'] })
}
uploadLedenlijst()
}
const uploadLedenlijst = async () => {
try {
const batch = writeBatch(db)
try {
const batch = writeBatch(db)
for (let i = 0; i < ledenlijst.value.length; i++) {
const docRef = doc(db, "ledenlijst", ledenlijst.value[i].relatiecode)
batch.set(docRef, ledenlijst.value[i]);
}
newLedenlijst.value.forEach(lid => {
const docRef = doc(db, "ledenlijst", lid.relatiecode)
await batch.commit();
const exists = ledenlijst.value.filter(a => a.relatiecode === lid.relatiecode).length > 1
toast.success('Published ledenlijst')
} catch (e) {
toast.error("Error updating ledenlijst");
console.log(e)
}
if (!exists) {
return batch.set(docRef, lid);
}
batch.update(docRef, { fullName: lid.relatiecode, email: lid.email, groups: lid.groups, diploma: lid.diploma})
})
const deleteLeden = ledenlijst.value.filter(a => newLedenlijst.value.map(x => x.relatiecode).indexOf(a.relatiecode) === -1)
updateUsers()
deleteLeden.forEach(lid => {
const docRef = doc(db, "ledenlijst", lid.relatiecode)
batch.delete(docRef)
})
await batch.commit();
toast.success('Published ledenlijst')
} catch (e) {
toast.error("Error updating ledenlijst");
console.log(e)
}
ledenlijst.value = newLedenlijst.value
updateUsers()
}
@ -164,7 +182,7 @@ const updateUsers = async () => {
user.allRelatiecodes = newRelatiecodes
user.relatiecodes.forEach((relatiecode, index) => {
if (!newRelatiecodes.includes(relatiecode)) { user.relatiecodes.splice(index, 1); console.log('removed item')}
if (!newRelatiecodes.includes(relatiecode)) { user.relatiecodes.splice(index, 1); console.log('removed item', relatiecode)}
})
const userRef = doc(db, "users", user.id)