0

basically what the title says, I'm having trouble with returning the id that mongo database sets into an object because the same has already passed through a bull queue so the "res" object is not available to use.

What i want is basically, when you add an object to the database to have the id returned to Postman.

Here is the process:

Router

router.post("/sales/transactions", (req, res) => {
  salesControllerInstance.addRequestToQueue(req.body, res);
});

Controller

async addRequestToQueue(req, res) {
    const request = await this.bullServiceInstance.addToQueue(req);

    res.send(request);
    return request;
  } 

Bullservice: In the transactionQueue.process i get the _id in the result from the createTransaction func, but how do i get that result to the client is my issue.

module.exports = class BullService {
  constructor() {
    this.transactionQueue = new Queue("transaction-Queue");

    this.transactionQueue.process(async (saleCheck, done) => {
      const result = await this.createTransaction(saleCheck.data);
      //console.log(result);
      done(); //done(null, { transactionId: result });
    });
  }
...

Thanks!

Svar
  • 17
  • 3

0 Answers0