Skip to content
Merged
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
17 changes: 12 additions & 5 deletions server/src/routers/mentorship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ const createMentor = protectedProcedure
tags: ["Mentorship"],
},
})
.mutation(({ input }) =>
.mutation(({ input, ctx }) =>
withErrorHandling("", async () => {
log.debug({ userId: input.userId }, "createMentor");
return await mentorshipService.createMentor(input);
const userId = ctx.auth.user.id;
log.debug({ userId }, "createMentor");
return await mentorshipService.createMentor({
...input,
userId,
});
}),
);

Expand All @@ -50,9 +54,12 @@ const createMentee = protectedProcedure
tags: ["Mentorship"],
},
})
.mutation(({ input }) =>
.mutation(({ input, ctx }) =>
withErrorHandling("createMentee", async () => {
return await mentorshipService.createMentee(input);
return await mentorshipService.createMentee({
...input,
userId: ctx.auth.user.id,
});
}),
);

Expand Down
5 changes: 3 additions & 2 deletions server/src/types/mentee-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const menteeSchema = z.object({
export type MenteeSchema = z.infer<typeof menteeSchema>;

export const createMenteeInputSchema = z.object({
userId: z.string(),
learningGoals: z.string().optional(),
experienceLevel: z.string().optional(),
preferredMentorType: z.string().optional(),
Expand Down Expand Up @@ -59,7 +58,9 @@ export const getMenteesByUserInputSchema = z.object({
userId: z.string(),
});

export type CreateMenteeInput = z.infer<typeof createMenteeInputSchema>;
export type CreateMenteeInput = z.infer<typeof createMenteeInputSchema> & {
userId: string;
};
export type UpdateMenteeInput = z.infer<typeof updateMenteeInputSchema>;
export type GetMenteeInput = z.infer<typeof getMenteeInputSchema>;
export type GetMenteesByUserInput = z.infer<typeof getMenteesByUserInputSchema>;
Expand Down
5 changes: 3 additions & 2 deletions server/src/types/mentor-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const mentorSchema = z.object({
export type MentorSchema = z.infer<typeof mentorSchema>;

export const createMentorInputSchema = z.object({
userId: z.string(),
mentorshipPreferences: z.string().optional(),
yearsOfService: z.number().int().nonnegative().optional(),
eligibilityData: z.record(z.string(), z.unknown()).nullish(),
Expand Down Expand Up @@ -70,7 +69,9 @@ export const createMentorInputSchema = z.object({
hoursPerMonthCommitment: z.number().int().positive().optional(),
});

export type CreateMentorInput = z.infer<typeof createMentorInputSchema>;
export type CreateMentorInput = z.infer<typeof createMentorInputSchema> & {
userId: string;
};

export const createMentorOutputSchema = z.object({
mentorId: z.number(),
Expand Down
9 changes: 0 additions & 9 deletions web/src/app/mentorship/apply/mentee/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DropzoneContent,
DropzoneEmptyState,
} from "@/components/ui/shadcn-io/dropzone";
import { authClient } from "@/lib/auth-client";
import { useTRPC, useTRPCClient } from "@/lib/trpc";

type ResumeState = null | {
Expand Down Expand Up @@ -66,8 +65,6 @@ export default function MentorshipApplyMenteePage() {
const queryClient = useQueryClient();
const router = useRouter();
const searchParams = useSearchParams();
const { data: sessionData } = authClient.useSession();
const userId = sessionData?.user?.id ?? null;
const backHref = useMemo(
() =>
searchParams.get("from") === "dashboard"
Expand Down Expand Up @@ -168,11 +165,6 @@ export default function MentorshipApplyMenteePage() {
}, [resume, trpcClient]);

const handleSubmit = async () => {
if (!userId) {
setFormError("You must be logged in to submit this application.");
return;
}

// Block submit if resume is in a bad state
if (resume?.status === "uploading") {
setFormError("Please wait for the resume upload to complete.");
Expand Down Expand Up @@ -207,7 +199,6 @@ export default function MentorshipApplyMenteePage() {
})();

await createMentee.mutateAsync({
userId,
resumeFileId: resume?.status === "uploaded" ? resume.fileId : undefined,
personalInterests:
selectedInterests.length > 0
Expand Down
10 changes: 0 additions & 10 deletions web/src/app/mentorship/apply/mentor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DropzoneContent,
DropzoneEmptyState,
} from "@/components/ui/shadcn-io/dropzone";
import { authClient } from "@/lib/auth-client";
import { useTRPCClient } from "@/lib/trpc";

type ResumeState = null | {
Expand All @@ -29,8 +28,6 @@ export default function MentorshipApplyMentorPage() {
const trpcClient = useTRPCClient();
const router = useRouter();
const searchParams = useSearchParams();
const { data: sessionData } = authClient.useSession();
const userId = sessionData?.user?.id ?? null;
const backHref = useMemo(
() =>
searchParams.get("from") === "dashboard"
Expand Down Expand Up @@ -134,11 +131,6 @@ export default function MentorshipApplyMentorPage() {
}, [resume, isSubmitted, trpcClient]);

const handleSubmit = useCallback(async () => {
if (!userId) {
setFormError("You must be logged in to submit this application.");
return;
}

setFormError(null);
setIsSubmitting(true);

Expand Down Expand Up @@ -197,7 +189,6 @@ export default function MentorshipApplyMentorPage() {
})();

await createMentor.mutateAsync({
userId,
resumeFileId: resume?.status === "uploaded" ? resume.fileId : undefined,
strengths: selectedQualities,
personalInterests:
Expand Down Expand Up @@ -234,7 +225,6 @@ export default function MentorshipApplyMentorPage() {
setIsSubmitting(false);
}
}, [
userId,
resume,
selectedQualities,
selectedInterests,
Expand Down