generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/release-please
- Loading branch information
Showing
11 changed files
with
152 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
vehicles/src/common/constraint/query-param-list.constraint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
ValidationArguments, | ||
} from 'class-validator'; | ||
import { Nullable } from '../types/common'; | ||
|
||
@ValidatorConstraint({ name: 'QueryParamList', async: false }) | ||
export class QueryParamListConstraint implements ValidatorConstraintInterface { | ||
validate(field: Nullable<string>, args: ValidationArguments): boolean { | ||
return !this.validateQueryParamList(field, args)?.length; | ||
} | ||
|
||
validateQueryParamList( | ||
field: Nullable<string>, | ||
args: ValidationArguments, | ||
): string[] { | ||
const fieldList = field?.split(',') || []; | ||
const allowedFieldValues = Object.values( | ||
args.constraints?.at(0) as Record<string, unknown>, | ||
); | ||
|
||
return fieldList.flatMap((fieldValue) => { | ||
const errors: string[] = []; | ||
if (!allowedFieldValues.includes(fieldValue)) { | ||
errors.push( | ||
`${fieldValue} is an invalid value. Possible values are: ${Object.values(allowedFieldValues).join(', ')}.`, | ||
); | ||
} | ||
return errors; | ||
}); | ||
} | ||
|
||
defaultMessage(args: ValidationArguments): string { | ||
const applicationQueueStatus = ( | ||
args.object as { applicationQueueStatus?: Nullable<string> } | ||
).applicationQueueStatus; | ||
const invalidFields = this.validateQueryParamList( | ||
applicationQueueStatus, | ||
args, | ||
); | ||
return invalidFields.join(' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.