Skip to content

Commit 15b64db

Browse files
committed
[added]
1 parent 0b2046e commit 15b64db

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

controller/module.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
deleteModuleById,
66
} from "#services/module";
77
import { logger } from "#util";
8+
import { isEntityIdValid } from "#middleware/entityIdValidation";
9+
import Topic from "#models/topic";
810

911
async function showModule(req, res) {
1012
try {
@@ -21,15 +23,22 @@ async function showModule(req, res) {
2123

2224
async function addModule(req, res) {
2325
const { no, name, contents, hrsPerModule, cognitiveLevels } = req.body;
26+
const isTopicValid = await isEntityIdValid(Topic, Topic);
2427
try {
25-
const newModule = await addNewModule(
26-
no,
27-
name,
28-
contents,
29-
hrsPerModule,
30-
cognitiveLevels,
31-
);
32-
res.json({ res: `added module ${newModule.name}` });
28+
if (isTopicValid) {
29+
const newModule = await addNewModule(
30+
no,
31+
name,
32+
contents,
33+
hrsPerModule,
34+
cognitiveLevels,
35+
);
36+
res.json({ res: `added module ${newModule.name}` });
37+
res.json({ res: `added module ${newModule.id}` });
38+
} else {
39+
res.status(400).json({ err: "Invalid name" });
40+
res.status(400).json({ err: "Invalid id" });
41+
}
3342
} catch (error) {
3443
logger.error("Error while inserting", error);
3544
res.status(500);

0 commit comments

Comments
 (0)