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
Show 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
*
*
src/controllers/auth.controller.ts
View file @
a9467abb
...
@@ -20,7 +20,7 @@ export class AuthController {
...
@@ -20,7 +20,7 @@ export class AuthController {
const
user
=
await
this
.
service
.
signIn
(
signInUserDto
);
const
user
=
await
this
.
service
.
signIn
(
signInUserDto
);
res
.
send
(
user
);
res
.
send
(
user
);
}
catch
(
e
)
{
}
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 {
...
@@ -40,7 +40,7 @@ export class AuthController {
res
.
send
(
user
);
res
.
send
(
user
);
}
catch
(
e
)
{
}
catch
(
e
)
{
if
((
e
as
{
code
:
string
}).
code
===
'ER_DUP_ENTRY'
)
{
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
{
}
else
{
res
.
status
(
500
).
send
({
error
:
{
message
:
'Oops something went wrong'
}
});
res
.
status
(
500
).
send
({
error
:
{
message
:
'Oops something went wrong'
}
});
}
}
...
...
src/dto/product.dto.ts
View file @
a9467abb
import
{
Expose
}
from
'class-transformer'
;
import
{
Expose
}
from
'class-transformer'
;
import
{
IsNotEmpty
,
IsNumberString
,
IsOptional
,
IsString
}
from
'class-validator'
;
import
{
IsNotEmpty
,
IsNumberString
,
IsOptional
,
IsString
}
from
'class-validator'
;
import
{
IsTitleTV
}
from
'@/validators/isTitleTV'
;
@
Expose
()
@
Expose
()
export
class
ProductDto
{
export
class
ProductDto
{
@
IsNotEmpty
({
message
:
'Продукт не может быть создан без названия!'
})
@
IsNotEmpty
({
message
:
'Продукт не может быть создан без названия!'
})
@
IsString
({
message
:
'Название должно быть строкой'
})
@
IsString
({
message
:
'Название должно быть строкой'
})
@
IsTitleTV
(
'title'
,
{
message
:
'The title is TV'
})
title
!
:
string
;
title
!
:
string
;
@
IsOptional
()
@
IsOptional
()
...
...
src/entities/product.entity.ts
View file @
a9467abb
...
@@ -12,10 +12,10 @@ export class Product {
...
@@ -12,10 +12,10 @@ export class Product {
@
Column
()
@
Column
()
price
!
:
number
;
price
!
:
number
;
@
Column
()
@
Column
(
{
nullable
:
true
}
)
image
?:
string
;
image
?:
string
;
@
Column
()
@
Column
(
{
nullable
:
true
}
)
description
!
:
string
;
description
!
:
string
;
@
ManyToOne
(()
=>
Category
)
@
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