Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
7a8f982c
Commit
7a8f982c
authored
Apr 17, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prefix to restful
parent
3428f578
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
src/decorators/restful.ts
src/decorators/restful.ts
+25
-5
No files found.
src/decorators/restful.ts
View file @
7a8f982c
...
...
@@ -37,6 +37,7 @@ import { RenameClass } from '../utility/rename-class';
export
interface
RestfulFactoryOptions
<
T
>
{
fieldsToOmit
?:
(
keyof
T
)[];
prefix
?:
string
;
}
export
class
RestfulFactory
<
T
>
{
...
...
@@ -93,9 +94,28 @@ export class RestfulFactory<T> {
private
options
:
RestfulFactoryOptions
<
T
>
=
{},
)
{}
private
usePrefix
(
methodDec
:
(
path
?:
string
)
=>
MethodDecorator
,
path
?:
string
,
)
{
if
(
path
)
{
if
(
this
.
options
.
prefix
)
{
return
methodDec
(
`
${
this
.
options
.
prefix
}
/
${
path
}
`
);
}
else
{
return
methodDec
(
path
);
}
}
else
{
if
(
this
.
options
.
prefix
)
{
return
methodDec
(
this
.
options
.
prefix
);
}
else
{
return
methodDec
();
}
}
}
create
(
extras
:
Partial
<
OperationObject
>
=
{}):
MethodDecorator
{
return
MergeMethodDecorators
([
Post
(
),
this
.
usePrefix
(
Post
),
HttpCode
(
200
),
ApiOperation
({
summary
:
`Create a new
${
this
.
entityClass
.
name
}
`
,
...
...
@@ -116,7 +136,7 @@ export class RestfulFactory<T> {
findOne
(
extras
:
Partial
<
OperationObject
>
=
{}):
MethodDecorator
{
return
MergeMethodDecorators
([
Get
(
'
:id
'
),
this
.
usePrefix
(
Get
,
'
:id
'
),
ApiOperation
({
summary
:
`Find a
${
this
.
entityClass
.
name
}
by id`
,
...
extras
,
...
...
@@ -140,7 +160,7 @@ export class RestfulFactory<T> {
findAll
(
extras
:
Partial
<
OperationObject
>
=
{}):
MethodDecorator
{
return
MergeMethodDecorators
([
Get
(
),
this
.
usePrefix
(
Get
),
ApiOperation
({
summary
:
`Find all
${
this
.
entityClass
.
name
}
`
,
...
extras
}),
ApiOkResponse
({
type
:
this
.
entityArrayReturnMessageDto
}),
]);
...
...
@@ -152,7 +172,7 @@ export class RestfulFactory<T> {
update
(
extras
:
Partial
<
OperationObject
>
=
{}):
MethodDecorator
{
return
MergeMethodDecorators
([
Patch
(
'
:id
'
),
this
.
usePrefix
(
Patch
,
'
:id
'
),
HttpCode
(
200
),
ApiOperation
({
summary
:
`Update a
${
this
.
entityClass
.
name
}
by id`
,
...
...
@@ -182,7 +202,7 @@ export class RestfulFactory<T> {
delete
(
extras
:
Partial
<
OperationObject
>
=
{}):
MethodDecorator
{
return
MergeMethodDecorators
([
Delete
(
'
:id
'
),
this
.
usePrefix
(
Delete
,
'
:id
'
),
HttpCode
(
200
),
ApiOperation
({
summary
:
`Delete a
${
this
.
entityClass
.
name
}
by id`
,
...
...
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