Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor speakers/registration schemas and db #120

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
EventAttendanceValidator,
} from "./services/events/events-schema";
import { RoleValidator, RoleSchema } from "./services/auth/auth-schema";
import {
RegistrationSchema,
RegistrationValidator,
} from "./services/registration/registration-schema";
import { RegistrationSchema } from "./services/registration/registration-schema";
import {
SubscriptionSchemaValidator,
SubscriptionSchema,
Expand All @@ -24,10 +21,7 @@ import {
NotificationsSchema,
NotificationsValidator,
} from "./services/notifications/notifications-schema";
import {
SpeakerSchema,
SpeakerValidator,
} from "./services/speakers/speakers-schema";
import { SpeakerSchema } from "./services/speakers/speakers-schema";
import {
SponsorAuthSchema,
SponsorAuthValidator,
Expand Down Expand Up @@ -86,11 +80,7 @@ export const Database = {
SubscriptionSchema,
SubscriptionSchemaValidator
),
REGISTRATION: initializeModel(
"registration",
RegistrationSchema,
RegistrationValidator
),
REGISTRATION: mongoose.model("registration", RegistrationSchema),
NOTIFICATIONS: initializeModel(
"notifications",
NotificationsSchema,
Expand All @@ -101,7 +91,7 @@ export const Database = {
SponsorAuthSchema,
SponsorAuthValidator
),
SPEAKERS: initializeModel("speakers", SpeakerSchema, SpeakerValidator),
SPEAKERS: mongoose.model("speakers", SpeakerSchema),
CORPORATE: initializeModel(
"corporate",
CorporateSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/services/speakers/speakers-router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Router } from "express";
import { StatusCodes } from "http-status-codes";
import { SpeakerValidator } from "./speakers-schema";
import { SpeakerValidator } from "./speakers-validators";
import { Database } from "../../database";
import RoleChecker from "../../middleware/role-checker";
import { Role } from "../auth/auth-models";
Expand Down
12 changes: 0 additions & 12 deletions src/services/speakers/speakers-schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import { Schema } from "mongoose";
import { z } from "zod";
import { v4 as uuidv4 } from "uuid";

// Zod schema for speaker
export const SpeakerValidator = z.object({
speakerId: z.coerce.string().default(() => uuidv4()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldnt be needed - also make changes to speaker, so that we have the following:

GET /speakers/:SPEAKERID

PUT /speakers/:SPEAKERID

POST /speakers/ (create speakerid)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those endpoints were added already ?

name: z.string(),
title: z.string(),
bio: z.string(),
eventTitle: z.string(),
eventDescription: z.string(),
imgUrl: z.string(),
});

// Mongoose schema for speaker
export const SpeakerSchema = new Schema({
speakerId: {
Expand Down
11 changes: 11 additions & 0 deletions src/services/speakers/speakers-validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z } from "zod";

// Zod schema for speaker
export const SpeakerValidator = z.object({
name: z.string(),
title: z.string(),
bio: z.string(),
eventTitle: z.string(),
eventDescription: z.string(),
imgUrl: z.string(),
});