dashpresshq/dashpress

View on GitHub
src/backend/lib/request/validations/implementations/request-query.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { progammingError } from "@/backend/lib/errors";

import type { ValidationImplType } from "./types";

export const requestQueryValidationImpl: ValidationImplType<string> = async (
  req,
  requestOption: unknown
) => {
  progammingError(
    "Please provide the field to pull off the request query",
    !requestOption
  );

  progammingError(
    "Invalid request query field",
    typeof requestOption !== "string"
  );

  const value = req.query[requestOption as string];

  return value as string;
};