added user migration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
xeovalyte 2022-12-17 13:01:49 +01:00
parent 009cd2ddc5
commit c270d81cef
3 changed files with 90 additions and 20 deletions

View File

@ -43,6 +43,7 @@ const calEvents = ref([])
const news = ref(null) const news = ref(null)
const contestTimes = ref(null) const contestTimes = ref(null)
const competitors = ref([]) const competitors = ref([])
const users = ref([])
const messaging = ref(null) const messaging = ref(null)
@ -224,7 +225,7 @@ const logDeviceInfo = async () => {
const ledenlijst = ref([]) const ledenlijst = ref([])
provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, userAllPersons, getPersons, calEvents, news, registrationToken, contestTimes, competitors }) provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, users, userAllPersons, getPersons, calEvents, news, registrationToken, contestTimes, competitors })
</script> </script>
<style scoped> <style scoped>

View File

@ -19,7 +19,7 @@
</template> </template>
<script setup> <script setup>
import { doc, getDocs, collection, writeBatch } from "firebase/firestore"; import { doc, getDocs, collection, writeBatch, runTransaction } from "firebase/firestore";
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
definePageMeta({ definePageMeta({
@ -27,7 +27,7 @@ definePageMeta({
key: 'back' key: 'back'
}) })
const { db, ledenlijst } = inject('firebase') const { db, ledenlijst, users } = inject('firebase')
const toast = useToast() const toast = useToast()
@ -112,8 +112,7 @@ const csvToJson = (csv) => {
result.push(obj) result.push(obj)
} }
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\r')) 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 = [] ledenlijst.value = []
@ -132,7 +131,7 @@ const csvToJson = (csv) => {
if (groups[1] === 'Week') groups[1] = 'Vrijdag' if (groups[1] === 'Week') groups[1] = 'Vrijdag'
} }
ledenlijst.value.push({ relatiecode: result[i].Relatiecode, fullName: result[i]['Volledige naam (1)'].join(' '), 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)'].join(' '), email: [result[i]['E-mail'], result[i]['2e E-mail']], groups: [...new Set(groups)], diploma: result[i]['Diploma dropdown 1\r'] })
} }
uploadLedenlijst() uploadLedenlijst()
@ -155,6 +154,42 @@ const uploadLedenlijst = async () => {
console.log(e) console.log(e)
} }
disableButtons.value = false updateUsers()
}
const updateUsers = async () => {
try {
const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
const data = doc.data()
data.id = doc.id
users.value.push(data)
});
} catch (e) {
console.log(e)
toast.error('Error getting users')
}
const batch = writeBatch(db);
users.value.forEach(user => {
const lid = ledenlijst.value.filter(a => a.email.includes(user.email))
const newRelatiecodes = lid.map(a => a.relatiecode)
user.allRelatiecodes = newRelatiecodes
user.relatiecodes.forEach((relatiecode, index) => {
if (!newRelatiecodes.includes(relatiecode)) { user.relatiecodes.splice(index, 1); console.log('removed item')}
})
const userRef = doc(db, "users", user.id)
batch.update(userRef, user)
})
await batch.commit();
disableButtons.value = false
} }
</script> </script>

View File

@ -9,18 +9,36 @@
<label class="font-bold">Onderdelen</label> <label class="font-bold">Onderdelen</label>
<button @click="newEvent = true" class="item-hover border-dashed border-2 container text-center font-bold border-neutral-500 mb-3">Onderdeel Toevoegen</button> <button @click="newEvent = true" class="item-hover border-dashed border-2 container text-center font-bold border-neutral-500 mb-3">Onderdeel Toevoegen</button>
<div> <div class="flex flex-col gap-y-5 mb-5">
Onderdeel <div v-for="(event, index) in contest.events" :key="index" class="container p-2 flex flex-col gap-y-3">
<h2 class="text-center text-primary font-bold text-lg">{{ event.type }}</h2>
<table class="table-fixed text-left odd:bg-blue-500">
<thead class="font-bold">
<tr>
<th class="w-3/6">Naam</th>
<th class="w-2/6">Tijd</th>
<th class="w-1/6">DSQ</th>
</tr>
</thead>
<tbody>
<tr v-for="competitor in event.competitors" class="even:dark:bg-neutral-700 even:bg-neutral-300">
<td>{{ competitors.find(x => x.relatiecode === competitor.relatiecode ).name }}</td>
<td>{{ competitor.time.minute}}:{{ competitor.time.seconds }}:{{ competitor.time.milliseconds }}</td>
<td>{{ competitor.dsq }}</td>
</tr>
</tbody>
</table>
</div>
</div> </div>
<div class="w-full flex flex-wrap justify-between"> <div class="w-full flex flex-wrap justify-between">
<input :disabled="disableButtons" type="submit" value="Wedstrijd Toevoegen" class="btn w-full sm:w-48 mb-1"> <input :disabled="disableButtons" type="submit" value="Wedstrijd Toevoegen" class="btn w-full sm:w-48 mb-1">
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Cancel</button> <button @click="resetContest" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Reset</button>
</div> </div>
</form> </form>
<form v-else class="flex flex-col"> <form v-else @submit.prevent="addEvent" class="flex flex-col">
<label class="font-bold">Onderdeel</label> <label class="font-bold">Onderdeel</label>
<select class="input mb-5"> <select v-model="tempEvent.type" class="input mb-5">
<option value="200m-Obstacle-Swim">200m Obstacle Swim (Hindernis)</option> <option value="200m-Obstacle-Swim">200m Obstacle Swim (Hindernis)</option>
<option value="50m-Manikin-Carry">50m Manikin Carry (Popvervoeren)</option> <option value="50m-Manikin-Carry">50m Manikin Carry (Popvervoeren)</option>
<option value="100m-Rescue-Medley">100m Rescue Medley (Reddingswissel)</option> <option value="100m-Rescue-Medley">100m Rescue Medley (Reddingswissel)</option>
@ -34,30 +52,30 @@
</select> </select>
<label class="font-bold">Deelnemers</label> <label class="font-bold">Deelnemers</label>
<button @click="tempEvent.competitors.push({ relatiecode: '', dsq: false, info: null, time: { minute: null, seconds: null, milliseconds: null }})" type="button" class="item-hover border-dashed border-2 container text-center font-bold border-neutral-500 mb-3">Deelnemer Toevoegen</button> <button @click="tempEvent.competitors.unshift({ relatiecode: '', dsq: false, info: '', time: { minute: null, seconds: null, milliseconds: null }})" type="button" class="item-hover border-dashed border-2 container text-center font-bold border-neutral-500 mb-3">Deelnemer Toevoegen</button>
<div class="flex flex-col gap-y-3"> <div class="flex flex-col gap-y-3 mb-5">
<div v-for="(competitor, index) in tempEvent.competitors" :key="index"> <div v-for="(competitor, index) in tempEvent.competitors" :key="index">
<div class="container flex flex-col p-4"> <div class="container flex flex-col p-4">
<label class="font-bold">Deelnemer</label> <label class="font-bold">Deelnemer</label>
<select v-model="competitor.relatiecode" class="input dark:bg-neutral-700 bg-neutral-300 mb-5"> <select v-model="competitor.relatiecode" class="input dark:bg-neutral-700 bg-neutral-300 mb-5">
<option v-for="(user, index) in competitors" :value="user.relatiecode">{{ user.name}} ({{ user.relatiecode }})</option> <option v-for="user in competitors" :value="user.relatiecode">{{ user.name}} ({{ user.relatiecode }})</option>
</select> </select>
<label class="font-bold">Tijd</label> <label class="font-bold">Tijd</label>
<div class="flex dark:bg-neutral-700 bg-neutral-300 gap-x-2 w-min rounded mb-2"> <div class="flex dark:bg-neutral-700 bg-neutral-300 gap-x-2 w-min rounded mb-2">
<select v-model="competitor.time.minute" class="input pl-3 pr-8 bg-opacity-0 shadow-none "> <select v-model="competitor.time.minute" class="input pl-3 pr-8 bg-opacity-0 shadow-none ">
<option value="null" disabled selected>mm</option> <option value="null" disabled selected>mm</option>
<option v-for="n in 60" :value="n - 1">{{ n < 11 ? `0${n-1}` : `${n-1}` }}</option> <option v-for="n in 60" :value="n < 11 ? `0${n-1}` : `${n-1}`">{{ n < 11 ? `0${n-1}` : `${n-1}` }}</option>
</select> </select>
<span class="my-auto text-xl">:</span> <span class="my-auto text-xl">:</span>
<select v-model="competitor.time.seconds" class="input pl-2 pr-8 bg-opacity-0 shadow-none "> <select v-model="competitor.time.seconds" class="input pl-2 pr-8 bg-opacity-0 shadow-none ">
<option value="null" disabled selected>ss</option> <option value="null" disabled selected>ss</option>
<option v-for="n in 60" :value="n - 1">{{ n < 11 ? `0${n-1}` : `${n-1}`}}</option> <option v-for="n in 60" :value="n < 11 ? `0${n-1}` : `${n-1}`">{{ n < 11 ? `0${n-1}` : `${n-1}`}}</option>
</select> </select>
<span class="my-auto text-xl">:</span> <span class="my-auto text-xl">:</span>
<select v-model="competitor.time.milliseconds" class="input pl-2 pr-8 bg-opacity-0 shadow-none "> <select v-model="competitor.time.milliseconds" class="input pl-2 pr-8 bg-opacity-0 shadow-none ">
<option value="null" disabled selected>ms</option> <option value="null" disabled selected>ms</option>
<option v-for="n in 100" :value="n - 1">{{ n < 11 ? `0${n-1}` : `${n-1}` }}</option> <option v-for="n in 100" :value="n < 11 ? `0${n-1}` : `${n-1}`">{{ n < 11 ? `0${n-1}` : `${n-1}` }}</option>
</select> </select>
</div> </div>
<div class="flex items-center mb-5"> <div class="flex items-center mb-5">
@ -70,6 +88,10 @@
</div> </div>
</div> </div>
</div> </div>
<div class="w-full flex flex-wrap justify-between">
<input :disabled="disableButtons" type="submit" value="Onderdeel Toevoegen" class="btn w-full sm:w-48 mb-1">
<button @click="backEvent" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Cancel</button>
</div>
</form> </form>
</div> </div>
</template> </template>
@ -83,6 +105,7 @@ definePageMeta({
const { userData, db, competitors } = inject('firebase') const { userData, db, competitors } = inject('firebase')
const disableButtons = ref(false)
const router = useRouter() const router = useRouter()
const newEvent = ref(false) const newEvent = ref(false)
@ -105,6 +128,17 @@ const getCompetitors = async () => {
}) })
} }
const addEvent = () => {
newEvent.value = false
contest.value.events.unshift(tempEvent.value)
tempEvent.value = { type: '', competitors: []}
}
const backEvent = () => {
newEvent.value = false
tempEvent.value = { type: '', competitors: []}
}
onMounted(() => { onMounted(() => {
getCompetitors() getCompetitors()
}) })