diff --git a/src/api/middleware/validators/offer.js b/src/api/middleware/validators/offer.js index 1f0b8141..38371c5e 100644 --- a/src/api/middleware/validators/offer.js +++ b/src/api/middleware/validators/offer.js @@ -18,6 +18,13 @@ import { import * as companyMiddleware from "../company.js"; import config from "../../../config/env.js"; import { validApplyURL } from "../../../models/modelUtils.js"; +const jobMinDurationMustNotExistInFreelance = (jobMinDuration, { req }) => { + if (req.body.jobType !== "FREELANCE") return true; + if (jobMinDuration !== null && jobMinDuration !== undefined) { + throw new Error(ValidationReasons.FREELANCE_OFFER_CANT_HAVE_MIN_DURATION); + } + return true; +}; const jobMaxDurationGreaterOrEqualThanJobMinDuration = (jobMaxDuration, { req }) => { @@ -82,6 +89,7 @@ export const create = useExpressValidators([ body("jobMinDuration", ValidationReasons.DEFAULT) + .custom(jobMinDurationMustNotExistInFreelance) .if((value, { req }) => req.body.jobType !== "FREELANCE") .exists().withMessage(ValidationReasons.REQUIRED).bail() .isInt().withMessage(ValidationReasons.INT), diff --git a/src/api/middleware/validators/validationReasons.js b/src/api/middleware/validators/validationReasons.js index 7a38a793..fcd35d97 100644 --- a/src/api/middleware/validators/validationReasons.js +++ b/src/api/middleware/validators/validationReasons.js @@ -50,6 +50,7 @@ const ValidationReasons = Object.freeze({ OFFER_HIDDEN: "offer-is-hidden", FILE_TOO_LARGE: (max) => `file-cant-be-larger-than-${max}MB`, MUST_BE_GREATER_THAN_OR_EQUAL_TO: (field) => `must-be-greater-than-or-equal-to:${field}`, + FREELANCE_OFFER_CANT_HAVE_MIN_DURATION: "freelance-offer-cant-have-min-duration", }); export default ValidationReasons;