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
0dd313b2
Commit
0dd313b2
authored
Oct 24, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert
parent
1feaf24b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
14 deletions
+7
-14
src/crud-base.ts
src/crud-base.ts
+7
-14
No files found.
src/crud-base.ts
View file @
0dd313b2
...
@@ -23,15 +23,14 @@ import { ConsoleLogger } from '@nestjs/common';
...
@@ -23,15 +23,14 @@ import { ConsoleLogger } from '@nestjs/common';
import
{
camelCase
}
from
'
typeorm/util/StringUtils
'
;
import
{
camelCase
}
from
'
typeorm/util/StringUtils
'
;
import
_
from
'
lodash
'
;
import
_
from
'
lodash
'
;
import
{
ClassType
}
from
'
./utility/insert-field
'
;
import
{
ClassType
}
from
'
./utility/insert-field
'
;
import
{
RecursiveKeyOf
}
from
'
./utility/recursive-key-of
'
;
export
type
EntityId
<
T
extends
{
id
:
any
}
>
=
T
[
'
id
'
];
export
type
EntityId
<
T
extends
{
id
:
any
}
>
=
T
[
'
id
'
];
export
interface
RelationDef
<
T
>
{
export
interface
RelationDef
{
name
:
T
;
name
:
string
;
inner
?:
boolean
;
inner
?:
boolean
;
}
}
export
const
Inner
=
<
T
>
(
name
:
T
):
RelationDef
<
T
>
=>
{
export
const
Inner
=
(
name
:
string
):
RelationDef
=>
{
return
{
name
,
inner
:
true
};
return
{
name
,
inner
:
true
};
};
};
...
@@ -40,7 +39,7 @@ export type ValidCrudEntity<T> = Record<string, any> & {
...
@@ -40,7 +39,7 @@ export type ValidCrudEntity<T> = Record<string, any> & {
}
&
Partial
<
QueryWise
<
T
>
&
DeletionWise
&
EntityHooks
&
PageSettingsFactory
>
;
}
&
Partial
<
QueryWise
<
T
>
&
DeletionWise
&
EntityHooks
&
PageSettingsFactory
>
;
export
interface
CrudOptions
<
T
extends
ValidCrudEntity
<
T
>>
{
export
interface
CrudOptions
<
T
extends
ValidCrudEntity
<
T
>>
{
relations
?:
(
RecursiveKeyOf
<
T
>
|
RelationDef
<
RecursiveKeyOf
<
T
>>
)[];
relations
?:
(
string
|
RelationDef
)[];
extraGetQuery
?:
(
qb
:
SelectQueryBuilder
<
T
>
)
=>
void
;
extraGetQuery
?:
(
qb
:
SelectQueryBuilder
<
T
>
)
=>
void
;
hardDelete
?:
boolean
;
hardDelete
?:
boolean
;
}
}
...
@@ -53,10 +52,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -53,10 +52,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
readonly
entityPaginatedReturnMessageDto
=
PaginatedReturnMessageDto
(
readonly
entityPaginatedReturnMessageDto
=
PaginatedReturnMessageDto
(
this
.
entityClass
,
this
.
entityClass
,
);
);
readonly
entityRelations
:
(
readonly
entityRelations
:
(
string
|
RelationDef
)[];
|
RecursiveKeyOf
<
T
>
|
RelationDef
<
RecursiveKeyOf
<
T
>>
)[];
readonly
extraGetQuery
:
(
qb
:
SelectQueryBuilder
<
T
>
)
=>
void
;
readonly
extraGetQuery
:
(
qb
:
SelectQueryBuilder
<
T
>
)
=>
void
;
readonly
log
=
new
ConsoleLogger
(
`
${
this
.
entityClass
.
name
}
Service`
);
readonly
log
=
new
ConsoleLogger
(
`
${
this
.
entityClass
.
name
}
Service`
);
...
@@ -195,10 +191,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -195,10 +191,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
return
camelCase
(
this
.
entityName
);
return
camelCase
(
this
.
entityName
);
}
}
_applyRelationToQuery
(
_applyRelationToQuery
(
qb
:
SelectQueryBuilder
<
T
>
,
relation
:
RelationDef
)
{
qb
:
SelectQueryBuilder
<
T
>
,
relation
:
RelationDef
<
RecursiveKeyOf
<
T
>>
,
)
{
const
{
name
}
=
relation
;
const
{
name
}
=
relation
;
const
relationUnit
=
name
.
split
(
'
.
'
);
const
relationUnit
=
name
.
split
(
'
.
'
);
const
base
=
const
base
=
...
@@ -216,7 +209,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
...
@@ -216,7 +209,7 @@ export class CrudBase<T extends ValidCrudEntity<T>> {
_applyRelationsToQuery
(
qb
:
SelectQueryBuilder
<
T
>
)
{
_applyRelationsToQuery
(
qb
:
SelectQueryBuilder
<
T
>
)
{
for
(
const
relation
of
this
.
entityRelations
)
{
for
(
const
relation
of
this
.
entityRelations
)
{
if
(
typeof
relation
===
'
string
'
)
{
if
(
typeof
relation
===
'
string
'
)
{
this
.
_applyRelationToQuery
(
qb
,
{
name
:
relation
as
any
});
this
.
_applyRelationToQuery
(
qb
,
{
name
:
relation
});
}
else
{
}
else
{
this
.
_applyRelationToQuery
(
qb
,
relation
);
this
.
_applyRelationToQuery
(
qb
,
relation
);
}
}
...
...
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