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
62d28c7f
Commit
62d28c7f
authored
Jan 20, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add query decorators
parent
a40a05d0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
5 deletions
+49
-5
src/bases/page-settings.ts
src/bases/page-settings.ts
+15
-0
src/bases/time-base.ts
src/bases/time-base.ts
+6
-1
src/decorators/index.ts
src/decorators/index.ts
+1
-0
src/decorators/query.ts
src/decorators/query.ts
+13
-0
src/utility/metadata.ts
src/utility/metadata.ts
+14
-4
No files found.
src/bases/page-settings.ts
View file @
62d28c7f
...
@@ -2,6 +2,7 @@ import { NotWritable } from '../decorators';
...
@@ -2,6 +2,7 @@ import { NotWritable } from '../decorators';
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
IsInt
,
IsPositive
}
from
'
class-validator
'
;
import
{
IsInt
,
IsPositive
}
from
'
class-validator
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
reflector
}
from
'
../utility/metadata
'
;
export
interface
PageSettingsWise
{
export
interface
PageSettingsWise
{
pageCount
:
number
;
pageCount
:
number
;
...
@@ -16,6 +17,13 @@ export interface QueryWise<T> {
...
@@ -16,6 +17,13 @@ export interface QueryWise<T> {
applyQuery
(
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
):
void
;
applyQuery
(
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
):
void
;
}
}
export
type
QueryCond
=
<
T
extends
PageSettingsDto
>
(
obj
:
T
,
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
,
key
:
keyof
T
&
string
,
)
=>
any
;
export
class
PageSettingsDto
export
class
PageSettingsDto
implements
PageSettingsWise
,
PageSettingsFactory
,
QueryWise
<
PageSettingsDto
>
implements
PageSettingsWise
,
PageSettingsFactory
,
QueryWise
<
PageSettingsDto
>
{
{
...
@@ -61,6 +69,13 @@ export class PageSettingsDto
...
@@ -61,6 +69,13 @@ export class PageSettingsDto
}
}
applyQuery
(
qb
:
SelectQueryBuilder
<
PageSettingsDto
>
,
entityName
:
string
)
{
applyQuery
(
qb
:
SelectQueryBuilder
<
PageSettingsDto
>
,
entityName
:
string
)
{
const
queryFields
=
reflector
.
getArray
(
'
queryConditionFields
'
,
this
);
for
(
const
field
of
queryFields
)
{
const
condition
=
reflector
.
get
(
'
queryCondition
'
,
this
,
field
);
if
(
condition
)
{
condition
(
this
,
qb
,
entityName
,
field
as
keyof
PageSettingsDto
);
}
}
qb
.
take
(
this
.
getRecordsPerPage
()).
skip
(
this
.
getStartingFrom
());
qb
.
take
(
this
.
getRecordsPerPage
()).
skip
(
this
.
getStartingFrom
());
}
}
}
}
src/bases/time-base.ts
View file @
62d28c7f
import
{
CreateDateColumn
,
DeleteDateColumn
,
UpdateDateColumn
}
from
'
typeorm
'
;
import
{
CreateDateColumn
,
DeleteDateColumn
,
SelectQueryBuilder
,
UpdateDateColumn
,
}
from
'
typeorm
'
;
import
{
NotColumn
}
from
'
../decorators
'
;
import
{
NotColumn
}
from
'
../decorators
'
;
import
{
PageSettingsDto
}
from
'
./page-settings
'
;
import
{
PageSettingsDto
}
from
'
./page-settings
'
;
...
...
src/decorators/index.ts
View file @
62d28c7f
...
@@ -3,3 +3,4 @@ export * from './merge';
...
@@ -3,3 +3,4 @@ export * from './merge';
export
*
from
'
./property
'
;
export
*
from
'
./property
'
;
export
*
from
'
./restful
'
;
export
*
from
'
./restful
'
;
export
*
from
'
./pipes
'
;
export
*
from
'
./pipes
'
;
export
*
from
'
./query
'
;
src/decorators/query.ts
0 → 100644
View file @
62d28c7f
import
{
QueryCond
}
from
'
../bases
'
;
import
{
Metadata
}
from
'
../utility/metadata
'
;
import
{
applyQueryProperty
,
applyQueryPropertyLike
,
applyQueryPropertySearch
,
}
from
'
../utility
'
;
export
const
QueryCondition
=
(
cond
:
QueryCond
)
=>
Metadata
.
set
(
'
queryCondition
'
,
cond
,
'
queryConditionFields
'
);
export
const
QueryEqual
=
()
=>
QueryCondition
(
applyQueryProperty
);
export
const
QueryLike
=
()
=>
QueryCondition
(
applyQueryPropertyLike
);
export
const
QuerySearch
=
()
=>
QueryCondition
(
applyQueryPropertySearch
);
src/utility/metadata.ts
View file @
62d28c7f
import
{
MetadataSetter
,
Reflector
}
from
'
typed-reflector
'
;
import
{
MetadataSetter
,
Reflector
}
from
'
typed-reflector
'
;
import
{
QueryCond
}
from
'
../bases
'
;
export
interface
SpecificFields
{
interface
SpecificFields
{
notColumn
:
boolean
;
notColumn
:
boolean
;
notWritable
:
boolean
;
notWritable
:
boolean
;
notChangeable
:
boolean
;
notChangeable
:
boolean
;
}
}
type
MetadataArrayMap
=
{
[
K
in
keyof
SpecificFields
as
`
${
K
}
Fields`
]:
string
};
export
const
Metadata
=
new
MetadataSetter
<
SpecificFields
,
MetadataArrayMap
>
();
interface
MetadataMap
extends
SpecificFields
{
export
const
reflector
=
new
Reflector
<
SpecificFields
,
MetadataArrayMap
>
();
queryCondition
:
QueryCond
;
}
type
FieldsMap
=
{
[
K
in
keyof
MetadataMap
as
`
${
K
}
Fields`
]:
string
;
};
type
MetadataArrayMap
=
FieldsMap
;
export
const
Metadata
=
new
MetadataSetter
<
MetadataMap
,
MetadataArrayMap
>
();
export
const
reflector
=
new
Reflector
<
MetadataMap
,
MetadataArrayMap
>
();
export
function
getSpecificFields
(
obj
:
any
,
type
:
keyof
SpecificFields
)
{
export
function
getSpecificFields
(
obj
:
any
,
type
:
keyof
SpecificFields
)
{
return
reflector
return
reflector
...
...
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