Skip to content

Commit af58e7e

Browse files
committed
Use enum for oprations
1 parent 68fcbb3 commit af58e7e

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/common/components/results-table/tool-bar/filter/schema.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import { z } from "zod";
22

3+
export const operators = {
4+
GREATER_THAN: "gt",
5+
LESS_THAN: "lt",
6+
GREATER_THAN_EQUAL: "gte",
7+
LESS_THAN_EQUAL: "lte",
8+
EQUAL: "eq",
9+
NOT_EQUAL: "ne",
10+
};
11+
312
export const filedOptions = [
413
{ label: "Marks", value: "marks" },
514
{ label: "AIR", value: "air" },
615
{ label: "Application No.", value: "id" },
716
];
817

918
export const operatorOptions = [
10-
{ label: ">", value: "gt" },
11-
{ label: "<", value: "lt" },
12-
{ label: ">=", value: "gte" },
13-
{ label: "<=", value: "lte" },
14-
{ label: "=", value: "eq" },
15-
{ label: "!=", value: "ne" },
19+
{ label: ">", value: operators.GREATER_THAN },
20+
{ label: "<", value: operators.LESS_THAN },
21+
{ label: ">=", value: operators.GREATER_THAN_EQUAL },
22+
{ label: "<=", value: operators.LESS_THAN_EQUAL },
23+
{ label: "=", value: operators.EQUAL },
24+
{ label: "!=", value: operators.NOT_EQUAL },
1625
];
1726

1827
export const defaultState = {

src/common/utils/worker/results.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expose } from "comlink";
22
import { get24Results } from "@/api/index";
33
import { DATA_PER_PAGE } from "@/utils/constants";
4+
import { operators, type FiltersSchema } from "@/components/results-table/tool-bar/filter/schema";
45
import type { Result } from "@/utils/types";
5-
import type { FiltersSchema } from "@/components/results-table/tool-bar/filter/schema";
66

77
type GetResultsParams = {
88
pageNo: number;
@@ -42,17 +42,17 @@ export class Results {
4242
if (!fieldValue) return false;
4343

4444
switch (operator) {
45-
case "gt":
45+
case operators.GREATER_THAN:
4646
return fieldValue > value;
47-
case "lt":
47+
case operators.LESS_THAN:
4848
return fieldValue < value;
49-
case "gte":
49+
case operators.GREATER_THAN_EQUAL:
5050
return fieldValue >= value;
51-
case "lte":
51+
case operators.LESS_THAN_EQUAL:
5252
return fieldValue <= value;
53-
case "eq":
53+
case operators.EQUAL:
5454
return fieldValue === value;
55-
case "ne":
55+
case operators.NOT_EQUAL:
5656
return fieldValue !== value;
5757
default:
5858
return false;

0 commit comments

Comments
 (0)