This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5352561
commit 766cc33
Showing
10 changed files
with
66 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
import { Request, Response } from 'express'; | ||
|
||
import admin from 'firebase-admin'; | ||
import 'firebase/auth'; | ||
|
||
export default async (req: Request, res: Response) => { | ||
const userId = req.headers.authorization ?? ''; | ||
const idToken = req.headers.authorization?.split(' ')[1] ?? ''; | ||
|
||
try { | ||
await admin.auth().getUser(userId); | ||
} catch (e) { | ||
return res.status(401).send(); | ||
} | ||
const userAuth = await admin.auth().verifyIdToken(idToken); | ||
|
||
if ((await admin.firestore().collection('proposals').where('studentId', '==', userId).get()).docs[0]?.exists) | ||
return res.status(202).send({ message: 'Proposal already submitted', status: 202 }); | ||
try { | ||
if ((await admin.firestore().collection('proposals').where('studentId', '==', userAuth.uid).get()).docs[0]?.exists) | ||
return res.status(202).send({ message: 'Proposal already submitted', status: 202 }); | ||
|
||
if ((await admin.firestore().collection('projects').where('studentId', '==', userId).get()).docs[0]?.exists) | ||
return res.status(202).send({ message: 'You already have project', status: 202 }); | ||
if ((await admin.firestore().collection('projects').where('studentId', '==', userAuth.uid).get()).docs[0]?.exists) | ||
return res.status(202).send({ message: 'You already have project', status: 202 }); | ||
|
||
const userData = (await admin.firestore().collection('users').doc(userId).get()).data(); | ||
const userData = (await admin.firestore().collection('users').doc(userAuth.uid).get()).data(); | ||
|
||
// User doesnt have current year set | ||
if (!userData?.currentYear) return res.status(412).send(); | ||
// User doesnt have current year set | ||
if (!userData?.currentYear) return res.status(412).send(); | ||
|
||
// Teacher cant submit proposal | ||
if (userData?.teacher) return res.status(403).send('Teacher cannot submit proposal'); | ||
// Teacher cant submit proposal | ||
if (userData?.teacher) return res.status(403).send('Teacher cannot submit proposal'); | ||
|
||
try { | ||
const teachersData = (await admin.firestore().collection('users').where('teacher', '==', true).where('extern', '==', false).where('deleted', '==', false).get()).docs; | ||
const teachersData = (await admin.firestore().collection('users').where('teacher', '==', true).where('extern', '==', false).where('deleted', '==', false).get()).docs; | ||
|
||
const teachersList = teachersData.map((teacherDoc) => { | ||
return { | ||
placeholder: teacherDoc.data().displayName, | ||
value: teacherDoc.id, | ||
}; | ||
}); | ||
const teachersList = teachersData.map((teacherDoc) => { | ||
return { | ||
placeholder: teacherDoc.data().displayName, | ||
value: teacherDoc.id, | ||
}; | ||
}); | ||
|
||
return res.status(200).json(teachersList); | ||
return res.status(200).json(teachersList); | ||
} catch (e) { | ||
return res.status(500).send(e); | ||
} | ||
} catch (e) { | ||
return res.status(500).send(e); | ||
return res.status(401).send(); | ||
} | ||
}; |