Merge stable version before large change #16
@ -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,9 +116,7 @@ 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()
|
||||
}
|
||||
@ -124,11 +125,26 @@ const uploadLedenlijst = async () => {
|
||||
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)
|
||||
|
||||
const exists = ledenlijst.value.filter(a => a.relatiecode === lid.relatiecode).length > 1
|
||||
|
||||
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)
|
||||
|
||||
deleteLeden.forEach(lid => {
|
||||
const docRef = doc(db, "ledenlijst", lid.relatiecode)
|
||||
|
||||
batch.delete(docRef)
|
||||
})
|
||||
|
||||
await batch.commit();
|
||||
|
||||
toast.success('Published ledenlijst')
|
||||
@ -137,6 +153,8 @@ const uploadLedenlijst = async () => {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user