All files / src/endpoints settingBudgetForTransaction.ts

0% Statements 0/8
100% Branches 0/0
0% Functions 0/1
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
import { QueueEvents } from "bullmq"
import { NextFunction, Request, Response } from "express"
import pino from "pino"
 
import { env } from "../config"
import { getQueue } from "../queues"
import { SetBudgetForTransactionJob } from "../queues/jobs/setBudgetForTransaction"
import { addEndpointJobToQueue } from "../queues/utils"
 
const logger = pino()
 
export async function settingBudgetForTransaction(
  req: Request<{ transactionId: string; budget_id: string }>,
  _res: Response,
  next: NextFunction,
) {
  logger.info("=================================== Setting budget for transaction ===================================")
  const queue = await getQueue()
  const queueEvents = new QueueEvents(queue.name, { connection: env.redisConnection })
  const { transactionId, budget_id } = req.params
 
  const job = await addEndpointJobToQueue(new SetBudgetForTransactionJob(), transactionId, { budget_id })
  await job.waitUntilFinished(queueEvents)
  next()
}