Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
feat(my-project): my-project ui and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKanera committed Feb 27, 2021
1 parent 387b550 commit 31b7c76
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
5 changes: 3 additions & 2 deletions components/chips/chips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export default defineComponent({
};
const addChip = () => {
if (currentInput.value === '') return;
const inputValue = currentInput.value.trim();
if (inputValue === '') return;
chips.value.push(currentInput.value.trim());
chips.value.push(inputValue);
currentInput.value = '';
emit('input', chips.value);
};
Expand Down
17 changes: 10 additions & 7 deletions components/my-project/my-project.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template lang="pug">
.h-auto.m-4(class='md:mx-12')
ps-loader(:value='loading')
.flex.justify-center.mb-4
.flex.justify-center.mb-4(v-if='thisSchoolYearRef')
.rounded-lg.shadow.bg-ps-secondary.flex.px-2
.text-ps-white.mr-2 Termín odevzdání:
.text-ps-green.text-lg {{ `${deadlineFormatted}` }}
.text-ps-green.text-lg {{ deadlineFormatted }}
.flex.flex-col.justify-between.items-stretch(class='lg:flex-row-reverse lg:items-start')
.my-project-user
.user-info
Expand Down Expand Up @@ -52,7 +52,7 @@
ps-chips(v-model='keywordsRef', :edittable='modificable', placeholder='Klíčová slova')
.mt-8.w-full.flex.flex.justify-center
ps-btn.mr-4(@click='saveChanges', :disabled='awaiting || submittedRef || !modificable', :loading='awaiting') Uložit
ps-btn.ml-4(@click='checkModal', :disabled='awaiting || submittedRef || !modificable', :loading='awaiting') Odevzdat
ps-btn.ml-4(@click='checkModal', :disabled='awaiting || submittedRef || !modificable || !thisSchoolYearRef', :loading='awaiting') Odevzdat
template(#icon-right)
chevron-right/
ps-modal(v-model='submitCheck', :disabled='awaiting')
Expand Down Expand Up @@ -112,6 +112,7 @@ export default defineComponent({
const submittedRef = ref(false);
const deadlineDateRef = ref(new firebase.firestore.Timestamp(0, 0));
const keywordsRef = ref([]);
const thisSchoolYearRef = ref(false);
const mandatoryFilesUpload = ref([]);
const optionalFilesUpload = ref([]);
Expand All @@ -138,7 +139,7 @@ export default defineComponent({
},
});
const { title, description, links, mandatoryFiles, optionalFiles, submitted, deadlineDate, keywords } = response.data;
const { title, description, links, mandatoryFiles, optionalFiles, submitted, deadlineDate, keywords, thisSchoolYear } = response.data;
titleRef.value = title;
descriptionRef.value = description;
Expand All @@ -148,8 +149,9 @@ export default defineComponent({
// @ts-ignore
optionalFilesRef.value = getExtensions(optionalFiles);
submittedRef.value = submitted;
deadlineDateRef.value = new firebase.firestore.Timestamp(deadlineDate._seconds, 0);
deadlineDateRef.value = deadlineDate == null ? new firebase.firestore.Timestamp(0, 0) : new firebase.firestore.Timestamp(deadlineDate._seconds, 0);
keywordsRef.value = keywords;
thisSchoolYearRef.value = thisSchoolYear;
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -285,9 +287,9 @@ export default defineComponent({
awaiting.value = false;
};
const deadlineFormatted = computed(() => deadlineDateRef.value.toDate().toLocaleDateString('cs-CZ'));
const deadlineFormatted = computed(() => `${deadlineDateRef.value.toDate().toLocaleDateString('cs-CZ')} ${deadlineDateRef.value.toDate().toLocaleTimeString('cs-CZ').substr(0, 5)}`);
const modificable = computed(() => !submittedRef.value && deadlineDateRef.value > firebase.firestore.Timestamp.now());
const modificable = computed(() => (!submittedRef.value && deadlineDateRef.value > firebase.firestore.Timestamp.now()) || !thisSchoolYearRef.value);
return {
displayName: mainStore.state.user.displayName,
Expand Down Expand Up @@ -316,6 +318,7 @@ export default defineComponent({
modificable,
loading,
keywordsRef,
thisSchoolYearRef,
};
},
});
Expand Down
1 change: 1 addition & 0 deletions pages/admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export default defineComponent({
displayName: studentDoc.data()?.displayName,
profilePicture: studentDoc.data()?.profilePicture,
currentYear: studentDoc.data()?.currentYear,
year: (studentDoc.data()?.currentYear as firebase.firestore.Timestamp).toDate().getFullYear(),
};
});
Expand Down
12 changes: 10 additions & 2 deletions server/api/project/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ export default async (req: Request, res: Response) => {
}

let deadlineDate = projectData?.deadlineDate;
let thisSchoolYear = false;

if (deadlineDate == null) {
deadlineDate = (await admin.firestore().collection('system').doc('schoolYear').get())?.data()?.projectDeadline;
const schoolYear = (await admin.firestore().collection('system').doc('schoolYear').get())?.data();

if ((projectData?.currentYear as admin.firestore.Timestamp).isEqual(schoolYear?.currentYear)) {
deadlineDate = deadlineDate ?? schoolYear?.projectDeadline;
thisSchoolYear = true;
} else {
deadlineDate = null;
thisSchoolYear = false;
}

const studentData = (await admin.firestore().collection('users').doc(projectData?.studentId).get()).data();
Expand All @@ -71,6 +78,7 @@ export default async (req: Request, res: Response) => {
optionalFiles: await getFiles(projectFiles.data()?.optional),
submitted: projectData?.submitted,
deadlineDate,
thisSchoolYear,
studentProfilePicture: studentData?.profilePicture,
studentDisplayName: studentData?.displayName,
keywords: projectData?.keywords,
Expand Down
15 changes: 6 additions & 9 deletions server/api/project/student-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,17 @@ export default async (req: Request, res: Response) => {

await admin.firestore().runTransaction(async (transaction) => {
const sfDoc = await transaction.get(projectRef);
const system = await transaction.get(admin.firestore().collection('system').doc('schoolYear'));

if (!sfDoc.exists) throw new Error('404');

if (sfDoc.data()?.studentId !== authUser.uid) throw new Error('403');

if (sfDoc.data()?.submitted) throw new Error('409');

if (sfDoc.data()?.deadlineDate != null) {
if (admin.firestore.Timestamp.now() > sfDoc.data()?.deadlineDate) throw new Error('423');
} else {
const system = await transaction.get(admin.firestore().collection('system').doc('schoolYear'));

if (admin.firestore.Timestamp.now() > system.data()?.projectDeadline) throw new Error('423');
}
if ((sfDoc.data()?.currentYear as admin.firestore.Timestamp).isEqual(system.data()?.currentYear)) {
if (sfDoc.data()?.deadlineDate != null) {
if (admin.firestore.Timestamp.now() > sfDoc.data()?.deadlineDate) throw new Error('423');
} else if (admin.firestore.Timestamp.now() > system.data()?.projectDeadline) throw new Error('423');
} else if (sfDoc.data()?.currentYear < system.data()?.currentYear) throw new Error('403');

const projectFilesRef = (await admin.firestore().collection('projectFiles').where('projectId', '==', sfDoc.id).get()).docs[0].ref;

Expand Down
14 changes: 8 additions & 6 deletions server/api/project/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export default async (req: Request, res: Response) => {
if (projectData?.studentId !== userAuth.uid) throw new Error('403');
if (projectData?.submitted) throw new Error('409');

const system = await transaction.get(systemRef.doc('schoolYear'));

if ((projectData?.currentYear as admin.firestore.Timestamp).isEqual(system.data()?.projectDeadline)) throw new Error('409/2');

if (sfDoc.data()?.deadlineDate != null) {
if (admin.firestore.Timestamp.now() > sfDoc.data()?.deadlineDate) throw new Error('423');
} else {
const system = await transaction.get(systemRef.doc('schoolYear'));

if (admin.firestore.Timestamp.now() > system.data()?.projectDeadline) throw new Error('423');
}
} else if (admin.firestore.Timestamp.now() > system.data()?.projectDeadline) throw new Error('423');

const statisticsDoc = await transaction.get(systemRef.doc('statistics'));

Expand Down Expand Up @@ -122,12 +122,14 @@ export default async (req: Request, res: Response) => {
return res.status(404).send('Project does not exist');
case 'Error: 409':
return res.status(409).send('Project already submitted');
case 'Error: 409/2':
return res.status(409).send('You can submit project during your graduation year');
case 'Error: 412':
return res.status(412).send('Missing mandatory files (docx, pdf, zip/rar)');
case 'Error: 423':
return res.status(423).send('Past deadline');
default:
return res.status(500).send();
return res.status(500).send(e);
}
}
} catch (_) {
Expand Down

0 comments on commit 31b7c76

Please sign in to comment.