Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
feat: add student with no embedding middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-seyam committed May 7, 2021
1 parent 16ae1d9 commit 885d155
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions services/Routes/User/Student/StudentWithNoEmbedding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import StudentLogic from "@controller/BusinessLogic/User/Student/students-logic";
import StudentLogicImpl from "@controller/BusinessLogic/User/Student/students-logic-impl";
import Student from "@models/Users/Student";
import UserInputError from "@services/utils/UserInputError";
import express from "express";
import { getRepository } from "typeorm";
/**
* Embedding check middleware
* @param req
* @param res
* @param next
*/
export default async function studentWithNoEmbedding(
req: express.Request,
res: express.Response,
next: express.NextFunction
) {
const studentLogic: StudentLogic = new StudentLogicImpl();
try {
const embedding = await studentLogic.getEmbedding(
req.params["studentId"]
);
if (!embedding) {
res.status(403).send({
success: false,
message: "student doesn't have embedding",
});
return;
}
} catch (e) {
if (e instanceof UserInputError) {
res.status(400).send({ success: false, message: e.message });
} else {
throw e;
}
}
next();
}
3 changes: 2 additions & 1 deletion services/Routes/User/Student/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import DepartmentsLogicImpl from "@controller/BusinessLogic/Department/departmen
import UserInputError from "@services/utils/UserInputError";
import multer from "multer";
import { sendInitialVideo } from "@controller/sending/sendFiles";
import studentWithNoEmbedding from "./StudentWithNoEmbedding";

const router = Router();
router.use(BlockedJWTMiddleware);
Expand Down Expand Up @@ -169,7 +170,7 @@ router.get("/:studentId/lectures", async (req, res) => {
});
});

router.post("/:studentId/exams", async (req, res) => {
router.post("/:studentId/exams", studentWithNoEmbedding, async (req, res) => {
simpleFinalMWDecorator(
res,
async () => {
Expand Down

0 comments on commit 885d155

Please sign in to comment.