Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulpybaev Ilyas
shop-api
Commits
a9467abb
Commit
a9467abb
authored
May 06, 2024
by
Kulpybaev Ilyas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson-92
parent
c8515eeb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
5 deletions
+31
-5
.gitignore
public/uploads/.gitignore
+2
-1
auth.controller.ts
src/controllers/auth.controller.ts
+2
-2
product.dto.ts
src/dto/product.dto.ts
+2
-0
product.entity.ts
src/entities/product.entity.ts
+2
-2
isTitleTV.ts
src/validators/isTitleTV.ts
+23
-0
No files found.
public/uploads/.gitignore
View file @
a9467abb
*
\ No newline at end of file
*
src/controllers/auth.controller.ts
View file @
a9467abb
...
...
@@ -20,7 +20,7 @@ export class AuthController {
const
user
=
await
this
.
service
.
signIn
(
signInUserDto
);
res
.
send
(
user
);
}
catch
(
e
)
{
res
.
s
end
((
e
as
Error
).
message
);
res
.
s
tatus
(
400
).
send
({
error
:
{
message
:
(
e
as
Error
).
message
}
}
);
}
};
...
...
@@ -40,7 +40,7 @@ export class AuthController {
res
.
send
(
user
);
}
catch
(
e
)
{
if
((
e
as
{
code
:
string
}).
code
===
'ER_DUP_ENTRY'
)
{
res
.
send
({
error
:
{
message
:
'User already exists'
}
});
res
.
s
tatus
(
400
).
s
end
({
error
:
{
message
:
'User already exists'
}
});
}
else
{
res
.
status
(
500
).
send
({
error
:
{
message
:
'Oops something went wrong'
}
});
}
...
...
src/dto/product.dto.ts
View file @
a9467abb
import
{
Expose
}
from
'class-transformer'
;
import
{
IsNotEmpty
,
IsNumberString
,
IsOptional
,
IsString
}
from
'class-validator'
;
import
{
IsTitleTV
}
from
'@/validators/isTitleTV'
;
@
Expose
()
export
class
ProductDto
{
@
IsNotEmpty
({
message
:
'Продукт не может быть создан без названия!'
})
@
IsString
({
message
:
'Название должно быть строкой'
})
@
IsTitleTV
(
'title'
,
{
message
:
'The title is TV'
})
title
!
:
string
;
@
IsOptional
()
...
...
src/entities/product.entity.ts
View file @
a9467abb
...
...
@@ -12,10 +12,10 @@ export class Product {
@
Column
()
price
!
:
number
;
@
Column
()
@
Column
(
{
nullable
:
true
}
)
image
?:
string
;
@
Column
()
@
Column
(
{
nullable
:
true
}
)
description
!
:
string
;
@
ManyToOne
(()
=>
Category
)
...
...
src/validators/isTitleTV.ts
0 → 100644
View file @
a9467abb
import
{
registerDecorator
,
ValidationOptions
,
ValidationArguments
}
from
'class-validator'
;
import
{
ProductDto
}
from
'@/dto/product.dto'
;
export
function
IsTitleTV
(
property
:
string
,
validationOptions
?:
ValidationOptions
)
{
return
function
(
object
:
NonNullable
<
unknown
>
,
propertyName
:
string
)
{
registerDecorator
({
name
:
'isTitleTv'
,
target
:
object
.
constructor
,
propertyName
:
propertyName
,
constraints
:
[
property
],
options
:
validationOptions
,
validator
:
{
validate
(
value
:
string
,
args
:
ValidationArguments
)
{
const
[
relatedPropertyName
]
=
args
.
constraints
;
console
.
log
(
args
.
object
);
console
.
log
(
value
);
const
relatedValue
=
(
args
.
object
as
ProductDto
)[
relatedPropertyName
as
keyof
ProductDto
];
return
relatedValue
!==
'TV'
;
// you can return a Promise<boolean> here as well, if you want to make async validation
},
},
});
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment