Spaces:
Sleeping
Sleeping
Download backend/src/controllers/profile.controller.ts from cuteepeiarchu/PathFinders: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/cuteepeiarchu/PathFinders/resolve/main/backend/src/controllers/profile.controller.ts
- Command line
-
hf download hf://spaces/cuteepeiarchu/PathFinders/backend/src/controllers/profile.controller.ts
-
curl -L -o profile.controller.ts https://huggingface.co/spaces/cuteepeiarchu/PathFinders/resolve/main/backend/src/controllers/profile.controller.ts
1.72 kB
| import { NextFunction, Request, Response } from "express"; | |
| import { profileService } from "../services/profile.service"; | |
| import { AppError } from "../utils/appError"; | |
| export const profileController = { | |
| getMe(request: Request, response: Response, next: NextFunction) { | |
| try { | |
| if (!request.authUserId) { | |
| throw new AppError("Unauthorized.", 401); | |
| } | |
| const data = profileService.getProfile(request.authUserId); | |
| response.json({ success: true, data }); | |
| } catch (error) { | |
| next(error); | |
| } | |
| }, | |
| saveMe(request: Request, response: Response, next: NextFunction) { | |
| try { | |
| if (!request.authUserId) { | |
| throw new AppError("Unauthorized.", 401); | |
| } | |
| const { age, educationLevel, stream, interests, careerIntent } = request.body; | |
| if (typeof age !== "number" || age <= 0) { | |
| throw new AppError("Age must be a valid number."); | |
| } | |
| if (typeof educationLevel !== "string" || !educationLevel.trim()) { | |
| throw new AppError("Education level is required."); | |
| } | |
| if (typeof stream !== "string" || !stream.trim()) { | |
| throw new AppError("Stream is required."); | |
| } | |
| if (!Array.isArray(interests) || !interests.length) { | |
| throw new AppError("At least one interest is required."); | |
| } | |
| if (!["confused", "exploring", "switching"].includes(careerIntent)) { | |
| throw new AppError("Career intent is invalid."); | |
| } | |
| const data = profileService.saveProfile(request.authUserId, { | |
| age, | |
| educationLevel, | |
| stream, | |
| interests, | |
| careerIntent, | |
| }); | |
| response.json({ success: true, data }); | |
| } catch (error) { | |
| next(error); | |
| } | |
| }, | |
| }; | |