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

334
Views
ValidationError: validTill: Cast to Number falló para el valor \"NaN\" en la ruta \"validTill\"

Parece que no puedo hacer que mi API POST funcione cuando funcionaba normalmente como hace 1 semana, creo que olvidé cómo poner la fecha, pero aquí está el error: ValidationError: validTill: Cast to Number failed for value \"NaN\" at path \"validTill\" Aquí está mi json que intento enviar: {"plrID": "1", "key": "abc", "validTill": "1633872004841", "reason": "test"} ¿Hay algo que esté haciendo mal aquí? Intenté hacerlo con una cita, pero no funcionó. Aquí está el código: ```const mongoose = require('mongoose') module.exports = async function (req, res) { const receiveData = {...req.body}

 try { require('../models/Ban') const BanModel = mongoose.model('Ban') const pre = await BanModel.findOne({ plrID: receivedData.plrID}) if (pre) { var someDate = new Date(); var numberOfDaysToAdd = receivedData.validDays; someDate.setDate(someDate.getDate() + numberOfDaysToAdd); await BanModel.findByIdAndUpdate(pre._id, {$set: { validTill: someDate.getTime(), Valid: true }}) } else { var someDate = new Date(); var numberOfDaysToAdd = receivedData.validDays; someDate.setDate(someDate.getDate() + numberOfDaysToAdd); const newBanInstance = new BanModel({ plrID: receivedData.plrID, key: receivedData.key, validTill: someDate.getTime(), reason: receivedData.reason, gameID: 1, Cancelled: false, Valid: true }) const newSub = await newBanInstance.save() require('../models/BanCreator') const creatorModel = mongoose.model('BanCreator') await creatorModel.findOneAndUpdate({ gameID: 1 }, { $push: { BanIds: newSub._id } }) } var nowDate = new Date(); var addDays = receivedData.validDays; nowDate.setDate(nowDate.getDate() + addDays); res.json({ plrID: receivedData.plrID, validTill: nowDate.toDateString(), reason: receivedData.reason, valid: true, failResponse: "Faced No Errors" }) } catch (e) { res.json({ plrID: receivedData.plrID, validTill: null, reason: receivedData.reason, valid: false, failResponse: `oopsies an error happened: ${e}` }) }

}``` ¡Gracias! ben

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

0

Hice los parámetros incorrectos, terminé arreglándolo yo mismo.

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!