Skip to content

Commit 700be2a

Browse files
added validator in middleware
1 parent 09eb81e commit 700be2a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/api/middleware/validators/offer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import {
1818
import * as companyMiddleware from "../company.js";
1919
import config from "../../../config/env.js";
2020
import { validApplyURL } from "../../../models/modelUtils.js";
21+
const jobMinDurationMustNotExistInFreelance = (jobMinDuration, { req }) => {
22+
if (req.body.jobType !== "FREELANCE") return true;
23+
if (jobMinDuration !== null && jobMinDuration !== undefined) {
24+
throw new Error(ValidationReasons.FREELANCE_OFFER_CANT_HAVE_MIN_DURATION);
25+
}
26+
return true;
27+
};
2128

2229
const jobMaxDurationGreaterOrEqualThanJobMinDuration = (jobMaxDuration, { req }) => {
2330

@@ -82,6 +89,7 @@ export const create = useExpressValidators([
8289

8390

8491
body("jobMinDuration", ValidationReasons.DEFAULT)
92+
.custom(jobMinDurationMustNotExistInFreelance)
8593
.if((value, { req }) => req.body.jobType !== "FREELANCE")
8694
.exists().withMessage(ValidationReasons.REQUIRED).bail()
8795
.isInt().withMessage(ValidationReasons.INT),

src/api/middleware/validators/validationReasons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const ValidationReasons = Object.freeze({
5050
OFFER_HIDDEN: "offer-is-hidden",
5151
FILE_TOO_LARGE: (max) => `file-cant-be-larger-than-${max}MB`,
5252
MUST_BE_GREATER_THAN_OR_EQUAL_TO: (field) => `must-be-greater-than-or-equal-to:${field}`,
53+
FREELANCE_OFFER_CANT_HAVE_MIN_DURATION: "freelance-offer-cant-have-min-duration",
5354
});
5455

5556
export default ValidationReasons;

0 commit comments

Comments
 (0)