Skip to content

Commit

Permalink
Merge branch 'main' into dev/alex/rsvp
Browse files Browse the repository at this point in the history
  • Loading branch information
aletya authored Oct 19, 2023
2 parents 1eeb6a4 + 1347b61 commit e806ac5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import authRouter from "./services/auth/auth-router.js";
import userRouter from "./services/user/user-router.js";
import eventRouter from "./services/event/event-router.js";
import profileRouter from "./services/profile/profile-router.js";
import staffRouter from "./services/staff/staff-router.js";
import newsletterRouter from "./services/newsletter/newsletter-router.js";
import rsvpRouter from "./services/rsvp/rsvp-router.js";
import versionRouter from "./services/version/version-router.js";
Expand All @@ -32,11 +33,12 @@ app.use(express.json());

// Add routers for each sub-service
app.use("/auth/", authRouter);
app.use("/user/", userRouter);
app.use("/newsletter/", newsletterRouter);
app.use("/event/", eventRouter);
app.use("/newsletter/", newsletterRouter);
app.use("/profile/", profileRouter);
app.use("/rsvp/", rsvpRouter);
app.use("/staff/", staffRouter);
app.use("/user/", userRouter);
app.use("/version/", versionRouter);

// Ensure that API is running
Expand Down
18 changes: 7 additions & 11 deletions src/database/event-db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { modelOptions, prop } from "@typegoose/typegoose";
import { ObjectId } from "mongodb";

import Constants from "../constants.js";
import { GenericEventFormat } from "../services/event/event-formats.js";
Expand Down Expand Up @@ -56,13 +55,10 @@ class BaseEvent {
@prop({ required: true })
public isAsync: boolean;

constructor(baseEvent: GenericEventFormat, setId: boolean = true) {
const id: string = new ObjectId().toHexString();
if (setId) {
this.eventId = id;
}
this.description = baseEvent.description;
constructor(baseEvent: GenericEventFormat) {
this.eventId = baseEvent.eventId;
this.name = baseEvent.name;
this.description = baseEvent.description;
this.startTime = baseEvent.startTime;
this.endTime = baseEvent.endTime;
this.locations = baseEvent.locations;
Expand Down Expand Up @@ -100,8 +96,8 @@ export class PublicEvent extends BaseEvent {
@prop({ required: true })
public points: number;

constructor(baseEvent: GenericEventFormat, setId: boolean = true) {
super(baseEvent, setId);
constructor(baseEvent: GenericEventFormat) {
super(baseEvent);
this.eventType = baseEvent.publicEventType ?? "OTHER";
this.isPrivate = baseEvent.isPrivate ?? false;
this.displayOnStaffCheckIn = baseEvent.displayOnStaffCheckIn ?? false;
Expand All @@ -111,8 +107,8 @@ export class PublicEvent extends BaseEvent {
}

export class StaffEvent extends BaseEvent {
constructor(baseEvent: GenericEventFormat, setId: boolean = true) {
super(baseEvent, setId);
constructor(baseEvent: GenericEventFormat) {
super(baseEvent);
this.eventType = baseEvent.staffEventType ?? "OTHER";
}
}
Expand Down
1 change: 1 addition & 0 deletions src/services/auth/auth-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface ProfileData {
login?: string;
email: string;
displayName?: string;
name?: string;
}

export interface RoleData {
Expand Down
2 changes: 1 addition & 1 deletion src/services/auth/auth-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ authRouter.get(
const redirect: string = Constants.REDIRECT_MAPPINGS.get(device) ?? Constants.DEFAULT_REDIRECT;

data.id = data.id ?? user.id;
data.displayName = data.displayName ?? data.login;
data.displayName = data.name ?? data.displayName ?? data.login;

try {
// Load in the payload with the actual values stored in the database
Expand Down
18 changes: 11 additions & 7 deletions src/services/event/event-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,29 @@ eventsRouter.post("/", strongJwtVerification, async (req: Request, res: Response
const eventId: string = crypto.randomBytes(Constants.EVENT_BYTES_GEN).toString("hex");
const isStaffEvent: boolean = eventFormat.isStaff;
const metadata: EventMetadata = new EventMetadata(eventId, isStaffEvent, eventFormat.endTime);

console.log(eventId);
// Populate the new eventFormat object with the needed params
eventFormat._id = new ObjectId().toString();
eventFormat.eventId = eventId;

// Try to upload the events if possible, else throw an error
let newEvent: PublicEvent | StaffEvent | null;

if (isStaffEvent) {
// If ID doesn't exist -> return the invalid parameters
if (!isValidStaffFormat(eventFormat)) {
return res.status(Constants.BAD_REQUEST).send({ error: "InvalidParams" });
}

newEvent = await Models.StaffEvent.create(eventFormat);
const event: StaffEvent = new StaffEvent(eventFormat);
console.log(event, metadata);
newEvent = await Models.StaffEvent.create(event);
} else {
if (!isValidPublicFormat(eventFormat)) {
return res.status(Constants.BAD_REQUEST).send({ error: "InvalidParams" });
}

newEvent = await Models.PublicEvent.create(eventFormat);
const event: PublicEvent = new PublicEvent(eventFormat);
console.log(event, metadata);
newEvent = await Models.PublicEvent.create(event);
}
await Models.EventMetadata.create(metadata);
return res.status(Constants.CREATED).send(newEvent);
Expand Down Expand Up @@ -611,14 +614,15 @@ eventsRouter.put("/", strongJwtVerification, async (req: Request, res: Response)
return res.status(Constants.BAD_REQUEST).send({ message: "InvalidParams" });
}

const event: StaffEvent = new StaffEvent(eventFormat, false);
const event: StaffEvent = new StaffEvent(eventFormat);
const updatedEvent: StaffEvent | null = await Models.StaffEvent.findOneAndUpdate({ eventId: eventId }, event);
return res.status(Constants.SUCCESS).send(updatedEvent);
} else {
if (!isValidPublicFormat(eventFormat)) {
return res.status(Constants.BAD_REQUEST).send({ message: "InvalidParams" });
}
const event: PublicEvent = new PublicEvent(eventFormat, false);

const event: PublicEvent = new PublicEvent(eventFormat);
const updatedEvent: PublicEvent | null = await Models.PublicEvent.findOneAndUpdate({ eventId: eventId }, event);
return res.status(Constants.SUCCESS).send(updatedEvent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/staff/staff-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ staffRouter.post("/attendance/", strongJwtVerification, async (req: Request, res
return res.status(Constants.BAD_REQUEST).send({ error: "InvalidParams" });
}

const metadata: EventMetadata | null = await Models.EventMetadata.findById(eventId);
const metadata: EventMetadata | null = await Models.EventMetadata.findOne({ eventId: eventId });

if (!metadata) {
return res.status(Constants.BAD_REQUEST).send({ error: "EventNotFound" });
Expand Down

0 comments on commit e806ac5

Please sign in to comment.