Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

336
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda