All files / src/endpoints setNotifier.ts

10% Statements 1/10
0% Branches 0/2
0% Functions 0/2
10% Lines 1/10

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 { Request, Response } from "express"
import pino from "pino"
 
import DynamicConfig, { VConfig } from "../modules/config/dynamic"
import { Notifiers } from "../modules/notifiers/types"
 
const logger = pino()
 
function isNotifier(value: string): value is Notifiers {
  return Object.values(Notifiers).includes(value as Notifiers)
}
 
export async function setNotifier(req: Request<{ notifier: Notifiers }>, res: Response) {
  const { notifier } = req.params
  logger.info("=================================== Setting Notifier ===================================")
 
  if (!isNotifier(notifier)) {
    logger.error("Invalid notifier %s", notifier)
    return res.status(400).send({ message: "Invalid notifier" })
  }
 
  logger.info("Setting notifier %s", notifier)
  await DynamicConfig.set(VConfig.Notifier, notifier)
  return res.status(201).send({ notifier })
}