Merge stable version before large change #16
@ -34,6 +34,7 @@ const toast = useToast()
|
|||||||
const file = ref(null)
|
const file = ref(null)
|
||||||
const disableButtons = ref(false)
|
const disableButtons = ref(false)
|
||||||
const searchTerm = ref('')
|
const searchTerm = ref('')
|
||||||
|
const newLedenlijst = ref([])
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!ledenlijst.value.length) {
|
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')
|
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) {
|
for (let i in result) {
|
||||||
let groups = []
|
let groups = []
|
||||||
let correctGroups = null
|
let correctGroups = null
|
||||||
|
if (!result[i].Relatiecode) break;
|
||||||
|
|
||||||
if (result[i].Verenigingssporten.includes(',')) correctGroups = result[i].Verenigingssporten.split(',')
|
if (result[i].Verenigingssporten.includes(',')) correctGroups = result[i].Verenigingssporten.split(',')
|
||||||
else correctGroups = [result[i].Verenigingssporten]
|
else correctGroups = [result[i].Verenigingssporten]
|
||||||
|
|
||||||
@ -113,31 +116,46 @@ const csvToJson = (csv) => {
|
|||||||
|
|
||||||
if (groups[2] === 'Week') groups[2] = 'Vrijdag'
|
if (groups[2] === 'Week') groups[2] = 'Vrijdag'
|
||||||
|
|
||||||
groups = groups.filter((item) => item !== "Groep")
|
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'] })
|
||||||
|
|
||||||
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'] })
|
|
||||||
}
|
}
|
||||||
uploadLedenlijst()
|
uploadLedenlijst()
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadLedenlijst = async () => {
|
const uploadLedenlijst = async () => {
|
||||||
try {
|
try {
|
||||||
const batch = writeBatch(db)
|
const batch = writeBatch(db)
|
||||||
|
|
||||||
for (let i = 0; i < ledenlijst.value.length; i++) {
|
newLedenlijst.value.forEach(lid => {
|
||||||
const docRef = doc(db, "ledenlijst", ledenlijst.value[i].relatiecode)
|
const docRef = doc(db, "ledenlijst", lid.relatiecode)
|
||||||
batch.set(docRef, ledenlijst.value[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
await batch.commit();
|
const exists = ledenlijst.value.filter(a => a.relatiecode === lid.relatiecode).length > 1
|
||||||
|
|
||||||
toast.success('Published ledenlijst')
|
if (!exists) {
|
||||||
} catch (e) {
|
return batch.set(docRef, lid);
|
||||||
toast.error("Error updating ledenlijst");
|
}
|
||||||
console.log(e)
|
|
||||||
}
|
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.allRelatiecodes = newRelatiecodes
|
||||||
user.relatiecodes.forEach((relatiecode, index) => {
|
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)
|
const userRef = doc(db, "users", user.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user