All files / src/endpoints hideCategory.ts

8.33% Statements 1/12
0% Branches 0/2
0% Functions 0/1
8.33% Lines 1/12

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          2x                                    
import { Request, Response } from "express"
import pino from "pino"
 
import DynamicConfig, { AConfig } from "../modules/config/dynamic"
 
const logger = pino()
 
export async function hideCategory(req: Request<{ categoryName: string }>, res: Response) {
  const { categoryName } = req.params
  logger.info("=================================== Hiding toggle category ===================================")
  const hiddenCategories = await DynamicConfig.lrange(AConfig.HiddenCategories, 0, -1)
  const isCategoryHidden = hiddenCategories.includes(categoryName)
 
  if (isCategoryHidden) {
    logger.info("Category with name %s is already hidden, removing from hidden categories", categoryName)
    await DynamicConfig.lrem(AConfig.HiddenCategories, 0, categoryName)
    return res.status(202).send({})
  } else {
    logger.info("Category with name %s is not hidden, adding to hidden categories", categoryName)
    await DynamicConfig.rpush(AConfig.HiddenCategories, categoryName)
    return res.status(201).send({})
  }
}