Skip to content

Commit

Permalink
feat(seeders): add learner, tutor, and tutor services seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Nov 15, 2024
1 parent 77c1c7d commit eb34b42
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 129 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PORT=
FIREBASE_SERVICE_ACCOUNT_KEY=
FIREBASE_DATABASE_URL=
GCS_BUCKET_NAME=
GCS_BUCKET_NAME=
GROQ_KEY=
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"express": "^4.21.1",
"express-rate-limit": "^7.4.1",
"firebase-admin": "^12.7.0",
"groq-sdk": "^0.8.0",
"helmet": "^8.0.0",
"morgan": "^1.10.0",
"multer": "1.4.5-lts.1",
Expand All @@ -27,6 +28,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@faker-js/faker": "^9.2.0",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
Expand Down
98 changes: 98 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/express.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import type { Learner, Tutor } from "./types";

// https://stackoverflow.com/a/69328045/13838937
// To make a property non-optional
type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };

type LearnerWithId = WithRequired<Learner, "id">;
type TutorWithId = WithRequired<Tutor, "id">;

declare global {
namespace Express {
interface Request {
learner: Learner;
tutor: Tutor;
learner: LearnerWithId;
tutor: TutorWithId;
}
}
}
2 changes: 1 addition & 1 deletion src/schemas/learner.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { validateInterests } from "@services/learner.service";
import { z } from "zod";

export const learnerSchema = z.object({
id: z.string(),
id: z.string().optional(),
name: z.string().min(3, "Name must be at least 3 characters"),
phoneNum: z
.string()
Expand Down
31 changes: 1 addition & 30 deletions src/schemas/tutor.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { checkTutorExists, validateServices } from "@services/tutor.service";
import { z } from "zod";

export const tutorSchema = z.object({
id: z.string(),
id: z.string().optional(),
name: z.string().min(3, "Name must be at least 3 characters"),
phoneNum: z
.string()
Expand Down Expand Up @@ -49,32 +49,3 @@ export const updateProfileSchema = z.object({
lastSeen: true,
}),
});

export const tutorServiceSchema = z.object({
id: z.string(),
tutorId: z.string().superRefine(async (tutorId, ctx) => {
const exists = await checkTutorExists(tutorId);
if (!exists) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Tutor does not exist",
});
}
}),
subjectId: z.string().superRefine(async (subjectId, ctx) => {
const exists = await checkSubjectExists(subjectId);
if (!exists) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Subject does not exist",
});
}
}),
// About the tutor's experience with the subject
aboutYou: z.string().optional(),
// Tutor's teaching methodology
teachingMethodology: z.string().optional(),
hourlyRate: z.number().optional(),
createdAt: z.date(),
updatedAt: z.date().optional(),
});
32 changes: 32 additions & 0 deletions src/schemas/tutorService.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { checkSubjectExists } from "@services/subject.service";
import { checkTutorExists } from "@services/tutor.service";
import { z } from "zod";

export const tutorServiceSchema = z.object({
id: z.string().optional(),
tutorId: z.string().superRefine(async (tutorId, ctx) => {
const exists = await checkTutorExists(tutorId);
if (!exists) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Tutor does not exist",
});
}
}),
subjectId: z.string().superRefine(async (subjectId, ctx) => {
const exists = await checkSubjectExists(subjectId);
if (!exists) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Subject does not exist",
});
}
}),
// About the tutor's experience with the subject
aboutYou: z.string(),
// Tutor's teaching methodology
teachingMethodology: z.string(),
hourlyRate: z.number(),
createdAt: z.date(),
updatedAt: z.date().optional(),
});
Loading

0 comments on commit eb34b42

Please sign in to comment.