Skip to content

Commit

Permalink
Merge pull request #7 from SprintCV-S24/jg-duplicate-check-route
Browse files Browse the repository at this point in the history
Duplicate name checking route
  • Loading branch information
jackgarritano authored Apr 13, 2024
2 parents 4fc0755 + 8ee244a commit 36b6ca5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/routers/duplicate.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Router, type Request, type Response } from "express";
import { checkDuplicateItemName } from "../utils/checkDuplicates";
import { HttpError, HttpStatus } from "../utils/errors";

export const duplicateRouter = Router();

//Get if there is a duplicate
//Include excludedItemId query param to exclude an item
duplicateRouter.get(
"/:itemName",
async (
req: Request<{ itemName: string }, any, any, { excludedItemId?: string }>,
res: Response,
) => {
try {
const isDuplicate = await checkDuplicateItemName(
req.body.user,
req.params.itemName,
req.query.excludedItemId || null,
);
res.status(HttpStatus.OK).json({ isDuplicate });
} catch (err: unknown) {
if (err instanceof HttpError) {
res.status(err.errorCode).json({ error: err.message });
} else {
res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.json({ error: "An unknown error occurred" });
}
}
},
);
2 changes: 2 additions & 0 deletions src/routers/root.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { headingRouter } from "./heading.router";
import { projectRouter } from "./project.router";
import { resumeRouter } from "./resume.router";
import { sectionHeadingRouter } from "./sectionHeading.router";
import { duplicateRouter } from "./duplicate.router";

export const router = Router();

Expand All @@ -18,3 +19,4 @@ router.use("/headings", headingRouter);
router.use("/projects", projectRouter);
router.use("/resumes", resumeRouter);
router.use("/sectionHeadings", sectionHeadingRouter);
router.use("/sectionHeadings", duplicateRouter);

0 comments on commit 36b6ca5

Please sign in to comment.