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

335
Views
ValidationError: validTill: Cast to Number failed for value \"NaN\" at path \"validTill\"

I can't seem to get my POST api to work when it was working normally like 1 week ago, I think I forgot how to put the date but here is the error: ValidationError: validTill: Cast to Number failed for value \"NaN\" at path \"validTill\" Here is my json I am trying to send: {"plrID": "1", "key": "abc", "validTill": "1633872004841", "reason": "test"} is there something I am doing wrong here? I have tried doing it with a date but it didn't work. Here is the code for it: ```const mongoose = require('mongoose') module.exports = async function (req, res) { const receivedData = {...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}`
    })
}

}``` Thanks! Ben

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

0

I did the incorrect params, I ended up fixing it myself.

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!