Skip to content

Commit

Permalink
implements part of skills
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgarritano committed Feb 28, 2024
1 parent 047593b commit 6db55ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion src/controllers/skills.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 },
);
}
}
4 changes: 2 additions & 2 deletions src/routers/skills.router.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -10,7 +10,7 @@ skillsRouter.post(
"/",
async (req: Request<any, any, SkillsType>, 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) {
Expand Down

0 comments on commit 6db55ac

Please sign in to comment.