-
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.
Merge branch 'main' into dev/alex/s3-service
- Loading branch information
Showing
12 changed files
with
281 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Router } from "express"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { AttendeeValidator } from "./attendee-schema"; | ||
import { Database } from "../../database"; | ||
|
||
const attendeeRouter = Router(); | ||
|
||
// Create a new attendee | ||
attendeeRouter.post("/", async (req, res, next) => { | ||
try { | ||
const attendeeData = AttendeeValidator.parse(req.body); | ||
const attendee = new Database.ATTENDEES(attendeeData); | ||
await attendee.save(); | ||
|
||
return res.status(StatusCodes.CREATED).json(attendeeData); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
// Check if a user email exists | ||
attendeeRouter.get("/:email", async (req, res, next) => { | ||
try { | ||
const { email } = req.params; | ||
|
||
// Check if the user exists in the database | ||
const userExists = await Database.ATTENDEES.exists({ email }); | ||
|
||
if (!userExists) { | ||
return { error: "DoesNotExist" }; | ||
} | ||
|
||
const user = await Database.ATTENDEES.findOne({ | ||
email, | ||
}); | ||
|
||
return res.status(StatusCodes.OK).json(user); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
export default attendeeRouter; |
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,26 @@ | ||
import mongoose from "mongoose"; | ||
import { z } from "zod"; | ||
|
||
// Zod schema for attendee | ||
const AttendeeValidator = z.object({ | ||
userId: z.string(), | ||
name: z.string(), | ||
email: z.string().email(), | ||
events: z.array(z.string()), | ||
dietary_restrictions: z.string(), | ||
priority_expiry: z.date().nullable().optional(), | ||
points: z.number().min(0).default(0), | ||
}); | ||
|
||
// Mongoose schema for attendee | ||
const AttendeeSchema = new mongoose.Schema({ | ||
userId: { type: String, required: true, unique: true }, | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true, unique: true }, | ||
events: [{ type: mongoose.Schema.Types.ObjectId, ref: "Event" }], | ||
dietary_restrictions: { type: String, required: true }, | ||
priority_expiry: { type: Date, default: null }, | ||
points: { type: Number, default: 0 }, | ||
}); | ||
|
||
export { AttendeeSchema, AttendeeValidator }; |
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,82 @@ | ||
import { Router } from "express"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { EventValidator } from "./event-schema"; | ||
import { Database } from "../../database"; | ||
|
||
const eventRouter = Router(); | ||
|
||
// Create a new event | ||
eventRouter.post("/", async (req, res, next) => { | ||
try { | ||
const eventData = EventValidator.parse(req.body); | ||
const event = new Database.EVENTS(eventData); | ||
await event.save(); | ||
return res.status(StatusCodes.CREATED).json(event); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
// Get all events | ||
eventRouter.get("/", async (req, res, next) => { | ||
try { | ||
const events = await Database.EVENTS.find(); | ||
return res.status(StatusCodes.OK).json(events); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
// Get event by ID | ||
eventRouter.get("/:id", async (req, res, next) => { | ||
try { | ||
const event = await Database.EVENTS.findOneAndUpdate( | ||
{ _id: req.params.id }, | ||
{ new: true } | ||
); | ||
|
||
if (!event) { | ||
return { error: "DoesNotExist" }; | ||
} | ||
|
||
return res.status(StatusCodes.OK).json(event); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
// Update event | ||
eventRouter.patch("/:id", async (req, res, next) => { | ||
try { | ||
const event = await Database.EVENTS.findOneAndUpdate( | ||
{ _id: req.params.id }, | ||
req.body, | ||
{ new: true } | ||
); | ||
|
||
if (!event) { | ||
return { error: "DoesNotExist" }; | ||
} | ||
|
||
return res.status(StatusCodes.OK).json(event); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
// Delete event | ||
eventRouter.delete("/:id", async (req, res, next) => { | ||
try { | ||
const event = await Database.EVENTS.findByIdAndDelete(req.params.id); | ||
|
||
if (!event) { | ||
return { error: "DoesNotExist" }; | ||
} | ||
|
||
return res.status(StatusCodes.OK).json(event); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
|
||
export default eventRouter; |
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,47 @@ | ||
import mongoose from "mongoose"; | ||
import { z } from "zod"; | ||
|
||
// Zod schema for event | ||
const EventValidator = z.object({ | ||
name: z.string(), | ||
description: z.string(), | ||
start_time: z.date(), | ||
end_time: z.date(), | ||
attendees: z.array(z.string()), | ||
location: z.array( | ||
z.object({ | ||
description: z.string(), | ||
tags: z.array(z.string()), | ||
latitude: z.number(), | ||
longitude: z.number(), | ||
}) | ||
), | ||
virtual: z.boolean(), | ||
points: z.number().min(0).default(0), | ||
imageUrl: z.string().nullable().optional(), | ||
visible: z.boolean().default(false), | ||
}); | ||
|
||
// Mongoose schema for location | ||
const LocationSchema = new mongoose.Schema({ | ||
description: { type: String, required: true }, | ||
tags: [{ type: String }], | ||
latitude: { type: Number, required: true }, | ||
longitude: { type: Number, required: true }, | ||
}); | ||
|
||
// Mongoose schema for event | ||
const EventSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
start_time: { type: Date, required: true }, | ||
end_time: { type: Date, required: true }, | ||
attendees: [{ type: mongoose.Schema.Types.ObjectId, ref: "Attendee" }], | ||
location: [LocationSchema], | ||
virtual: { type: Boolean, required: true }, | ||
points: { type: Number, default: 0 }, | ||
imageUrl: { type: String, default: null }, | ||
visible: { type: Boolean, default: false }, | ||
}); | ||
|
||
export { EventSchema, EventValidator, LocationSchema }; |
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,10 @@ | ||
import { Router } from "express"; | ||
// import { StatusCodes } from "http-status-codes"; | ||
// import { RegistrationValidator } from "./registration-schema"; | ||
// import { Database } from "../../database"; | ||
|
||
const registrationRouter = Router(); | ||
|
||
// TODO: registration routes | ||
|
||
export default registrationRouter; |
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,50 @@ | ||
import mongoose from "mongoose"; | ||
import { z } from "zod"; | ||
|
||
// Zod schema for registration | ||
const RegistrationValidator = z.object({ | ||
userId: z.string(), | ||
name: z.string(), | ||
email: z.string().email(), | ||
studentInfo: z.object({ | ||
university: z.string().nonempty(), | ||
graduation: z.string().nullable().optional(), | ||
major: z.string().nullable().optional(), | ||
}), | ||
dietary_restrictions: z.string(), | ||
age: z.number().nullable().optional(), | ||
gender: z.string().nullable().optional(), | ||
race: z.array(z.string()).nullable().optional(), | ||
ethnicity: z.array(z.string()).nullable().optional(), | ||
first_gen: z.string().nullable().optional(), | ||
hear_about_rp: z.array(z.string()).nullable().optional(), | ||
portfolio: z.string().nullable().optional(), | ||
job_interest: z.array(z.string()).nullable().optional(), | ||
interest_mech_puzzle: z.array(z.string()).nullable().optional(), | ||
has_resume: z.boolean(), | ||
}); | ||
|
||
// Mongoose schema for registration | ||
const RegistrationSchema = new mongoose.Schema({ | ||
userId: { type: String, required: true, unique: true }, | ||
name: { type: String, required: true }, | ||
email: { type: String, required: true, unique: true }, | ||
studentInfo: { | ||
university: { type: String, required: true }, | ||
graduation: { type: String, default: null }, | ||
major: { type: String, default: null }, | ||
}, | ||
dietary_restrictions: { type: String, required: true }, | ||
age: { type: Number, default: null }, | ||
gender: { type: String, default: null }, | ||
race: [{ type: String }], | ||
ethnicity: [{ type: String }], | ||
first_gen: { type: String, default: null }, | ||
hear_about_rp: [{ type: String }], | ||
portfolio: { type: String, default: null }, | ||
job_interest: [{ type: String }], | ||
interest_mech_puzzle: [{ type: String }], | ||
has_resume: { type: Boolean, default: false }, | ||
}); | ||
|
||
export { RegistrationSchema, RegistrationValidator }; |