-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Implemented create and delete postings for team matching api #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vvyn
wants to merge
7
commits into
develop
Choose a base branch
from
feat/create-and-delete-posting-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd9c717
feat(postings): Create and delete postings
vvyn a513245
feat(postings): Miminal changes to create and delete posting functions
vvyn 945cd47
Merge branch 'develop' into feat/create-and-delete-posting-api
vvyn 43f9b1a
Update create.tsx
vvyn e919611
feat(postings): Add verification of author for posting deletion
vvyn 2996f9a
fix(matching): Rename posting directory and associated files
vvyn bd0c710
Merge branch 'develop' into feat/create-and-delete-posting-api
vvyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { firestore } from 'firebase-admin'; | ||
| import { NextApiRequest, NextApiResponse } from 'next'; | ||
| import initializeApi from '../../../lib/admin/init'; | ||
| import { userIsAuthorized } from '../../../lib/authorization/check-authorization'; | ||
|
|
||
| initializeApi(); | ||
| const db = firestore(); | ||
| const POSTINGS_COLLECTION = '/postings'; | ||
|
|
||
| interface PostingData { | ||
| postingId: string; | ||
| numberOfPeopleWanted: number; | ||
| skillSet: string; | ||
| } | ||
|
|
||
| async function createPosting(req: NextApiRequest, res: NextApiResponse) { | ||
| try { | ||
| const postingData: PostingData = JSON.parse(req.body); | ||
| await db.collection(POSTINGS_COLLECTION).add(postingData); | ||
| return res.status(201).json({ | ||
| msg: 'Posting created', | ||
| }); | ||
| } catch (error) { | ||
| return res.status(500).json({ | ||
| msg: 'Unexpected error. Please try again later', | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| async function handlePostRequest(req: NextApiRequest, res: NextApiResponse) { | ||
| const userToken = req.headers['authorization'] as string; | ||
| const isAuthorized = await userIsAuthorized(userToken, ['hacker']); | ||
|
|
||
| if (!isAuthorized) { | ||
| return res.status(403).json({ | ||
| statusCode: 403, | ||
| msg: 'Request is not authorized to perform admin functionality', | ||
| }); | ||
| } | ||
|
|
||
| return createPosting(req, res); | ||
| } | ||
|
|
||
| export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
| const { method } = req; | ||
| switch (method) { | ||
| case 'POST': { | ||
| return handlePostRequest(req, res); | ||
| } | ||
| default: { | ||
| return res.status(404).json({ | ||
| msg: 'Route not found', | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { firestore } from 'firebase-admin'; | ||
| import { NextApiRequest, NextApiResponse } from 'next'; | ||
| import initializeApi from '../../../lib/admin/init'; | ||
| import { userIsAuthorized } from '../../../lib/authorization/check-authorization'; | ||
|
|
||
| initializeApi(); | ||
| const db = firestore(); | ||
| const POSTINGS_COLLECTION = '/postings'; | ||
|
|
||
| interface PostingData { | ||
| postingId: string; | ||
| } | ||
|
|
||
| async function deletePosting(req: NextApiRequest, res: NextApiResponse) { | ||
| try { | ||
| const postingData: PostingData = JSON.parse(req.body); | ||
| const snapshot = await db.collection(POSTINGS_COLLECTION).doc(postingData.postingId).get(); | ||
|
|
||
| if (!snapshot.exists) { | ||
| return res.status(404).json({ | ||
| msg: 'Posting not found', | ||
| }); | ||
| } | ||
|
|
||
| await db.collection(POSTINGS_COLLECTION).doc(postingData.postingId).delete(); | ||
| return res.status(200).json({ | ||
| msg: 'Posting deleted', | ||
| }); | ||
| } catch (error) { | ||
| return res.status(500).json({ | ||
| msg: 'Unexpected error. Please try again later', | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| async function handleDeletionRequest(req: NextApiRequest, res: NextApiResponse) { | ||
| const userToken = req.headers['authorization'] as string; | ||
| const isAuthorized = await userIsAuthorized(userToken, ['hacker']); | ||
|
|
||
| if (!isAuthorized) { | ||
| return res.status(403).json({ | ||
| msg: 'Request is not allowed to perform hacker functionality', | ||
| }); | ||
| } | ||
|
|
||
| return deletePosting(req, res); | ||
| } | ||
|
|
||
| export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
| const { method } = req; | ||
| switch (method) { | ||
| case 'POST': { | ||
| return handleDeletionRequest(req, res); | ||
| } | ||
| default: { | ||
| return res.status(404).json({ | ||
| msg: 'Route not found', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.