Skip to content

Commit

Permalink
registration schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobc2700 committed Apr 9, 2024
1 parent 0057b2a commit 4e64b93
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import errorHandler from "./middleware/error-handler";
import authRouter from "./services/auth/auth-router";
import attendeeRouter from "./services/attendees/attendee-router";
import eventRouter from "./services/events/event-router";
import registrationRouter from "./services/registration/registration-router";

const app = express();

Expand All @@ -26,6 +27,7 @@ app.use("/", bodyParser.json());
app.use("/attendee", attendeeRouter);
app.use("/auth", authRouter);
app.use("/event", eventRouter);
app.use("/registration", registrationRouter);

app.get("/status", (_, res) => {
console.log(StatusCodes.OK);
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getEnv } from "./utilities";

export const Environment = z.enum(["PRODUCTION", "DEVELOPMENT", "TESTING"]);

export const ListName = z.enum(["RP_INTEREST"]);

export const Config = {
DEFAULT_APP_PORT: 3000,
ENV: Environment.parse(getEnv("ENV")),
Expand Down
9 changes: 9 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
AttendeeSchema,
AttendeeValidator,
} from "./services/attendees/attendee-schema";
import {
RegistrationSchema,
RegistrationValidator,
} from "./services/registration/registration-schema";

mongoose.set("toObject", { versionKey: false });

Expand Down Expand Up @@ -39,4 +43,9 @@ export const Database = {
ROLES: initializeModel("roles", RoleSchema, RoleInfo),
EVENTS: initializeModel("events", EventSchema, EventValidator),
ATTENDEES: initializeModel("attendees", AttendeeSchema, AttendeeValidator),
REGISTRATION: initializeModel(
"registration",
RegistrationSchema,
RegistrationValidator
),
};
2 changes: 2 additions & 0 deletions src/services/attendees/attendee-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const AttendeeValidator = z.object({
interest_mech_puzzle: z.array(z.string()).nullable().optional(),
priority_expiry: z.date().nullable().optional(),
has_resume: z.boolean().optional(),
points: z.number().min(0).default(0), //
});

// Mongoose schema for attendee
Expand All @@ -47,6 +48,7 @@ const AttendeeSchema = new mongoose.Schema({
interest_mech_puzzle: [{ type: String }],
priority_expiry: { type: Date, default: null },
has_resume: { type: Boolean, default: false },
points: { type: Number, default: 0 },
});

export { AttendeeSchema, AttendeeValidator };
10 changes: 10 additions & 0 deletions src/services/registration/registration-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { StatusCodes } from "http-status-codes";

Check failure on line 2 in src/services/registration/registration-router.ts

View workflow job for this annotation

GitHub Actions / lint

'StatusCodes' is defined but never used
import { RegistrationValidator } from "./registration-schema";

Check failure on line 3 in src/services/registration/registration-router.ts

View workflow job for this annotation

GitHub Actions / lint

'RegistrationValidator' is defined but never used
import { Database } from "../../database";

Check failure on line 4 in src/services/registration/registration-router.ts

View workflow job for this annotation

GitHub Actions / lint

'Database' is defined but never used

const registrationRouter = Router();

// TODO: registration routes

export default registrationRouter;
22 changes: 22 additions & 0 deletions src/services/registration/registration-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mongoose from "mongoose";
import { z } from "zod";

// Zod schema for registration
const RegistrationValidator = z.object({
name: z.string(),
email: z.string().email(),
events: z.array(z.string()),
dietary_restrictions: z.string(),
points: z.number().min(0).default(0),
});

// Mongoose schema for registration
const RegistrationSchema = new mongoose.Schema({
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 },
points: { type: Number, default: 0 },
});

export { RegistrationSchema, RegistrationValidator };

0 comments on commit 4e64b93

Please sign in to comment.