I'm trying to build System to see all seller weekly income. than nextweek paymentDate need to update but I fail

20 views Asked by At

I'm trying to build an e-commerce app. I got a problem. I want every seller's weekly income. Every week payment data need to update automatically so I used agenda Js. But when my server is restarting I can't update data automatically. This is my income route code.

const joinUpdate = new Date(seller.startAt);
  const paymentDateAt = new Date(seller.paymentDateAt);
  let nowDate = new Date(seller.startAt);
  let Month = new Date(seller.paymentDateAt);


  agenda.define("Income" , async job => {
    nowDate = new Date(joinUpdate.setMinutes(joinUpdate.getMinutes() + 2));
    Month = new Date(paymentDateAt.setMinutes(paymentDateAt.getMinutes() + 2));
    console.log([nowDate , "Testing"]);
    console.log([Month , "Testing"]);
    
    try {
      const updateuser = await Seller.findByIdAndUpdate(req.seller.id , {
        "startAt":nowDate,
        "paymentDateAt":Month
      });
    } catch (error) {      
    }  
  })
  
  agenda.every('1 minutes', "Income" ); /// Only for testing
  agenda.start();
0

There are 0 answers