diff --git a/src/controllers/skills.controller.ts b/src/controllers/skills.controller.ts index a8cd3be..fe897a5 100644 --- a/src/controllers/skills.controller.ts +++ b/src/controllers/skills.controller.ts @@ -2,7 +2,7 @@ import { SkillsModel, type SkillsType } from "../models/skills.model"; import { HttpError, HttpStatus, checkMongooseErrors } from "../utils/errors"; import { checkDuplicateItemName } from "../utils/checkDuplicates"; -export const createSkills = async (skillsFields: SkillsType) => { +export const createSkill = async (skillsFields: SkillsType) => { try { if(await checkDuplicateItemName(skillsFields.itemName)){ throw new HttpError( @@ -28,3 +28,23 @@ export const createSkills = async (skillsFields: SkillsType) => { ); } }; + +export const getAllSkills = async (user: string) => { + try { + const skills = await SkillsModel.find({ user: user }); + return skills; + } catch (err: unknown) { + //rethrow any errors as HttpErrors + if (err instanceof HttpError) { + throw err; + } + //checks if mongoose threw and will rethrow with appropriate status code and message + checkMongooseErrors(err); + + throw new HttpError( + HttpStatus.INTERNAL_SERVER_ERROR, + "Skills retrieval failed", + { cause: err }, + ); + } +} \ No newline at end of file diff --git a/src/routers/skills.router.ts b/src/routers/skills.router.ts index 5c0edf2..04aa90e 100644 --- a/src/routers/skills.router.ts +++ b/src/routers/skills.router.ts @@ -1,5 +1,5 @@ import { Router, type Request, type Response } from "express"; -import { createSkills } from "../controllers/skills.controller"; +import { createSkill } from "../controllers/skills.controller"; import { HttpError, HttpStatus } from "../utils/errors"; import { type SkillsType } from "../models/skills.model"; @@ -10,7 +10,7 @@ skillsRouter.post( "/", async (req: Request, res: Response) => { try { - const skills = await createSkills(req.body); + const skills = await createSkill(req.body); res.status(HttpStatus.OK).json(skills); } catch (err: unknown) { if (err instanceof HttpError) {