From 7e2059e30e75f09e0f70a489993cc92e2abcc94f Mon Sep 17 00:00:00 2001 From: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com> Date: Tue, 13 Sep 2022 16:20:39 +0800 Subject: [PATCH] intrn(rule set): allow extending the ID rule validation --- server/rule_sets/make_multi-id-based_filter.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/rule_sets/make_multi-id-based_filter.ts b/server/rule_sets/make_multi-id-based_filter.ts index fab7f8da4..f1bd9871d 100644 --- a/server/rule_sets/make_multi-id-based_filter.ts +++ b/server/rule_sets/make_multi-id-based_filter.ts @@ -1,5 +1,5 @@ -import type { Pipe, FieldRules } from "!/types/validation" import type { BaseManagerClass } from "!/types/dependent" +import type { Pipe, Rules, FieldRules } from "!/types/validation" import string from "!/validators/base/string" import integer from "!/validators/base/integer" @@ -11,15 +11,20 @@ import stringArray from "!/validators/hybrid/string_array" export default function( ClassName: BaseManagerClass, { + postIDRules = { "pipes": [] }, initialPipes = [ nullable ], multipleIDKey = "IDs", mustCast = true }: Partial<{ + postIDRules: Rules, initialPipes: Pipe[], multipleIDKey: string, mustCast: boolean }> = {} ): FieldRules { + const postIDConstraints = postIDRules.constraints || {} + const postIDPipes = postIDRules.pipes + return { [multipleIDKey]: { "constraints": { @@ -29,9 +34,10 @@ export default function( "manager": { "className": ClassName, "columnName": "id" - } + }, + ...postIDConstraints }, - "pipes": [ string, integer, exists ] + "pipes": [ string, integer, exists, ...postIDPipes ] }, "length": { // TODO: Find the best length