Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
5a2f2dc4
Commit
5a2f2dc4
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
customvalidation in one file, added rolevalidator
parent
3eafdd7f
No related branches found
Branches containing commit
No related tags found
4 merge requests
!59
Development to master
,
!31
Development
,
!25
Dto service
,
!24
Faction task edit
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/shared/array-validation.ts
+0
-17
0 additions, 17 deletions
src/shared/array-validation.ts
src/shared/custom-validation.ts
+13
-0
13 additions, 0 deletions
src/shared/custom-validation.ts
src/task/task.dto.ts
+2
-2
2 additions, 2 deletions
src/task/task.dto.ts
with
15 additions
and
19 deletions
src/shared/array-validation.ts
deleted
100644 → 0
+
0
−
17
View file @
3eafdd7f
import
{
ValidatorConstraint
,
ValidatorConstraintInterface
,
ValidationArguments
}
from
"
class-validator
"
;
import
{
Logger
}
from
"
@nestjs/common
"
;
// validates array length
@
ValidatorConstraint
({
name
:
"
arrayLength
"
,
async
:
true
})
export
class
ArrayLength
implements
ValidatorConstraintInterface
{
validate
(
array
:
string
[],
args
:
ValidationArguments
)
{
Logger
.
log
(
array
.
length
)
return
array
.
length
>
args
.
constraints
[
0
]
&&
array
.
length
<
args
.
constraints
[
1
];
// for async validations you must return a Promise<boolean> here
}
defaultMessage
(
args
:
ValidationArguments
)
{
// here you can provide default error message if validation failed
return
"
Please input all passwords
"
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/shared/
uuid.
validation.ts
→
src/shared/
custom-
validation.ts
+
13
−
0
View file @
5a2f2dc4
...
...
@@ -17,3 +17,16 @@ export class Uuid implements ValidatorConstraintInterface {
return
'
Not valid uuid
'
;
}
}
// checks if role is valid
@
ValidatorConstraint
({
name
:
'
roleValidation
'
,
async
:
true
})
export
class
RoleValidation
implements
ValidatorConstraintInterface
{
validate
(
role
:
string
,
args
:
ValidationArguments
)
{
const
validRoles
=
[
'
admin
'
,
'
soldier
'
,
'
factionleader
'
];
return
validRoles
.
includes
(
role
);
}
defaultMessage
(
args
:
ValidationArguments
)
{
return
'
Not valid uuid
'
;
}
}
This diff is collapsed.
Click to expand it.
src/task/task.dto.ts
+
2
−
2
View file @
5a2f2dc4
...
...
@@ -7,8 +7,8 @@ import {
Equals
,
}
from
'
class-validator
'
;
import
{
FactionEntity
}
from
'
../game/faction.entity
'
;
import
{
Uuid
}
from
'
../
shared/uuid.validation
'
;
import
{
GameEntity
}
from
'
src/game/game.entity
'
;
import
{
GameEntity
}
from
'
../
game/game.entity
'
;
import
{
Uuid
}
from
'
../shared/custom-validation
'
;
export
class
CreateTaskDTO
{
@
IsString
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment