Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

689
Views
sequelize - how to set validate rule for Date field

I have a DATE field called completedAt, which should only accept the value on or after the current datetime.

I think I have to add a validate rule on completedAt, but I don't know how to add the condition

const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const homework = sequelizeClient.define('homework', {
    ...,
    completedAt: {
      type: DataTypes.DATE,
      validate: {//What should I do here}
    },
  }, 
  });

  homework.associate = function (models) {
  };

  return homework;
};

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Create custom validator of seqlize.

completedAt: {
    type: DataTypes.DATE,
    validate: {
      customValidator(value) {
        if (new Date(value) < new Date()) {
          throw new Error("invalid date");
        }
      },
    },
  },
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!