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

Commit

Permalink
intrn(semester): improve the validation of creating a semester
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Nov 26, 2022
1 parent 11c2788 commit 1b156be
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions routes/api/semester/create.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import string from "!/validators/base/string"
import required from "!/validators/base/required"
import oneOf from "!/validators/comparison/one-of"
import length from "!/validators/comparison/length"
import isLessThan from "!/validators/comparison/is_less_than"
import makeResourceDocumentRules from "!/rule_sets/make_resource_document"

export default class extends JSONController {
Expand All @@ -28,14 +29,19 @@ export default class extends JSONController {
}

makeBodyRuleGenerator(unusedAuthenticatedRequest: AuthenticatedRequest): FieldRules {
const attributes = {
const attributes: FieldRules = {
"endAt": {
"friendlyName": "end at",
"pipes": [ required, string, date ]
},
"name": {
"constraints": {
"length": {
"maximum": 255,
"minimum": 10
}
},
"friendlyName": "semester name",
"pipes": [ required, string, length ]
},
"semesterOrder": {
Expand All @@ -44,13 +50,17 @@ export default class extends JSONController {
"values": [ ...OrderValues ]
}
},
"friendlyName": "order",
"pipes": [ required, string, oneOf ]
},
"startAt": {
"pipes": [ required, string, date ]
},
"endAt": {
"pipes": [ required, string, date ]
"constraints": {
"isLessThan": {
"pointer": "data.attributes.endAt"
}
},
"friendlyName": "start at",
"pipes": [ required, string, date, isLessThan ]
}
}

Expand Down

0 comments on commit 1b156be

Please sign in to comment.