Skip to content

Commit

Permalink
Merge branch 'main' into email-notifications-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jasozh committed Jun 2, 2024
2 parents 29d2d4d + dc0ac40 commit 3e19f20
Show file tree
Hide file tree
Showing 26 changed files with 775 additions and 199 deletions.
79 changes: 64 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
</p>
</div>



<!-- TABLE OF CONTENTS -->
<details>
<summary>Table of Contents</summary>
Expand All @@ -35,34 +33,35 @@
</ol>
</details>

<!-- ABOUT THE PROJECT -->

## About the Project

<!-- ABOUT THE PROJECT -->
## About The Project
This project aims to develop a volunteer management system for Lagos Food Bank Initiative. The system will allow volunteers to sign up for shifts, and for LFBI to manage volunteers and hours.
This project aims to develop a volunteer management system for Lagos Food Bank Initiative. The system will allow volunteers to sign up for shifts, and for LFBI to manage volunteers and hours.

### Built With

* [![Next][Next.js]][Next-url]
* [![React][React.js]][React-url]
* [![Express][Express.js]][Express-url]
* [![Postresql][Prisma.io]][Prisma-url]
- [![Next][Next.js]][Next-url]
- [![React][React.js]][React-url]
- [![Express][Express.js]][Express-url]
- [![Postresql][Prisma.io]][Prisma-url]

<!-- GETTING STARTED -->
## Getting Started

## Getting Started

> Folder structure
> Folder structure
.
├── frontend # Next.js client
├── backend # Express server
└── README.md

### Prerequisites
* Nodejs
* PostreSQL
* Docker

- Nodejs
- PostreSQL
- Docker

### Installation

Expand All @@ -85,9 +84,60 @@ This project aims to develop a volunteer management system for Lagos Food Bank I

> Note: See individual project files for more information on how to build and deploy the project.

## Contributors

### Spring 2024

- Leads
- Akinfolami Akin-Alamu
- Jason Zheng
- Developers
- Arushi Aggarwal
- Owen Chen
- Hubert He
- Trung-Nghia Le
- Brandon Lerit
- Diego Marques
- Tanvi Mavani
- David Valarezo

### Fall 2023

- Leads
- Akinfolami Akin-Alamu
- Jason Zheng
- Developers
- Sneha Rajaraman
- Daniel Thorne
- Louis Valencia
- Sophie Wang
- Yichen Yao
- Hannah Zhang
- Designers
- Ella Keen Allee
- Bella Besuud
- Mika Labadan

### Spring 2023

- Leads
- Akinfolami Akin-Alamu
- Jason Zheng
- Developers
- Jiayi Bai
- Daniel Botros
- Sneha Rajaraman
- Sophie Wang
- Yichen Yao
- Hannah Zhang
- Designers
- Bella Besuud
- Mika Labadan
- Julia Papp

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[Next.js]: https://img.shields.io/badge/next.js-000000?style=for-the-badge&logo=nextdotjs&logoColor=white
[Next-url]: https://nextjs.org/
[React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
Expand All @@ -96,4 +146,3 @@ This project aims to develop a volunteer management system for Lagos Food Bank I
[Express.js]: https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge&logo=express&logoColor=%2361DAFB
[Express-url]: https://expressjs.com/
[Prisma-url]: https://www.prisma.io/

11 changes: 8 additions & 3 deletions backend/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
"in": "query",
"type": "string"
},
{
"name": "attendeeStatus",
"in": "query",
"type": "string"
},
{
"name": "sort",
"in": "query",
Expand Down Expand Up @@ -785,8 +790,8 @@
}
}
},
"/events/{eventid}/users/{userid}": {
"put": {
"/events/{eventid}/attendees/{userid}/attendee-status": {
"patch": {
"tags": [
"Events"
],
Expand All @@ -810,7 +815,7 @@
"schema": {
"type": "object",
"properties": {
"status": {
"attendeeStatus": {
"example": "any"
}
}
Expand Down
33 changes: 25 additions & 8 deletions backend/src/about/views.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { Router, RequestHandler, Request, Response } from "express";
import { auth, NoAuth } from "../middleware/auth";
import {
auth,
NoAuth,
authIfAdmin,
authIfSupervisor,
} from "../middleware/auth";
import { attempt } from "../utils/helpers";
import aboutController from "./controllers";

const aboutRouter = Router();

let useAuth: RequestHandler;
let useAdminAuth: RequestHandler;
let useSupervisorAuth: RequestHandler;

process.env.NODE_ENV === "test"
? (useAuth = NoAuth as RequestHandler)
: (useAuth = auth as RequestHandler);
? ((useAuth = NoAuth as RequestHandler),
(useAdminAuth = NoAuth as RequestHandler),
(useSupervisorAuth = NoAuth as RequestHandler))
: ((useAuth = auth as RequestHandler),
(useAdminAuth = authIfAdmin as RequestHandler),
(useSupervisorAuth = authIfSupervisor as RequestHandler));

aboutRouter.get("/", useAuth, async (req: Request, res: Response) => {
attempt(res, 200, () => aboutController.getAboutPageContent());
});

aboutRouter.patch("/:pageid", useAuth, async (req: Request, res: Response) => {
const { newContent } = req.body;
attempt(res, 200, () => aboutController.updateAboutPageContent(req.params.pageid, newContent));
});
aboutRouter.patch(
"/:pageid",
useAdminAuth,
async (req: Request, res: Response) => {
const { newContent } = req.body;
attempt(res, 200, () =>
aboutController.updateAboutPageContent(req.params.pageid, newContent)
);
}
);

export default aboutRouter;
export default aboutRouter;
27 changes: 25 additions & 2 deletions backend/src/events/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const getEvents = async (
pagination: {
after: string;
limit: string;
},
include: {
attendees: boolean;
}
) => {
/* SORTING */
Expand Down Expand Up @@ -116,7 +119,7 @@ const getEvents = async (
/* FILTERING */

let whereDict: { [key: string]: any } = {};
let includeDict: { [key: string]: any } = {};
let includeDict: { [key: string]: any } = include;

// Handles GET /events?date=upcoming and GET /events?date=past
// TODO: Investigate creating events that occur in a few minutes into the future
Expand Down Expand Up @@ -264,6 +267,18 @@ const getEvent = async (eventID: string) => {
});
};

/**
* Returns a boleean indicating whether event is past or not
* @param eventID (String)
* @returns promise with boolean or error
*/
export const isEventPast = async (eventID: string) => {
const currentDateTime = new Date();
const event = (await getEvent(eventID)) as Event;
const eventDate = new Date(event.startDate);
return eventDate < currentDateTime;
};

/**
* Gets all attendees registered for an event
* @param eventID (String)
Expand Down Expand Up @@ -333,8 +348,9 @@ const addAttendee = async (eventID: string, userID: string) => {
var eventDateTimeUnknown = event?.startDate as unknown;
var eventDateTimeString = eventDateTimeUnknown as string;
var textBody = "Your registration was successful.";
const eventIsInThePast = await isEventPast(eventID);

if (process.env.NODE_ENV != "test") {
if (process.env.NODE_ENV != "test" && !eventIsInThePast) {
// creates updated html path with the changed inputs
const updatedHtml = replaceEventInputs(
stringEventUpdate,
Expand All @@ -353,6 +369,9 @@ const addAttendee = async (eventID: string, userID: string) => {
);
}
}
if (eventIsInThePast) {
return Promise.reject("Event is past, cannot enroll new user");
}
return await prisma.eventEnrollment.create({
data: {
event: {
Expand Down Expand Up @@ -433,6 +452,10 @@ const deleteAttendee = async (
* @returns promise with event or error
*/
const updateEventStatus = async (eventID: string, status: string) => {
if (await isEventPast(eventID)) {
return Promise.reject("Event is past, cannot update status");
}

return await prisma.event.update({
where: {
id: eventID,
Expand Down
Loading

0 comments on commit 3e19f20

Please sign in to comment.