Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/src/components/form/Form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let interpolatedResult = "";
let error = "";

/** Handles form submission by fetching calculation results from the API and updating the displayed output. */
async function onSubmit(event: Event) {
event.preventDefault();

Expand Down
1 change: 1 addition & 0 deletions web/src/pages/api/calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getResults } from "../../utils/inactivation";
import { parseQueryParams } from "../../utils/parseQueryParams";
import { validate } from "../../utils/validate";

/** Handles GET requests to the calc API endpoint by parsing query parameters, validating them, and returning the calculated inactivation results as JSON. */
export async function get({ params, request }) {
const queryParams = parseQueryParams(request.url);
const [validatedParams, error] = validate(queryParams);
Expand Down
7 changes: 7 additions & 0 deletions web/src/utils/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const methodologies = ["round", "interpolate", "formula"] as const;
export type Methodology = (typeof methodologies)[number];

/** Returns true if the given value is a valid methodology string. */
function isValidMethodology(methodology: any) {
if (typeof methodology !== "string") return false;
return methodologies.includes(methodology as Methodology);
Expand All @@ -14,6 +15,7 @@ const disinfectants = [
] as const;
export type Disinfectant = (typeof disinfectants)[number];

/** Returns true if the given value is a valid disinfectant string. */
function isValidDisinfectant(disinfectant: any) {
if (typeof disinfectant !== "string") return false;
return disinfectants.includes(disinfectant as Disinfectant);
Expand All @@ -22,21 +24,25 @@ function isValidDisinfectant(disinfectant: any) {
const pathogens = ["giardia", "virus"] as const;
export type Pathogen = (typeof pathogens)[number];

/** Returns true if the given value is a valid pathogen string. */
function isValidPathogen(pathogen: any) {
if (typeof pathogen !== "string") return false;
return pathogens.includes(pathogen as Pathogen);
}

/** Returns true if the given value is a valid temperature number (greater than 0 and up to 25°C inclusive). */
function isValidTemperature(temperature: any) {
if (typeof temperature !== "number") return false;
return 0 < temperature && temperature <= 25;
}

/** Returns true if the given value is a valid pH number (between 6 and 9 inclusive). */
function isValidPh(ph: any) {
if (typeof ph !== "number") return false;
return 6 <= ph && ph <= 9;
}

/** Returns true if the given value is a valid concentration number (greater than 0 and up to 3 mg/L inclusive). */
function isValidConcentration(concentration: any) {
if (typeof concentration !== "number") return false;
return 0 < concentration && concentration <= 3;
Expand All @@ -45,6 +51,7 @@ function isValidConcentration(concentration: any) {
// TODO should these be strings?
const inactivationLogs = [2, 3, 4];
const giardiaInactivationLogs = [0.5, 1, 1.5, 2, 2.5, 3];
/** Returns true if the given value is a valid inactivation log number for the given pathogen type. */
function isValidInactivationLog(inactivationLog: any, isGiardia?: boolean) {
if (typeof inactivationLog !== "number") return false;
return (isGiardia ? giardiaInactivationLogs : inactivationLogs).includes(
Expand Down
Loading