Skip to content

Commit 95bbf34

Browse files
committed
Refactor validator middleware
1 parent 90ec3bf commit 95bbf34

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/middlewares/validatorMiddleware.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { Actions } from '../models/actions';
44
import { Rule, UniqueConstraint, CallbackConstraint } from '../models/rule';
55
import { ValidationError } from '../models/validation';
66

7-
const onlyUniqueValues = (data: string[]) => {
8-
return new Set(data).size === data.length;
7+
const onlyUniqueValues = (values: string[]) => {
8+
return new Set(values).size === values.length;
99
};
1010

11-
const findDuplicates = (data: string[]) => {
12-
return Array.from(new Set(data.filter((item, index) => data.indexOf(item) != index)));
11+
const getDuplicates = (values: string[]) => {
12+
return Array.from(new Set(values.filter((item, index) => values.indexOf(item) != index)));
1313
};
1414

1515
const validateColumn = <T>(key: keyof T, data: T[keyof T][], rules?: Rule[]): ValidationError<T>[] => {
@@ -19,7 +19,7 @@ const validateColumn = <T>(key: keyof T, data: T[keyof T][], rules?: Rule[]): Va
1919
const values = data.map((d) => new String(d).toString());
2020
rules.forEach((r) => {
2121
if ((r.constraint as UniqueConstraint).unique && !onlyUniqueValues(values)) {
22-
const duplicates = findDuplicates(values);
22+
const duplicates = getDuplicates(values);
2323
values.forEach((v, i) => {
2424
if (duplicates.indexOf(v) !== -1) {
2525
errors.push({ column: key, row: i, message: r.message });

0 commit comments

Comments
 (0)