Skip to content

Commit

Permalink
now freelance jobs cant have min duration
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-carlos-sousa committed Apr 13, 2024
1 parent 0e62eb4 commit 09eb81e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/models/Offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const OfferSchema = new Schema({

jobMinDuration: {
type: Number,
required: validateMinDuration,
required: isMinDurationRequired,
validate: [
validateJobMinDuration,
"`jobMinDuration` is not valid for freelance job",
],
},

jobMaxDuration: {
Expand Down Expand Up @@ -138,11 +142,20 @@ export function validatePublishEndDateLimit(publishDate, publishEndDate) {

// jobMaxDuration must be larger than jobMinDuration
function validateJobMaxDuration(value) {
if (this.jobType === "FREELANCE" && this.jobMinDuration === null) return true;
if (this.jobType === "FREELANCE") return true;
return value >= this.jobMinDuration;
}

function validateMinDuration() {
function validateJobMinDuration() {
if (this.jobType === "FREELANCE") {
if (this.jobMinDuration === null) return true;
return false;
}
if (this.jobMinDuration === null) return false;
return true;
}

function isMinDurationRequired() {
if (this.jobType === "FREELANCE") return false;
return true;
}
Expand Down

0 comments on commit 09eb81e

Please sign in to comment.