-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/arnav/home-page
- Loading branch information
Showing
63 changed files
with
2,547 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# MacOS autogenerated files | ||
.DS_Store | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RequestHandler } from "express"; | ||
import BackgroundImageModel from "src/models/BackgroundImage"; | ||
|
||
export const getBackgroundImages: RequestHandler = async (req, res, next) => { | ||
const { page } = req.query; | ||
try { | ||
const images = await BackgroundImageModel.find({ page }); | ||
res.status(200).json(images); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { RequestHandler } from "express"; | ||
import { validationResult } from "express-validator"; | ||
import createHttpError from "http-errors"; | ||
import EventDetails from "src/models/eventDetails"; | ||
import validationErrorParser from "src/util/validationErrorParser"; | ||
|
||
export const getAllEventDetails: RequestHandler = async (req, res, next) => { | ||
try { | ||
const events = await EventDetails.find({}); | ||
|
||
if (!events) { | ||
res.status(200).json({ message: "No events found." }); | ||
} | ||
res.status(200).json(events); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const getEventDetails: RequestHandler = async (req, res, next) => { | ||
const { id } = req.params; | ||
|
||
try { | ||
const eventDetails = await EventDetails.findById(id); | ||
|
||
if (!eventDetails) { | ||
throw createHttpError(404, "Event not found."); | ||
} | ||
|
||
res.status(200).json(eventDetails); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const createEventDetails: RequestHandler = async (req, res, next) => { | ||
const errors = validationResult(req); | ||
const { name, description, guidelines, date, location, imageURI } = req.body; | ||
|
||
try { | ||
validationErrorParser(errors); | ||
|
||
const eventDetails = await EventDetails.create({ | ||
name, | ||
description, | ||
guidelines, | ||
date, | ||
location, | ||
imageURI, | ||
}); | ||
|
||
res.status(201).json(eventDetails); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const updateEventDetails: RequestHandler = async (req, res, next) => { | ||
const errors = validationResult(req); | ||
const { id } = req.params; | ||
|
||
if (id !== req.body._id) { | ||
// If the _id in the URL does not match the _id in the body, bad request | ||
res.status(400); | ||
} | ||
|
||
try { | ||
validationErrorParser(errors); | ||
|
||
const eventDetails = await EventDetails.findByIdAndUpdate(id, req.body); | ||
if (eventDetails === null) { | ||
// No event found | ||
res.status(404); | ||
} | ||
const updatedEventDetails = await EventDetails.findById(id); | ||
if (updatedEventDetails === null) { | ||
// No event found, something went wrong | ||
res.status(404); | ||
} | ||
res.status(200).json(updatedEventDetails); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { RequestHandler } from "express"; | ||
import VolunteerDetails from "../models/volunteerDetails"; | ||
|
||
export const getVolunteer: RequestHandler = async (req, res, next) => { | ||
const { id } = req.params; | ||
|
||
try { | ||
const volunteer = await VolunteerDetails.findById(id); | ||
|
||
if (!volunteer) { | ||
return res.status(404).json({ error: "Volunteer not found." }); | ||
} | ||
|
||
res.status(200).json(volunteer); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const getAllVolunteers: RequestHandler = async (req, res, next) => { | ||
try { | ||
const volunteers = await VolunteerDetails.find({}); | ||
|
||
if (!volunteers || volunteers.length === 0) { | ||
return res.status(200).json({ message: "No volunteers yet!" }); | ||
} | ||
|
||
res.status(200).json(volunteers); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const addVolunteer: RequestHandler = async (req, res, next) => { | ||
// Extract volunteer data from the request body | ||
const volunteerData = req.body; | ||
|
||
try { | ||
// Check if any of the required fields are missing | ||
const requiredProperties = [ | ||
"first_name", | ||
"last_name", | ||
"email", | ||
"phone", | ||
"signed_up_for_updates", | ||
]; | ||
|
||
for (const prop of requiredProperties) { | ||
if (!Object.prototype.hasOwnProperty.call(volunteerData, prop)) { | ||
return res | ||
.status(400) | ||
.json({ error: `Missing property: ${prop}. Please provide all required fields.` }); | ||
} | ||
} | ||
|
||
// Create a new volunteer using the extracted data | ||
const newVolunteer = await VolunteerDetails.create(volunteerData); | ||
|
||
// Respond with the newly created volunteer | ||
return res.status(201).json(newVolunteer); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { InferSchemaType, Schema, model } from "mongoose"; | ||
|
||
export enum BackgroundImagePages { | ||
TEAM = "TEAM", | ||
HOME = "HOME", | ||
} | ||
|
||
const backgroundImageSchema = new Schema({ | ||
imageURI: { type: String, required: true }, | ||
page: { type: String, required: true }, | ||
}); | ||
|
||
type BackgroundImage = InferSchemaType<typeof backgroundImageSchema>; | ||
|
||
export default model<BackgroundImage>("BackgroundImage", backgroundImageSchema); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { InferSchemaType, Schema, model } from "mongoose"; | ||
|
||
const eventDetailsSchema = new Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
guidelines: { type: String, required: true }, | ||
date: { type: String, required: true }, | ||
location: { type: String, required: true }, | ||
imageURI: { type: String, required: true }, // TODO: Change this if necessary | ||
// empty by default, stores _id of volunteers | ||
volunteers: { type: [String], required: false, default: [] }, | ||
}); | ||
|
||
type EventDetails = InferSchemaType<typeof eventDetailsSchema>; | ||
|
||
export default model<EventDetails>("EventDetails", eventDetailsSchema); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { InferSchemaType, Schema, model } from "mongoose"; | ||
|
||
const volunteerDetailsSchema = new Schema({ | ||
first_name: { | ||
type: String, | ||
required: true, | ||
}, | ||
last_name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
phone: { | ||
type: String, | ||
required: true, | ||
}, | ||
signed_up_for_updates: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}); | ||
|
||
type VolunteerDetails = InferSchemaType<typeof volunteerDetailsSchema>; | ||
|
||
export default model<VolunteerDetails>("VolunteerDetails", volunteerDetailsSchema); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
import * as BackgroundImageController from "src/controllers/BackgroundImage"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/get", BackgroundImageController.getBackgroundImages); | ||
|
||
export default router; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import express from "express"; | ||
import * as EventDetailsController from "src/controllers/eventDetails"; | ||
import * as EventDetailsValidator from "src/validators/eventDetails"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/", EventDetailsController.getAllEventDetails); | ||
router.get("/:id", EventDetailsValidator.getEventDetails, EventDetailsController.getEventDetails); | ||
router.put( | ||
"/:id", // getEventDetails validator works to just check ID | ||
EventDetailsValidator.getEventDetails, | ||
EventDetailsController.updateEventDetails, | ||
); | ||
router.post( | ||
"/", | ||
EventDetailsValidator.createEventDetails, | ||
EventDetailsController.createEventDetails, | ||
); | ||
|
||
export default router; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import express from "express"; | ||
import { getVolunteer, getAllVolunteers, addVolunteer } from "../controllers/volunteeerDetails"; | ||
|
||
const volunteerDetailsRoutes = express.Router(); | ||
|
||
// Define routes | ||
volunteerDetailsRoutes.get("/:id", getVolunteer); | ||
volunteerDetailsRoutes.get("/", getAllVolunteers); | ||
volunteerDetailsRoutes.post("/", addVolunteer); | ||
|
||
export default volunteerDetailsRoutes; |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { body } from "express-validator"; | ||
|
||
const makeIDValidator = () => | ||
body("_id") | ||
.exists() | ||
.withMessage("_id is required") | ||
.bail() | ||
.isMongoId() | ||
.withMessage("_id must be a MongoDB object ID"); | ||
const makeNameValidator = () => | ||
body("name") | ||
.exists() | ||
.withMessage("name is required") | ||
.bail() | ||
.isString() | ||
.withMessage("name must be a string"); | ||
const makeDescriptionValidator = () => | ||
body("description") | ||
.exists() | ||
.withMessage("description is required") | ||
.bail() | ||
.isString() | ||
.withMessage("description must be a string"); | ||
const makeGuidlinesValidator = () => | ||
body("guidelines") | ||
.exists() | ||
.withMessage("guidelines is required") | ||
.bail() | ||
.isString() | ||
.withMessage("guidelines must be a string"); | ||
const makeDateValidator = () => | ||
body("date") | ||
.exists() | ||
.withMessage("date is required") | ||
.bail() | ||
.isString() | ||
.withMessage("date must be a string"); | ||
const makeLocationValidator = () => | ||
body("location") | ||
.exists() | ||
.withMessage("location is required") | ||
.bail() | ||
.isString() | ||
.withMessage("location must be a string"); | ||
const makeImageURIValidator = () => | ||
body("imageURI") | ||
.exists() | ||
.withMessage("imageURI is required") | ||
.bail() | ||
.isString() | ||
.withMessage("imageURI must be a string") | ||
.bail() | ||
.isURL() | ||
.withMessage("imageURI must be a URL"); | ||
|
||
export const createEventDetails = [ | ||
makeNameValidator(), | ||
makeDescriptionValidator(), | ||
makeGuidlinesValidator(), | ||
makeDateValidator(), | ||
makeLocationValidator(), | ||
makeImageURIValidator(), | ||
]; | ||
|
||
export const getEventDetails = [makeIDValidator()]; |
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
Oops, something went wrong.