All files / src/endpoints settingBudgetForTransaction.ts

12.5% Statements 1/8
100% Branches 0/0
0% Functions 0/1
12.5% Lines 1/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                  2x                                
import { QueueEvents } from "bullmq"
import { NextFunction, Request, Response } from "express"
import pino from "pino"
 
import { getQueue } from "../queues"
import { SetBudgetForTransactionJob } from "../queues/jobs/setBudgetForTransaction"
import { addEndpointJobToQueue } from "../queues/utils"
import { redis as connection } from "../redis"
 
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 })
  const { transactionId, budget_id } = req.params
 
  const job = await addEndpointJobToQueue(new SetBudgetForTransactionJob(), transactionId, { budget_id })
  await job.waitUntilFinished(queueEvents)
  next()
}