Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PB138 - Film Database Group Project
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tomáš Havlíček
PB138 - Film Database Group Project
Commits
714e59df
There was an error fetching the commit references. Please try again later.
Commit
714e59df
authored
2 years ago
by
Martin Korec
Browse files
Options
Downloads
Patches
Plain Diff
fix: add create and update validation for directors
parent
96b5180d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/src/api/directors/directors.service.ts
+11
-4
11 additions, 4 deletions
backend/src/api/directors/directors.service.ts
backend/src/api/directors/dto/create-director.dto.ts
+19
-1
19 additions, 1 deletion
backend/src/api/directors/dto/create-director.dto.ts
with
30 additions
and
5 deletions
backend/src/api/directors/directors.service.ts
+
11
−
4
View file @
714e59df
...
...
@@ -2,14 +2,17 @@ import { Injectable } from '@nestjs/common';
import
{
CreateDirectorDto
}
from
'
./dto/create-director.dto
'
;
import
{
UpdateDirectorDto
}
from
'
./dto/update-director.dto
'
;
import
{
PrismaService
}
from
'
../../prisma.service
'
;
import
{
plainToClass
}
from
'
class-transformer
'
;
import
{
DirectorEntity
}
from
'
./entities/director.entity
'
;
@
Injectable
()
export
class
DirectorsService
{
constructor
(
private
prisma
:
PrismaService
)
{}
async
create
(
createDirectorDto
:
CreateDirectorDto
)
{
const
director
=
plainToClass
(
DirectorEntity
,
createDirectorDto
);
return
await
this
.
prisma
.
director
.
create
({
data
:
createD
irector
Dto
,
data
:
d
irector
,
});
}
...
...
@@ -26,12 +29,16 @@ export class DirectorsService {
}
async
update
(
id
:
string
,
updateDirectorDto
:
UpdateDirectorDto
)
{
const
updatedDirector
=
{
...
await
this
.
findOne
(
id
),
...
plainToClass
(
DirectorEntity
,
updateDirectorDto
),
};
return
await
this
.
prisma
.
director
.
update
({
where
:
{
id
,
},
data
:
{
...
updateDirector
Dto
,
...
update
d
Director
,
},
});
}
...
...
@@ -43,8 +50,8 @@ export class DirectorsService {
deletedAt
:
null
,
},
select
:
{
id
:
true
}
id
:
true
,
}
,
});
if
(
directorMovie
===
undefined
)
{
...
...
This diff is collapsed.
Click to expand it.
backend/src/api/directors/dto/create-director.dto.ts
+
19
−
1
View file @
714e59df
import
{
IsDate
,
IsNotEmpty
,
IsOptional
,
IsString
,
MaxDate
,
}
from
'
class-validator
'
;
export
class
CreateDirectorDto
{
@
IsNotEmpty
()
@
IsString
()
readonly
name
:
string
;
@
IsNotEmpty
()
@
IsString
()
readonly
surname
:
string
;
readonly
birthDate
?:
string
;
@
IsNotEmpty
()
@
IsDate
()
@
IsOptional
()
@
MaxDate
(
new
Date
())
readonly
birthDate
?:
Date
;
}
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