Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
W
Wenyuanwall Api
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
nanahira
Wenyuanwall Api
Commits
58e63f29
Commit
58e63f29
authored
Jul 15, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate to nicot
parent
bd6bbede
Pipeline
#14559
passed with stages
in 3 minutes and 59 seconds
Changes
30
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
81 additions
and
1257 deletions
+81
-1257
package-lock.json
package-lock.json
+30
-6
package.json
package.json
+1
-0
src/blacklist-account/blacklist-account.controller.ts
src/blacklist-account/blacklist-account.controller.ts
+4
-2
src/blacklist-account/blacklist-account.service.ts
src/blacklist-account/blacklist-account.service.ts
+5
-5
src/blacklist/blacklist.service.ts
src/blacklist/blacklist.service.ts
+10
-8
src/crud-base/crud-base.ts
src/crud-base/crud-base.ts
+0
-364
src/decorators/crud.decorators.ts
src/decorators/crud.decorators.ts
+0
-107
src/dto/PageSettings.dto.ts
src/dto/PageSettings.dto.ts
+0
-53
src/dto/ReturnMessage.dto.ts
src/dto/ReturnMessage.dto.ts
+0
-123
src/dto/import-entry.dto.ts
src/dto/import-entry.dto.ts
+0
-11
src/entities/bases/AvatarBase.entity.ts
src/entities/bases/AvatarBase.entity.ts
+0
-14
src/entities/bases/IdBase.entity.ts
src/entities/bases/IdBase.entity.ts
+0
-28
src/entities/bases/IdNameBase.entity.ts
src/entities/bases/IdNameBase.entity.ts
+0
-15
src/entities/bases/IdNameDescBase.entity.ts
src/entities/bases/IdNameDescBase.entity.ts
+0
-18
src/entities/bases/ManualAvatarBase.entity.ts
src/entities/bases/ManualAvatarBase.entity.ts
+0
-14
src/entities/bases/ManualIdBase.entity.ts
src/entities/bases/ManualIdBase.entity.ts
+0
-25
src/entities/bases/ManualNameBase.entity.ts
src/entities/bases/ManualNameBase.entity.ts
+0
-17
src/entities/bases/ManualNameDescBase.entity.ts
src/entities/bases/ManualNameDescBase.entity.ts
+0
-21
src/entities/bases/TimeBase.entity.ts
src/entities/bases/TimeBase.entity.ts
+0
-48
src/entities/blacklist-account.entity.ts
src/entities/blacklist-account.entity.ts
+10
-7
src/entities/blacklist.entity.ts
src/entities/blacklist.entity.ts
+21
-7
src/entities/decorators/base.ts
src/entities/decorators/base.ts
+0
-155
src/entities/decorators/extended.ts
src/entities/decorators/extended.ts
+0
-11
src/entities/decorators/relation.ts
src/entities/decorators/relation.ts
+0
-55
src/entities/decorators/transform.ts
src/entities/decorators/transform.ts
+0
-7
src/entities/interfaces/QueryWise.ts
src/entities/interfaces/QueryWise.ts
+0
-5
src/entities/interfaces/wises.ts
src/entities/interfaces/wises.ts
+0
-25
src/entities/utility/bigint-transform.ts
src/entities/utility/bigint-transform.ts
+0
-13
src/entities/utility/query.ts
src/entities/utility/query.ts
+0
-47
src/utility/pipes.ts
src/utility/pipes.ts
+0
-46
No files found.
package-lock.json
View file @
58e63f29
...
...
@@ -20,6 +20,7 @@
"class-validator"
:
"^0.13.2"
,
"lodash"
:
"^4.17.21"
,
"moment"
:
"^2.29.4"
,
"nicot"
:
"^1.0.5"
,
"node-schedule"
:
"^2.1.0"
,
"pg"
:
"^8.7.3"
,
"pg-native"
:
"^3.0.0"
,
...
...
@@ -1583,9 +1584,9 @@
}
},
"node_modules/@nestjs/swagger"
:
{
"version"
:
"6.0.
3
"
,
"resolved"
:
"https://registry.npmjs.org/@nestjs/swagger/-/swagger-6.0.
3
.tgz"
,
"integrity"
:
"sha512-
mpKfa1VOp7c8CPYdS403dO3XP8v6Hq6dI88yzzgmapKLEYPN0cFKXqTF2zULKv+BxqGl7EJM4h3P+cc0I9PStA
=="
,
"version"
:
"6.0.
4
"
,
"resolved"
:
"https://registry.npmjs.org/@nestjs/swagger/-/swagger-6.0.
4
.tgz"
,
"integrity"
:
"sha512-
YKf9RvCYHAgqkMvUG3xRr0zAcnuN8JsWPfvi7h0hzEXLRhNxByj2FT8Rzj+0fPAe6VZioWXBDpLzshO2PjE48Q
=="
,
"dependencies"
:
{
"@nestjs/mapped-types"
:
"1.1.0"
,
"js-yaml"
:
"4.1.0"
,
...
...
@@ -6361,6 +6362,21 @@
"integrity"
:
"sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
,
"dev"
:
true
},
"node_modules/nicot"
:
{
"version"
:
"1.0.5"
,
"resolved"
:
"https://registry.npmjs.org/nicot/-/nicot-1.0.5.tgz"
,
"integrity"
:
"sha512-M3HiKn/SQCmJIOYLLQuC5m0kchqzrKP5MzecXMtJ04YYlAr4tUiz4ZIP+d1CpshNjaAYH+BwDt5FZvS+T6NcMQ=="
,
"dependencies"
:
{
"lodash"
:
"^4.17.21"
},
"peerDependencies"
:
{
"@nestjs/common"
:
"^9.0.3"
,
"@nestjs/swagger"
:
"^6.0.4"
,
"class-transformer"
:
"^0.5.1"
,
"class-validator"
:
"^0.13.2"
,
"typeorm"
:
"^0.3.7"
}
},
"node_modules/node-emoji"
:
{
"version"
:
"1.11.0"
,
"resolved"
:
"https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz"
,
...
...
@@ -10126,9 +10142,9 @@
}
},
"@nestjs/swagger"
:
{
"version"
:
"6.0.
3
"
,
"resolved"
:
"https://registry.npmjs.org/@nestjs/swagger/-/swagger-6.0.
3
.tgz"
,
"integrity"
:
"sha512-
mpKfa1VOp7c8CPYdS403dO3XP8v6Hq6dI88yzzgmapKLEYPN0cFKXqTF2zULKv+BxqGl7EJM4h3P+cc0I9PStA
=="
,
"version"
:
"6.0.
4
"
,
"resolved"
:
"https://registry.npmjs.org/@nestjs/swagger/-/swagger-6.0.
4
.tgz"
,
"integrity"
:
"sha512-
YKf9RvCYHAgqkMvUG3xRr0zAcnuN8JsWPfvi7h0hzEXLRhNxByj2FT8Rzj+0fPAe6VZioWXBDpLzshO2PjE48Q
=="
,
"requires"
:
{
"@nestjs/mapped-types"
:
"1.1.0"
,
"js-yaml"
:
"4.1.0"
,
...
...
@@ -13754,6 +13770,14 @@
"integrity"
:
"sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
,
"dev"
:
true
},
"nicot"
:
{
"version"
:
"1.0.5"
,
"resolved"
:
"https://registry.npmjs.org/nicot/-/nicot-1.0.5.tgz"
,
"integrity"
:
"sha512-M3HiKn/SQCmJIOYLLQuC5m0kchqzrKP5MzecXMtJ04YYlAr4tUiz4ZIP+d1CpshNjaAYH+BwDt5FZvS+T6NcMQ=="
,
"requires"
:
{
"lodash"
:
"^4.17.21"
}
},
"node-emoji"
:
{
"version"
:
"1.11.0"
,
"resolved"
:
"https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz"
,
...
...
package.json
View file @
58e63f29
...
...
@@ -32,6 +32,7 @@
"
class-validator
"
:
"
^0.13.2
"
,
"
lodash
"
:
"
^4.17.21
"
,
"
moment
"
:
"
^2.29.4
"
,
"
nicot
"
:
"
^1.0.5
"
,
"
node-schedule
"
:
"
^2.1.0
"
,
"
pg
"
:
"
^8.7.3
"
,
"
pg-native
"
:
"
^3.0.0
"
,
...
...
src/blacklist-account/blacklist-account.controller.ts
View file @
58e63f29
import
{
Controller
,
Header
}
from
'
@nestjs/common
'
;
import
{
CrudFactory
}
from
'
../decorators/crud.decorators
'
;
import
{
BlacklistAccount
}
from
'
../entities/blacklist-account.entity
'
;
import
{
BlacklistAccountService
}
from
'
./blacklist-account.service
'
;
import
{
RestfulFactory
}
from
'
nicot
'
;
const
dec
=
new
CrudFactory
(
BlacklistAccount
,
[
'
blacklist
'
]);
const
dec
=
new
RestfulFactory
(
BlacklistAccount
,
{
fieldsToOmit
:
[
'
blacklist
'
],
});
class
UpdateDto
extends
dec
.
updateDto
{}
@
Controller
(
'
blacklist
'
)
...
...
src/blacklist-account/blacklist-account.service.ts
View file @
58e63f29
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
CrudBase
,
Inner
}
from
'
../crud-base/crud-base
'
;
import
{
BlacklistAccount
}
from
'
../entities/blacklist-account.entity
'
;
import
{
InjectDataSource
}
from
'
@nestjs/typeorm
'
;
import
{
DataSource
}
from
'
typeorm
'
;
import
{
CrudService
,
Inner
}
from
'
nicot
'
;
@
Injectable
()
export
class
BlacklistAccountService
extends
CrudBase
<
BlacklistAccount
>
{
export
class
BlacklistAccountService
extends
CrudService
(
BlacklistAccount
,
{
relations
:
[
Inner
(
'
blacklist
'
)],
})
{
constructor
(@
InjectDataSource
()
db
:
DataSource
)
{
super
(
BlacklistAccount
,
db
.
getRepository
(
BlacklistAccount
),
[
Inner
(
'
blacklist
'
),
]);
super
(
db
.
getRepository
(
BlacklistAccount
));
}
}
src/blacklist/blacklist.service.ts
View file @
58e63f29
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
CrudBase
,
Inner
}
from
'
../crud-base/crud-base
'
;
import
{
Blacklist
,
HamiData
}
from
'
../entities/blacklist.entity
'
;
import
{
InjectDataSource
}
from
'
@nestjs/typeorm
'
;
import
{
DataSource
}
from
'
typeorm
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
moment
from
'
moment
'
;
import
_
from
'
lodash
'
;
import
{
CrudService
,
Inner
}
from
'
nicot
'
;
@
Injectable
()
export
class
BlacklistService
extends
CrudBase
<
Blacklist
>
{
export
class
BlacklistService
extends
CrudService
(
Blacklist
,
{
relations
:
[
Inner
(
'
blacklistAccount
'
)],
})
{
constructor
(
@
InjectDataSource
()
db
:
DataSource
,
private
config
:
ConfigService
,
)
{
super
(
Blacklist
,
db
.
getRepository
(
Blacklist
),
[
Inner
(
'
blacklistAccount
'
)]
);
super
(
db
.
getRepository
(
Blacklist
)
);
}
async
getSinceTime
()
{
...
...
@@ -31,20 +33,20 @@ export class BlacklistService extends CrudBase<Blacklist> {
}
async
saveEntries
(
entries
:
HamiData
[])
{
this
.
log
(
`Saving
${
entries
.
length
}
entries...`
);
this
.
log
.
log
(
`Saving
${
entries
.
length
}
entries...`
);
const
chunks
=
_
.
chunk
(
entries
.
reverse
(),
4000
);
for
(
const
chunk
of
chunks
)
{
const
blacklists
=
chunk
.
map
((
d
)
=>
new
Blacklist
().
fromData
(
d
));
this
.
log
(
`Saving current chunk of
${
blacklists
.
length
}
entries...`
);
this
.
log
.
log
(
`Saving current chunk of
${
blacklists
.
length
}
entries...`
);
try
{
const
result
=
await
this
.
batchCreate
(
blacklists
,
undefined
,
true
);
this
.
log
(
this
.
log
.
log
(
`Saved
${
result
.
results
.
length
}
entries, and skipped
${
result
.
skipped
.
length
}
duplicated entries.`
,
);
}
catch
(
e
)
{
this
.
log
(
`Failed to save
${
chunk
.
length
}
entries:
${
e
.
message
}
`
);
this
.
log
.
log
(
`Failed to save
${
chunk
.
length
}
entries:
${
e
.
message
}
`
);
}
}
this
.
log
(
`Finished saving
${
entries
.
length
}
entries.`
);
this
.
log
.
log
(
`Finished saving
${
entries
.
length
}
entries.`
);
}
}
src/crud-base/crud-base.ts
deleted
100644 → 0
View file @
bd6bbede
This diff is collapsed.
Click to expand it.
src/decorators/crud.decorators.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ApiBody
,
ApiCreatedResponse
,
ApiNoContentResponse
,
ApiOkResponse
,
ApiOperation
,
ApiParam
,
OmitType
,
PartialType
,
}
from
'
@nestjs/swagger
'
;
import
{
Body
,
Delete
,
Get
,
Patch
,
Post
,
Query
,
Type
}
from
'
@nestjs/common
'
;
import
{
BlankReturnMessageDto
,
PaginatedReturnMessageDto
,
ReturnMessageDto
,
}
from
'
../dto/ReturnMessage.dto
'
;
import
{
TimeBase
,
TimeBaseFields
}
from
'
../entities/bases/TimeBase.entity
'
;
import
{
ClassGetPipe
,
CreatePipe
,
UpdatePipe
}
from
'
../utility/pipes
'
;
export
function
MergeMethodDecorators
(
decorators
:
MethodDecorator
[],
):
MethodDecorator
{
return
(
target
:
any
,
key
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
decorators
.
forEach
((
decorator
)
=>
{
decorator
(
target
,
key
,
descriptor
);
});
};
}
export
class
CrudFactory
<
T
extends
TimeBase
>
{
readonly
createDto
:
Type
<
Omit
<
T
,
keyof
T
>>
;
readonly
updateDto
:
Type
<
Partial
<
Omit
<
T
,
keyof
T
>>>
;
readonly
entityReturnMessageDto
=
ReturnMessageDto
(
this
.
entityClass
);
readonly
entityArrayReturnMessageDto
=
PaginatedReturnMessageDto
(
this
.
entityClass
,
);
constructor
(
public
readonly
entityClass
:
Type
<
T
>
,
fieldsToOmit
:
(
keyof
T
)[]
=
[],
// eslint-disable-next-line @typescript-eslint/ban-types
public
readonly
idType
:
Function
=
Number
,
)
{
this
.
createDto
=
OmitType
(
this
.
entityClass
,
[
...
TimeBaseFields
,
...
fieldsToOmit
,
]);
this
.
updateDto
=
PartialType
(
this
.
createDto
);
}
create
():
MethodDecorator
{
return
MergeMethodDecorators
([
Post
(),
ApiOperation
({
summary
:
`Create a new
${
this
.
entityClass
.
name
}
`
}),
ApiBody
({
type
:
this
.
createDto
}),
ApiCreatedResponse
({
type
:
this
.
entityReturnMessageDto
}),
]);
}
createParam
()
{
return
Body
(
CreatePipe
);
}
findOne
():
MethodDecorator
{
return
MergeMethodDecorators
([
Get
(
'
:id
'
),
ApiOperation
({
summary
:
`Find a
${
this
.
entityClass
.
name
}
by id`
}),
ApiParam
({
name
:
'
id
'
,
type
:
this
.
idType
,
required
:
true
}),
ApiOkResponse
({
type
:
this
.
entityReturnMessageDto
}),
]);
}
findAll
():
MethodDecorator
{
return
MergeMethodDecorators
([
Get
(),
ApiOperation
({
summary
:
`Find all
${
this
.
entityClass
.
name
}
`
}),
ApiOkResponse
({
type
:
this
.
entityArrayReturnMessageDto
}),
]);
}
findAllParam
()
{
return
Query
(
new
ClassGetPipe
(
this
.
entityClass
));
}
update
():
MethodDecorator
{
return
MergeMethodDecorators
([
Patch
(
'
:id
'
),
ApiOperation
({
summary
:
`Update a
${
this
.
entityClass
.
name
}
by id`
}),
ApiParam
({
name
:
'
id
'
,
type
:
this
.
idType
,
required
:
true
}),
ApiBody
({
type
:
this
.
updateDto
}),
ApiOkResponse
({
type
:
BlankReturnMessageDto
}),
]);
}
updateParam
()
{
return
Body
(
UpdatePipe
);
}
delete
():
MethodDecorator
{
return
MergeMethodDecorators
([
Delete
(
'
:id
'
),
ApiOperation
({
summary
:
`Delete a
${
this
.
entityClass
.
name
}
by id`
}),
ApiParam
({
name
:
'
id
'
,
type
:
this
.
idType
,
required
:
true
}),
ApiNoContentResponse
({
type
:
BlankReturnMessageDto
}),
]);
}
}
src/dto/PageSettings.dto.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
IsInt
,
IsPositive
}
from
'
class-validator
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
NotWritable
}
from
'
../entities/decorators/transform
'
;
export
interface
PageSettingsWise
{
pageCount
:
number
;
recordsPerPage
:
number
;
}
export
interface
PageSettingsFactory
{
getActualPageSettings
():
PageSettingsWise
;
}
export
class
PageSettingsDto
implements
PageSettingsWise
,
PageSettingsFactory
{
@
NotWritable
()
@
IsPositive
()
@
IsInt
()
@
ApiProperty
({
description
:
'
The nth page, starting with 1.
'
,
required
:
false
,
})
pageCount
:
number
;
@
NotWritable
()
@
IsPositive
()
@
IsInt
()
@
ApiProperty
({
description
:
'
Records per page.
'
,
required
:
false
})
recordsPerPage
:
number
;
getActualPageSettings
():
PageSettingsWise
{
return
{
pageCount
:
this
.
getPageCount
(),
recordsPerPage
:
this
.
getRecordsPerPage
(),
};
}
private
getPageCount
()
{
return
this
.
pageCount
||
1
;
}
private
getRecordsPerPage
()
{
return
this
.
recordsPerPage
||
25
;
}
private
getStartingFrom
()
{
return
(
this
.
getPageCount
()
-
1
)
*
this
.
getRecordsPerPage
();
}
applyQuery
(
qb
:
SelectQueryBuilder
<
PageSettingsDto
>
,
entityName
:
string
)
{
qb
.
take
(
this
.
getRecordsPerPage
()).
skip
(
this
.
getStartingFrom
());
}
}
src/dto/ReturnMessage.dto.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
import
{
PageSettingsWise
}
from
'
./PageSettings.dto
'
;
export
interface
BlankReturnMessage
{
statusCode
:
number
;
message
:
string
;
success
:
boolean
;
}
export
interface
ReturnMessage
<
T
>
extends
BlankReturnMessage
{
data
?:
T
;
}
export
class
BlankReturnMessageDto
implements
BlankReturnMessage
{
@
ApiProperty
({
description
:
'
Return code
'
})
statusCode
:
number
;
@
ApiProperty
({
description
:
'
Return message
'
})
message
:
string
;
@
ApiProperty
({
description
:
'
Whether success.
'
})
success
:
boolean
;
constructor
(
statusCode
:
number
,
message
?:
string
)
{
this
.
statusCode
=
statusCode
;
this
.
message
=
message
||
'
success
'
;
this
.
success
=
statusCode
<
400
;
}
toException
()
{
return
new
HttpException
(
this
,
this
.
statusCode
);
}
}
export
class
BlankPaginatedReturnMessageDto
extends
BlankReturnMessageDto
implements
PageSettingsWise
{
@
ApiProperty
({
description
:
'
Total record count.
'
})
total
:
number
;
@
ApiProperty
({
description
:
'
Total page count.
'
})
totalPages
:
number
;
@
ApiProperty
({
description
:
'
Current page.
'
})
pageCount
:
number
;
@
ApiProperty
({
description
:
'
Records per page.
'
})
recordsPerPage
:
number
;
constructor
(
statusCode
:
number
,
message
:
string
,
total
:
number
,
pageSettings
:
PageSettingsWise
,
)
{
super
(
statusCode
,
message
);
this
.
total
=
total
;
this
.
pageCount
=
pageSettings
.
pageCount
;
this
.
recordsPerPage
=
pageSettings
.
recordsPerPage
;
this
.
totalPages
=
Math
.
ceil
(
total
/
pageSettings
.
recordsPerPage
);
}
}
type
AnyClass
=
new
(...
args
:
any
[])
=>
any
;
type
ClassOrArray
=
AnyClass
|
[
AnyClass
];
type
TypeFromClass
<
T
>
=
T
extends
new
(...
args
:
any
[])
=>
infer
U
?
U
:
never
;
export
type
ParseType
<
T
extends
ClassOrArray
>
=
T
extends
[
infer
U
]
?
TypeFromClass
<
U
>
[]
:
TypeFromClass
<
T
>
;
function
getClass
(
o
:
ClassOrArray
)
{
return
o
instanceof
Array
?
o
[
0
]
:
o
;
}
export
function
ReturnMessageDto
<
T
extends
ClassOrArray
>
(
type
:
T
)
{
const
cl
=
class
SpecificReturnMessage
extends
BlankReturnMessageDto
{
data
?:
ParseType
<
T
>
;
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
ParseType
<
T
>
)
{
super
(
statusCode
,
message
);
this
.
data
=
data
;
}
};
ApiProperty
({
description
:
'
Return data.
'
,
type
})(
cl
.
prototype
,
'
data
'
);
Object
.
defineProperty
(
cl
,
'
name
'
,
{
value
:
`
${
getClass
(
type
).
name
}
ReturnMessageDto`
,
});
return
cl
;
}
export
function
PaginatedReturnMessageDto
<
T
extends
AnyClass
>
(
type
:
T
)
{
const
cl
=
class
SpecificPaginatedReturnMessageDto
extends
BlankPaginatedReturnMessageDto
implements
PageSettingsWise
{
data
?:
TypeFromClass
<
T
>
[];
constructor
(
statusCode
:
number
,
message
:
string
,
data
:
TypeFromClass
<
T
>
[],
total
:
number
,
pageSettings
:
PageSettingsWise
,
)
{
super
(
statusCode
,
message
,
total
,
pageSettings
);
this
.
data
=
data
;
}
};
ApiProperty
({
description
:
'
Return data.
'
,
type
:
[
type
]
})(
cl
.
prototype
,
'
data
'
,
);
Object
.
defineProperty
(
cl
,
'
name
'
,
{
value
:
`
${
getClass
(
type
).
name
}
PaginatedReturnMessageDto`
,
});
return
cl
;
}
export
class
StringReturnMessageDto
extends
BlankReturnMessageDto
implements
ReturnMessage
<
string
>
{
@
ApiProperty
({
description
:
'
Return data.
'
})
data
?:
string
;
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
string
)
{
super
(
statusCode
,
message
);
this
.
data
=
data
;
}
}
src/dto/import-entry.dto.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
export
class
ImportEntryBaseDto
{
@
ApiProperty
({
description
:
'
Import result
'
})
result
:
string
;
}
export
interface
ImportEntry
<
T
>
{
entry
:
T
;
result
:
string
;
}
src/entities/bases/AvatarBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
IdNameDescBase
}
from
'
./IdNameDescBase.entity
'
;
import
{
StringColumn
}
from
'
../decorators/base
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryPropertyLike
}
from
'
../utility/query
'
;
export
class
AvatarBase
extends
IdNameDescBase
{
@
StringColumn
(
128
,
'
图标地址
'
,
undefined
,
false
)
avatarUrl
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
AvatarBase
>
,
entityName
:
string
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryPropertyLike
(
this
,
qb
,
entityName
,
'
avatarUrl
'
);
}
}
src/entities/bases/IdBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
Column
,
Generated
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
IdWise
}
from
'
../interfaces/wises
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
applyQueryProperty
}
from
'
../utility/query
'
;
import
{
NotWritable
}
from
'
../decorators/transform
'
;
import
{
IsInt
,
IsPositive
}
from
'
class-validator
'
;
import
{
BigintTransformer
}
from
'
../utility/bigint-transform
'
;
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
export
class
IdBase
extends
TimeBase
implements
IdWise
{
@
Generated
(
'
increment
'
)
@
Column
(
'
bigint
'
,
{
primary
:
true
,
unsigned
:
true
,
transformer
:
new
BigintTransformer
(),
})
@
ApiProperty
({
description
:
'
编号
'
,
required
:
false
})
@
NotWritable
()
@
IsInt
()
@
IsPositive
()
id
:
number
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
IdBase
>
,
entityName
:
string
)
{
super
.
applyQuery
(
qb
,
entityName
);
qb
.
orderBy
(
`
${
entityName
}
.id`
,
'
DESC
'
);
applyQueryProperty
(
this
,
qb
,
entityName
,
'
id
'
);
}
}
src/entities/bases/IdNameBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
IdBase
}
from
'
./IdBase.entity
'
;
import
{
IdNameWise
}
from
'
../interfaces/wises
'
;
import
{
EntityName
}
from
'
../decorators/extended
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryPropertyLike
}
from
'
../utility/query
'
;
export
class
IdNameBase
extends
IdBase
implements
IdNameWise
{
@
EntityName
()
name
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
IdNameBase
>
,
entityName
:
string
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryPropertyLike
(
this
,
qb
,
entityName
,
'
name
'
);
}
}
src/entities/bases/IdNameDescBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
IdNameBase
}
from
'
./IdNameBase.entity
'
;
import
{
IdNameDescWise
}
from
'
../interfaces/wises
'
;
import
{
EntityDescription
}
from
'
../decorators/extended
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryPropertySearch
}
from
'
../utility/query
'
;
export
class
IdNameDescBase
extends
IdNameBase
implements
IdNameDescWise
{
@
EntityDescription
()
desc
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
IdNameDescBase
>
,
entityName
:
string
,
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryPropertySearch
(
this
,
qb
,
entityName
,
'
desc
'
);
}
}
src/entities/bases/ManualAvatarBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
StringColumn
}
from
'
../decorators/base
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryProperty
}
from
'
../utility/query
'
;
import
{
ManualNameDescBase
}
from
'
./ManualNameDescBase.entity
'
;
export
class
AvatarBase
extends
ManualNameDescBase
{
@
StringColumn
(
128
,
'
图标地址
'
,
undefined
,
false
)
avatarUrl
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
AvatarBase
>
,
entityName
:
string
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryProperty
(
this
,
qb
,
entityName
,
'
avatarUrl
'
);
}
}
src/entities/bases/ManualIdBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
PrimaryColumn
,
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
StringIdWise
}
from
'
../interfaces/wises
'
;
import
{
applyQueryProperty
}
from
'
../utility/query
'
;
import
{
NotChangeable
}
from
'
../decorators/transform
'
;
import
{
IsNotEmpty
,
IsString
}
from
'
class-validator
'
;
import
{
TimeBase
}
from
'
./TimeBase.entity
'
;
export
class
ManualIdBase
extends
TimeBase
implements
StringIdWise
{
@
PrimaryColumn
(
'
varchar
'
,
{
length
:
32
})
@
ApiProperty
({
description
:
'
编号
'
})
@
NotChangeable
()
@
IsString
()
@
IsNotEmpty
()
id
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
ManualIdBase
>
,
entityName
:
string
,
)
{
super
.
applyQuery
(
qb
,
entityName
);
qb
.
orderBy
(
`
${
entityName
}
.id`
,
'
ASC
'
);
applyQueryProperty
(
this
,
qb
,
entityName
,
'
id
'
);
}
}
src/entities/bases/ManualNameBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ManualIdBase
}
from
'
./ManualIdBase.entity
'
;
import
{
StringIdNameWise
}
from
'
../interfaces/wises
'
;
import
{
EntityName
}
from
'
../decorators/extended
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryPropertyLike
}
from
'
../utility/query
'
;
export
class
ManualNameBase
extends
ManualIdBase
implements
StringIdNameWise
{
@
EntityName
()
name
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
ManualNameBase
>
,
entityName
:
string
,
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryPropertyLike
(
this
,
qb
,
entityName
,
'
name
'
);
}
}
src/entities/bases/ManualNameDescBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ManualNameBase
}
from
'
./ManualNameBase.entity
'
;
import
{
StringIdNameDescWise
}
from
'
../interfaces/wises
'
;
import
{
EntityDescription
}
from
'
../decorators/extended
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
import
{
applyQueryPropertySearch
}
from
'
../utility/query
'
;
export
class
ManualNameDescBase
extends
ManualNameBase
implements
StringIdNameDescWise
{
@
EntityDescription
()
desc
:
string
;
override
applyQuery
(
qb
:
SelectQueryBuilder
<
ManualNameDescBase
>
,
entityName
:
string
,
)
{
super
.
applyQuery
(
qb
,
entityName
);
applyQueryPropertySearch
(
this
,
qb
,
entityName
,
'
desc
'
);
}
}
src/entities/bases/TimeBase.entity.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
CreateDateColumn
,
DeleteDateColumn
,
UpdateDateColumn
}
from
'
typeorm
'
;
import
{
PageSettingsDto
}
from
'
../../dto/PageSettings.dto
'
;
import
{
NotColumn
}
from
'
../decorators/base
'
;
export
interface
DeletionWise
{
deleteTime
?:
Date
;
}
export
interface
ImportWise
{
isValidInCreation
():
string
|
undefined
;
prepareForSaving
():
Promise
<
void
>
;
afterSaving
():
void
;
}
export
class
TimeBase
extends
PageSettingsDto
implements
DeletionWise
,
ImportWise
{
@
CreateDateColumn
({
select
:
false
})
@
NotColumn
()
createTime
:
Date
;
@
UpdateDateColumn
({
select
:
false
})
@
NotColumn
()
updateTime
:
Date
;
@
DeleteDateColumn
({
select
:
false
})
@
NotColumn
()
deleteTime
:
Date
;
toObject
()
{
return
JSON
.
parse
(
JSON
.
stringify
(
this
));
}
isValidInCreation
():
string
|
undefined
{
return
;
}
async
prepareForSaving
():
Promise
<
void
>
{}
afterSaving
()
{}
}
export
const
TimeBaseFields
:
(
keyof
TimeBase
)[]
=
[
'
createTime
'
,
'
updateTime
'
,
'
deleteTime
'
,
];
src/entities/blacklist-account.entity.ts
View file @
58e63f29
import
{
Entity
,
ManyToOne
,
SelectQueryBuilder
,
Unique
}
from
'
typeorm
'
;
import
{
IdBase
}
from
'
./bases/IdBase.entity
'
;
import
{
NotColumn
,
StringColumn
}
from
'
./decorators/base
'
;
import
{
StringRelationColumn
}
from
'
./decorators/relation
'
;
import
{
Blacklist
}
from
'
./blacklist.entity
'
;
import
{
applyQueryProperty
}
from
'
./utility/query
'
;
import
{
applyQueryProperty
,
IdBase
,
NotColumn
,
StringColumn
}
from
'
nicot
'
;
@
Unique
([
'
account
'
,
'
blacklist
'
])
@
Entity
()
export
class
BlacklistAccount
extends
IdBase
{
@
StringColumn
(
11
,
'
QQ account number.
'
,
undefined
,
true
)
export
class
BlacklistAccount
extends
IdBase
()
{
@
StringColumn
(
11
,
{
required
:
true
,
description
:
'
QQ account number.
'
,
})
account
:
string
;
@
StringRelationColumn
(
'
Blacklist ID.
'
,
true
)
@
StringColumn
(
32
,
{
required
:
true
,
description
:
'
Blacklist ID.
'
,
})
blacklistId
:
string
;
@
NotColumn
()
...
...
src/entities/blacklist.entity.ts
View file @
58e63f29
import
{
Entity
,
Index
,
OneToMany
}
from
'
typeorm
'
;
import
{
ManualIdBase
}
from
'
./bases/ManualIdBase.entity
'
;
import
{
DateColumn
,
NotColumn
,
StringColumn
}
from
'
./decorators/base
'
;
import
{
BlacklistAccount
}
from
'
./blacklist-account.entity
'
;
import
{
DateColumn
,
IdBase
,
NotColumn
,
StringColumn
,
StringIdBase
,
}
from
'
nicot
'
;
interface
TwintData
{
cashtags
:
string
[];
...
...
@@ -49,20 +54,29 @@ export interface HamiData extends TwintData {
}
@
Entity
()
export
class
Blacklist
extends
ManualIdBase
{
@
StringColumn
(
100
,
'
Twitter link.
'
,
undefined
,
true
)
export
class
Blacklist
extends
StringIdBase
({
length
:
32
})
{
@
StringColumn
(
100
,
{
description
:
'
Twitter link
'
,
required
:
true
,
})
link
:
string
;
@
Index
()
@
DateColumn
(
'
Tweet time
'
,
true
)
@
DateColumn
({
description
:
'
Tweet time
'
,
required
:
true
,
})
time
:
Date
;
@
StringColumn
(
500
,
'
Tweet content.
'
,
undefined
,
true
)
@
StringColumn
(
500
,
{
description
:
'
Tweet content
'
,
required
:
true
,
})
content
:
string
;
@
NotColumn
()
@
OneToMany
(
(
type
)
=>
BlacklistAccount
,
()
=>
BlacklistAccount
,
(
blacklistAccount
)
=>
blacklistAccount
.
blacklist
,
{
cascade
:
true
},
)
...
...
src/entities/decorators/base.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
Column
,
Index
}
from
'
typeorm
'
;
import
{
ApiProperty
,
ApiPropertyOptions
}
from
'
@nestjs/swagger
'
;
import
{
ColumnWithLengthOptions
}
from
'
typeorm/decorator/options/ColumnWithLengthOptions
'
;
import
{
ColumnCommonOptions
}
from
'
typeorm/decorator/options/ColumnCommonOptions
'
;
import
{
ColumnEnumOptions
}
from
'
typeorm/decorator/options/ColumnEnumOptions
'
;
import
{
IsDate
,
IsEnum
,
IsInt
,
IsNotEmpty
,
IsOptional
,
IsString
,
MaxLength
,
Min
,
}
from
'
class-validator
'
;
import
{
ColumnWithWidthOptions
}
from
'
typeorm/decorator/options/ColumnWithWidthOptions
'
;
import
{
BigintTransformer
}
from
'
../utility/bigint-transform
'
;
import
{
Exclude
}
from
'
class-transformer
'
;
export
function
MergePropertyDecorators
(
decs
:
PropertyDecorator
[],
):
PropertyDecorator
{
return
(
obj
,
key
)
=>
{
for
(
const
dec
of
decs
)
{
dec
(
obj
,
key
);
}
};
}
export
const
OptionalValidate
=
(...
conitions
:
PropertyDecorator
[])
=>
MergePropertyDecorators
([
IsOptional
(),
...
conitions
]);
export
const
StringColumn
=
(
length
=
32
,
description
=
'
unknown
'
,
defaultValue
?:
string
,
required
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnWithLengthOptions
=
{},
propertyExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
Column
(
'
varchar
'
,
{
length
,
default
:
defaultValue
,
nullable
:
!
required
&&
defaultValue
==
null
,
comment
:
description
,
...
columnExtras
,
}),
ApiProperty
({
type
:
String
,
description
,
default
:
defaultValue
,
required
:
required
&&
defaultValue
==
null
,
maxLength
:
length
,
...
propertyExtras
,
}),
...(
required
?
[]
:
[
IsOptional
()]),
IsString
(),
IsNotEmpty
(),
MaxLength
(
length
),
]);
export
const
IntColumn
=
(
type
:
'
int
'
|
'
smallint
'
|
'
bigint
'
|
'
tinyint
'
=
'
int
'
,
unsigned
=
false
,
description
=
'
unknown
'
,
defaultValue
?:
number
,
required
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnWithWidthOptions
=
{},
propertyExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
Column
(
type
,
{
default
:
defaultValue
,
nullable
:
!
required
&&
defaultValue
==
null
,
unsigned
,
comment
:
description
,
...(
type
===
'
bigint
'
?
{
transformer
:
new
BigintTransformer
()
}
:
{}),
...
columnExtras
,
}),
ApiProperty
({
type
:
Number
,
description
,
default
:
defaultValue
,
required
:
required
&&
defaultValue
==
null
,
...
propertyExtras
,
}),
...(
required
?
[]
:
[
IsOptional
()]),
IsInt
(),
...(
unsigned
?
[
Min
(
0
)]
:
[]),
]);
export
const
EnumColumn
=
<
T
>
(
targetEnum
:
Record
<
string
,
T
>
,
description
=
'
unknown
'
,
defaultValue
?:
T
,
required
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnEnumOptions
=
{},
swaggerExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
Index
(),
Column
(
'
enum
'
,
{
enum
:
targetEnum
,
default
:
defaultValue
,
nullable
:
!
required
&&
!
defaultValue
,
comment
:
description
,
...
columnExtras
,
}),
ApiProperty
({
description
,
enum
:
targetEnum
,
default
:
defaultValue
,
required
,
...
swaggerExtras
,
}),
...(
required
?
[]
:
[
IsOptional
()]),
IsEnum
(
targetEnum
),
]);
export
const
DateColumn
=
<
T
>
(
description
=
'
unknown
'
,
required
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnEnumOptions
=
{},
swaggerExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
IsDate
(),
...(
required
?
[]
:
[
IsOptional
()]),
Column
(
'
timestamp
'
,
{
nullable
:
!
required
,
comment
:
description
,
...
columnExtras
,
}),
ApiProperty
({
description
,
type
:
Date
,
required
,
...
swaggerExtras
,
}),
]);
export
const
NotColumn
=
(
description
?:
string
,
swaggerExtras
:
ApiPropertyOptions
=
{},
):
PropertyDecorator
=>
MergePropertyDecorators
([
Exclude
(),
ApiProperty
({
description
,
required
:
false
,
readOnly
:
true
,
...
swaggerExtras
,
}),
]);
src/entities/decorators/extended.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
MergePropertyDecorators
,
StringColumn
}
from
'
./base
'
;
import
{
Index
}
from
'
typeorm
'
;
export
const
EntityName
=
(
length
=
32
,
description
=
'
名称
'
)
=>
MergePropertyDecorators
([
Index
(),
StringColumn
(
length
,
description
,
undefined
,
true
),
]);
export
const
EntityDescription
=
(
length
=
5000
,
description
=
'
描述
'
)
=>
StringColumn
(
length
,
description
,
''
,
false
);
src/entities/decorators/relation.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
Column
}
from
'
typeorm
'
;
import
{
MergePropertyDecorators
}
from
'
./base
'
;
import
{
ApiProperty
,
ApiPropertyOptions
}
from
'
@nestjs/swagger
'
;
import
{
IsInt
,
IsNotEmpty
,
IsOptional
,
IsPositive
}
from
'
class-validator
'
;
import
{
BigintTransformer
}
from
'
../utility/bigint-transform
'
;
import
{
ColumnCommonOptions
}
from
'
typeorm/decorator/options/ColumnCommonOptions
'
;
import
{
ColumnWithLengthOptions
}
from
'
typeorm/decorator/options/ColumnWithLengthOptions
'
;
import
{
ColumnWithWidthOptions
}
from
'
typeorm/decorator/options/ColumnWithWidthOptions
'
;
export
const
RelationColumn
=
(
description
=
'
对应编号
'
,
notNull
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnWithWidthOptions
=
{},
propertyExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
Column
(
'
bigint
'
,
{
nullable
:
!
notNull
,
unsigned
:
true
,
transformer
:
new
BigintTransformer
(),
comment
:
description
,
...
columnExtras
,
}),
ApiProperty
({
type
:
Number
,
description
,
required
:
notNull
,
...
propertyExtras
,
}),
...(
notNull
?
[]
:
[
IsOptional
()]),
IsInt
(),
IsPositive
(),
]);
export
const
StringRelationColumn
=
(
description
=
'
对应编号
'
,
notNull
=
false
,
columnExtras
:
ColumnCommonOptions
&
ColumnWithLengthOptions
=
{},
propertyExtras
:
ApiPropertyOptions
=
{},
)
=>
MergePropertyDecorators
([
Column
(
'
varchar
'
,
{
length
:
32
,
nullable
:
!
notNull
,
comment
:
description
,
...
columnExtras
,
}),
ApiProperty
({
type
:
String
,
required
:
notNull
,
description
,
...
propertyExtras
,
}),
...(
notNull
?
[]
:
[
IsOptional
()]),
IsNotEmpty
(),
]);
src/entities/decorators/transform.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
Expose
}
from
'
class-transformer
'
;
import
{
MergePropertyDecorators
}
from
'
./base
'
;
import
{
IsOptional
}
from
'
class-validator
'
;
export
const
NotWritable
=
()
=>
MergePropertyDecorators
([
Expose
({
groups
:
[
'
r
'
]
}),
IsOptional
()]);
export
const
NotChangeable
=
()
=>
Expose
({
groups
:
[
'
r
'
,
'
c
'
]
});
src/entities/interfaces/QueryWise.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
export
interface
QueryWise
<
T
>
{
applyQuery
(
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
):
void
;
}
src/entities/interfaces/wises.ts
deleted
100644 → 0
View file @
bd6bbede
export
interface
IdWise
{
id
:
number
;
}
export
interface
StringIdWise
{
id
:
string
;
}
export
interface
NameWise
{
name
:
string
;
}
export
interface
DescWise
{
desc
:
string
;
}
export
interface
NameDescWise
extends
NameWise
,
DescWise
{}
export
interface
IdNameWise
extends
IdWise
,
NameWise
{}
export
interface
StringIdNameWise
extends
StringIdWise
,
NameWise
{}
export
interface
IdNameDescWise
extends
IdWise
,
NameDescWise
{}
export
interface
StringIdNameDescWise
extends
StringIdNameWise
,
DescWise
{}
src/entities/utility/bigint-transform.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ValueTransformer
}
from
'
typeorm
'
;
export
class
BigintTransformer
implements
ValueTransformer
{
from
(
dbValue
)
{
if
(
dbValue
==
null
)
{
return
dbValue
;
}
return
parseInt
(
dbValue
);
}
to
(
entValue
):
any
{
return
entValue
;
}
}
src/entities/utility/query.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
TimeBase
}
from
'
../bases/TimeBase.entity
'
;
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
export
function
applyQueryProperty
<
T
extends
TimeBase
>
(
obj
:
T
,
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
,
...
fields
:
(
keyof
T
&
string
)[]
)
{
for
(
const
field
of
fields
)
{
if
(
obj
[
field
]
==
null
)
{
continue
;
}
qb
.
andWhere
(
`
${
entityName
}
.
${
field
}
= :
${
field
}
`
,
{
[
field
]:
obj
[
field
]
});
}
}
export
function
applyQueryPropertyLike
<
T
extends
TimeBase
>
(
obj
:
T
,
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
,
...
fields
:
(
keyof
T
&
string
)[]
)
{
for
(
const
field
of
fields
)
{
if
(
obj
[
field
]
==
null
)
{
continue
;
}
qb
.
andWhere
(
`
${
entityName
}
.
${
field
}
like (:
${
field
}
|| '%')`
,
{
[
field
]:
obj
[
field
],
});
}
}
export
function
applyQueryPropertySearch
<
T
extends
TimeBase
>
(
obj
:
T
,
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
,
...
fields
:
(
keyof
T
&
string
)[]
)
{
for
(
const
field
of
fields
)
{
if
(
obj
[
field
]
==
null
)
{
continue
;
}
qb
.
andWhere
(
`
${
entityName
}
.
${
field
}
like ('%' || :
${
field
}
|| '%')`
,
{
[
field
]:
obj
[
field
],
});
}
}
src/utility/pipes.ts
deleted
100644 → 0
View file @
bd6bbede
import
{
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
ClassConstructor
,
plainToInstance
}
from
'
class-transformer
'
;
export
const
CreatePipe
=
new
ValidationPipe
({
transform
:
true
,
transformOptions
:
{
groups
:
[
'
c
'
],
enableImplicitConversion
:
true
},
});
export
const
GetPipe
=
new
ValidationPipe
({
transform
:
true
,
transformOptions
:
{
groups
:
[
'
r
'
],
enableImplicitConversion
:
true
},
skipMissingProperties
:
true
,
skipNullProperties
:
true
,
skipUndefinedProperties
:
true
,
});
export
class
ClassGetPipe
<
T
>
extends
ValidationPipe
{
constructor
(
private
readonly
classConstructor
:
ClassConstructor
<
T
>
)
{
super
({
transform
:
false
,
transformOptions
:
{
groups
:
[
'
r
'
],
enableImplicitConversion
:
true
,
},
skipMissingProperties
:
true
,
skipNullProperties
:
true
,
skipUndefinedProperties
:
true
,
});
}
override
async
transform
(
value
:
any
,
metadata
:
any
)
{
const
obj
=
await
super
.
transform
(
value
,
metadata
);
return
plainToInstance
(
this
.
classConstructor
,
obj
,
{
groups
:
[
'
r
'
],
enableImplicitConversion
:
false
,
});
}
}
export
const
UpdatePipe
=
new
ValidationPipe
({
transform
:
true
,
transformOptions
:
{
groups
:
[
'
u
'
],
enableImplicitConversion
:
true
},
skipMissingProperties
:
true
,
skipNullProperties
:
true
,
skipUndefinedProperties
:
true
,
});
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