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

214
Visualizações
Execute a function once the timer runs zero

I have a database entry that has the following data:

{
   _id:"fdjshbjds564564sfsdf",
   shipmentCreationTime:"12:17 AM"
   shipmentExpiryTime:"12:32 AM"
}

What I want to do is create a timer from the front end (ReactJS) on the basis of creation and expiry time provided in the data set. And once the timer runs zero, I want to execute an API call back to the backend.

The function is as follows:

exports.expireShipmentOffer = async (req,res) => {

    const { shipmentOfferId } = req.body;

    try {
        const updatedOffer = await ShipmentOrder.findOneAndUpdate({_id: shipmentOfferId} , {$set:{status:'Expired'}} , {new: true})
       
        const newNotification = await Notification({accountId: updatedOffer.accountId ,  notificationHeader: ` Shipment Order Expired `  , notificationMessage:`Your Shipment Request ${shipmentOfferId} has been expired due to no response from the carrier` , timeAndDate : moment().format('LLL'), actionPath:`/shipmentOffer/${updatedOffer._id}`})
    
        await newNotification.save();
    
        res.json({
            status: 200,
            message: updatedOffer
        })
    } catch (error) {
        res.json({
            status: 500,
            message:error.message
        })
    }

}

What can I do to achieve this?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can achieve this in different ways , one of them is to register a callback and use setTimout() function based on your dataset , you then can execute the request inside this function

about 4 years ago · Juan Pablo Isaza Relatório

0

I did not understand very well.

Do you want to create a Countdown or Timer?

If if you want to create a Countdown, save the value in a state and call your API when it is zero.

But if you want to create a timer, I suggest you use Promise docs

const tiemr = () => {
    return new Promise(done => {
        setTimeout(() => {
            done(callYourAPI());
        }, 5000); // after 5s
    })
}
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