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

230
Views
Validate both JS Date and Firestore Date with Joi

I'm currently discovering Joi library and - at this time - it's a great experience.
However, I'm facing a tiny problem I can't resolve. Help or advice needed!

Consider the following schema (a bit):

const workSchema = Joi.object({ timeline_created: Joi.date().allow(null).required()) }

It works perfectly fine when I submit a JS date (or null value).
However, I'm using Firestore which convert JS Date to this kind of object:

timeline_created: Timestamp { _seconds: 1637258607, _nanoseconds: 349000000 }

Thus, I can't validate my schema (it's not a date Joi knows).
Then, my question: how to write my schema (I want it to be strict/precise) but validating at the same time a JS Date and a Firestore Date.

Thanks

EDIT: I made some progress with:

timeline_created: Joi.object().keys({_seconds: Joi.number(),_nanoseconds: Joi.number()}).required()

It validates my Firestore object.
However, how could I also validate if timeline_created is null or a JS Date? Thx.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is working:

Joi.alternatives([Joi.object().keys({ _seconds: Joi.number(), _nanoseconds: Joi.number() }), Joi.date(), null]).required()
about 4 years ago · Juan Pablo Isaza 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!