Skip to content

Commit 9e95148

Browse files
committed
resolve comments by @DashDeipayan in the PR
1 parent 07d57be commit 9e95148

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

constants/progresses.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ const TYPE_MAP = {
1818
task: "taskId",
1919
};
2020

21-
module.exports = { RESPONSE_MESSAGES, MILLISECONDS_IN_DAY, INTERNAL_SERVER_ERROR_MESSAGE, TYPE_MAP };
21+
const VALID_PROGRESS_TYPES = ["task", "user"];
22+
23+
module.exports = {
24+
RESPONSE_MESSAGES,
25+
MILLISECONDS_IN_DAY,
26+
INTERNAL_SERVER_ERROR_MESSAGE,
27+
TYPE_MAP,
28+
VALID_PROGRESS_TYPES,
29+
};

middlewares/validators/progresses.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
const joi = require("joi");
2+
const { VALID_PROGRESS_TYPES } = require("../../constants/progresses");
23

34
const validateCreateProgressRecords = async (req, res, next) => {
45
const baseSchema = joi
56
.object()
67
.strict()
78
.keys({
8-
type: joi.string().trim().valid("user", "task").required().messages({
9-
"any.required": "Required field 'type' is missing.",
10-
"any.only": "Type field is restricted to either 'user' or 'task'.",
11-
}),
9+
type: joi
10+
.string()
11+
.trim()
12+
.valid(...VALID_PROGRESS_TYPES)
13+
.required()
14+
.messages({
15+
"any.required": "Required field 'type' is missing.",
16+
"any.only": "Type field is restricted to either 'user' or 'task'.",
17+
}),
1218
completed: joi.string().trim().required().messages({
1319
"any.required": "Required field 'completed' is missing.",
1420
"string.trim": "completed must not have leading or trailing whitespace",

0 commit comments

Comments
 (0)