Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(rule set): allow extending the ID rule validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 13, 2022
1 parent cadddc2 commit 7e2059e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/rule_sets/make_multi-id-based_filter.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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": {
Expand All @@ -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
Expand Down

0 comments on commit 7e2059e

Please sign in to comment.