Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
I
init-things
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
init-things
Commits
c6213c70
Commit
c6213c70
authored
Sep 27, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nest-typeorm move and fix
parent
864e6f5c
Pipeline
#16880
passed with stages
in 3 minutes and 45 seconds
Changes
46
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
46 changed files
with
24 additions
and
2252 deletions
+24
-2252
things/nest-typeorm/.dockerignore
things/nest-typeorm/.dockerignore
+0
-42
things/nest-typeorm/.gitignore
things/nest-typeorm/.gitignore
+0
-38
things/nest-typeorm/.gitkeep
things/nest-typeorm/.gitkeep
+0
-0
things/nest-typeorm/.gitlab-ci.yml
things/nest-typeorm/.gitlab-ci.yml
+0
-51
things/nest-typeorm/.npmignore
things/nest-typeorm/.npmignore
+0
-9
things/nest-typeorm/Dockerfile
things/nest-typeorm/Dockerfile
+1
-0
things/nest-typeorm/LICENSE
things/nest-typeorm/LICENSE
+0
-661
things/nest-typeorm/README.md
things/nest-typeorm/README.md
+0
-30
things/nest-typeorm/install-npm-typeorm.sh
things/nest-typeorm/install-npm-typeorm.sh
+0
-0
things/nest-typeorm/install-npm.sh
things/nest-typeorm/install-npm.sh
+0
-15
things/nest-typeorm/src/app.controller.spec.ts
things/nest-typeorm/src/app.controller.spec.ts
+0
-22
things/nest-typeorm/src/app.module.ts
things/nest-typeorm/src/app.module.ts
+18
-16
things/nest-typeorm/src/app.service.ts
things/nest-typeorm/src/app.service.ts
+0
-17
things/nest-typeorm/src/crud-base/crud-base.ts
things/nest-typeorm/src/crud-base/crud-base.ts
+0
-356
things/nest-typeorm/src/decorators/crud.decorators.ts
things/nest-typeorm/src/decorators/crud.decorators.ts
+0
-125
things/nest-typeorm/src/dto/PageSettings.dto.ts
things/nest-typeorm/src/dto/PageSettings.dto.ts
+0
-50
things/nest-typeorm/src/dto/ReturnMessage.dto.ts
things/nest-typeorm/src/dto/ReturnMessage.dto.ts
+1
-115
things/nest-typeorm/src/dto/import-entry.dto.ts
things/nest-typeorm/src/dto/import-entry.dto.ts
+0
-11
things/nest-typeorm/src/entities/User.entity.ts
things/nest-typeorm/src/entities/User.entity.ts
+0
-14
things/nest-typeorm/src/entities/bases/AvatarBase.entity.ts
things/nest-typeorm/src/entities/bases/AvatarBase.entity.ts
+0
-14
things/nest-typeorm/src/entities/bases/IdBase.entity.ts
things/nest-typeorm/src/entities/bases/IdBase.entity.ts
+0
-28
things/nest-typeorm/src/entities/bases/IdNameBase.entity.ts
things/nest-typeorm/src/entities/bases/IdNameBase.entity.ts
+0
-15
things/nest-typeorm/src/entities/bases/IdNameDescBase.entity.ts
.../nest-typeorm/src/entities/bases/IdNameDescBase.entity.ts
+0
-18
things/nest-typeorm/src/entities/bases/ManualAvatarBase.entity.ts
...est-typeorm/src/entities/bases/ManualAvatarBase.entity.ts
+0
-14
things/nest-typeorm/src/entities/bases/ManualIdBase.entity.ts
...gs/nest-typeorm/src/entities/bases/ManualIdBase.entity.ts
+0
-25
things/nest-typeorm/src/entities/bases/ManualNameBase.entity.ts
.../nest-typeorm/src/entities/bases/ManualNameBase.entity.ts
+0
-17
things/nest-typeorm/src/entities/bases/ManualNameDescBase.entity.ts
...t-typeorm/src/entities/bases/ManualNameDescBase.entity.ts
+0
-21
things/nest-typeorm/src/entities/bases/TimeBase.entity.ts
things/nest-typeorm/src/entities/bases/TimeBase.entity.ts
+0
-48
things/nest-typeorm/src/entities/decorators/base.ts
things/nest-typeorm/src/entities/decorators/base.ts
+0
-132
things/nest-typeorm/src/entities/decorators/extended.ts
things/nest-typeorm/src/entities/decorators/extended.ts
+0
-11
things/nest-typeorm/src/entities/decorators/relation.ts
things/nest-typeorm/src/entities/decorators/relation.ts
+0
-55
things/nest-typeorm/src/entities/decorators/transform.ts
things/nest-typeorm/src/entities/decorators/transform.ts
+0
-7
things/nest-typeorm/src/entities/interfaces/QueryWise.ts
things/nest-typeorm/src/entities/interfaces/QueryWise.ts
+0
-5
things/nest-typeorm/src/entities/interfaces/wises.ts
things/nest-typeorm/src/entities/interfaces/wises.ts
+0
-25
things/nest-typeorm/src/entities/utility/bigint-transform.ts
things/nest-typeorm/src/entities/utility/bigint-transform.ts
+0
-13
things/nest-typeorm/src/entities/utility/query.ts
things/nest-typeorm/src/entities/utility/query.ts
+0
-47
things/nest-typeorm/src/main.ts
things/nest-typeorm/src/main.ts
+0
-22
things/nest-typeorm/src/utility/pipes.ts
things/nest-typeorm/src/utility/pipes.ts
+0
-46
things/nest-typeorm/test/app.e2e-spec.ts
things/nest-typeorm/test/app.e2e-spec.ts
+0
-24
things/nest-typeorm/test/jest-e2e.json
things/nest-typeorm/test/jest-e2e.json
+0
-9
things/nest-typeorm/tsconfig.json
things/nest-typeorm/tsconfig.json
+0
-18
things/nest-typeorm2/Dockerfile
things/nest-typeorm2/Dockerfile
+0
-21
things/nest-typeorm2/nest-cli.json
things/nest-typeorm2/nest-cli.json
+0
-7
things/nest-typeorm2/src/app.module.ts
things/nest-typeorm2/src/app.module.ts
+0
-36
things/nest-typeorm2/src/dto/ReturnMessage.dto.ts
things/nest-typeorm2/src/dto/ReturnMessage.dto.ts
+0
-1
things/nest/src/dto/ReturnMessage.dto.ts
things/nest/src/dto/ReturnMessage.dto.ts
+4
-1
No files found.
things/nest-typeorm/.dockerignore
deleted
100644 → 0
View file @
864e6f5c
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
.git*
Dockerfile
.dockerignore
things/nest-typeorm/.gitignore
deleted
100644 → 0
View file @
864e6f5c
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
\ No newline at end of file
things/nest-typeorm
2
/.gitkeep
→
things/nest-typeorm/.gitkeep
View file @
c6213c70
File moved
things/nest-typeorm/.gitlab-ci.yml
deleted
100644 → 0
View file @
864e6f5c
stages
:
-
build
-
deploy
variables
:
GIT_DEPTH
:
"
1"
before_script
:
-
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
.build-image
:
stage
:
build
script
:
-
docker build --pull -t $TARGET_IMAGE .
-
docker push $TARGET_IMAGE
build-x86
:
extends
:
.build-image
tags
:
-
docker
variables
:
TARGET_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
build-arm
:
extends
:
.build-image
tags
:
-
docker-arm
variables
:
TARGET_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
.deploy
:
stage
:
deploy
tags
:
-
docker
script
:
-
docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86
-
docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
-
docker manifest create $TARGET_IMAGE --amend $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-x86 --amend
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-arm
-
docker manifest push $TARGET_IMAGE
deploy_latest
:
extends
:
.deploy
variables
:
TARGET_IMAGE
:
$CI_REGISTRY_IMAGE:latest
only
:
-
master
deploy_branch
:
extends
:
.deploy
variables
:
TARGET_IMAGE
:
$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
things/nest-typeorm/.npmignore
deleted
100644 → 0
View file @
864e6f5c
/install-npm.sh
.git*
/data
/output
/config.yaml
.idea
.dockerignore
Dockerfile
/src
things/nest-typeorm/Dockerfile
View file @
c6213c70
...
@@ -14,6 +14,7 @@ FROM base
...
@@ -14,6 +14,7 @@ FROM base
ENV
NODE_ENV production
ENV
NODE_ENV production
RUN
npm ci
&&
npm cache clean
--force
RUN
npm ci
&&
npm cache clean
--force
COPY
--from=builder /usr/src/app/dist ./dist
COPY
--from=builder /usr/src/app/dist ./dist
COPY
./config.example.yaml ./config.yaml
ENV
NODE_PG_FORCE_NATIVE=true
ENV
NODE_PG_FORCE_NATIVE=true
EXPOSE
3000
EXPOSE
3000
...
...
things/nest-typeorm/LICENSE
deleted
100644 → 0
View file @
864e6f5c
This diff is collapsed.
Click to expand it.
things/nest-typeorm/README.md
deleted
100644 → 0
View file @
864e6f5c
# App name
App description.
## Environment
*
`DB_HOST`
`DB_PORT`
`DB_USER`
`DB_PASS`
`DB_NAME`
Database configs.
## Installation
```
bash
$
npm
install
```
## Running the app
```
bash
# development
$
npm run start
# watch mode
$
npm run start:dev
# production mode
$
npm run start:prod
```
## License
AGPLv3
things/nest-typeorm
2
/install-npm-typeorm.sh
→
things/nest-typeorm/install-npm-typeorm.sh
View file @
c6213c70
File moved
things/nest-typeorm/install-npm.sh
deleted
100755 → 0
View file @
864e6f5c
#!/bin/bash
npm
install
--save-exact
--legacy-peer-deps
typeorm@0.2.45 @nestjs/typeorm@8.0.4
npm
install
--save
\
class-validator
\
class-transformer
\
@nestjs/swagger
\
@nestjs/config
\
pg
\
pg-native
\
reflect-metadata
npm
install
--save-dev
\
@types/express
\
@types/multer
things/nest-typeorm/src/app.controller.spec.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
describe
(
'
AppController
'
,
()
=>
{
let
appController
:
AppController
;
beforeEach
(
async
()
=>
{
const
app
:
TestingModule
=
await
Test
.
createTestingModule
({
controllers
:
[
AppController
],
providers
:
[
AppService
],
}).
compile
();
appController
=
app
.
get
<
AppController
>
(
AppController
);
});
describe
(
'
root
'
,
()
=>
{
it
(
'
should be defined
'
,
()
=>
{
expect
(
appController
).
toBeDefined
();
});
});
});
things/nest-typeorm/src/app.module.ts
View file @
c6213c70
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
User
}
from
'
./entities/User.entity
'
;
import
{
loadConfig
}
from
'
./utility/config
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
@
Module
({
@
Module
({
imports
:
[
imports
:
[
ConfigModule
.
forRoot
({
ConfigModule
.
forRoot
({
load
:
[
loadConfig
],
isGlobal
:
true
,
isGlobal
:
true
,
ignoreEnvVars
:
true
,
ignoreEnvFile
:
true
,
}),
}),
TypeOrmModule
.
forRootAsync
({
TypeOrmModule
.
forRootAsync
({
inject
:
[
ConfigService
],
inject
:
[
ConfigService
],
useFactory
:
async
(
config
:
ConfigService
)
=>
{
useFactory
:
async
(
config
:
ConfigService
)
=>
({
return
{
type
:
'
postgres
'
,
type
:
'
postgres
'
,
entities
:
[],
entities
:
[
User
],
// entities here
autoLoadEntities
:
true
,
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
username
:
config
.
get
(
'
DB_USER
'
),
username
:
config
.
get
(
'
DB_USER
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
supportBigNumbers
:
true
,
supportBigNumbers
:
true
,
bigNumberStrings
:
false
,
bigNumberStrings
:
false
,
};
}),
},
}),
}),
],
],
controllers
:
[
AppController
],
controllers
:
[
AppController
],
...
...
things/nest-typeorm/src/app.service.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
Connection
}
from
'
typeorm
'
;
import
{
InjectConnection
}
from
'
@nestjs/typeorm
'
;
import
{
Injectable
,
ConsoleLogger
}
from
'
@nestjs/common
'
;
@
Injectable
()
export
class
AppService
extends
ConsoleLogger
{
constructor
(
@
InjectConnection
(
'
app
'
)
private
db
:
Connection
,
)
{
super
(
'
app
'
);
}
getHello
():
string
{
return
'
Hello World!
'
;
}
}
things/nest-typeorm/src/crud-base/crud-base.ts
deleted
100644 → 0
View file @
864e6f5c
This diff is collapsed.
Click to expand it.
things/nest-typeorm/src/decorators/crud.decorators.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
ApiBody
,
ApiCreatedResponse
,
ApiNoContentResponse
,
ApiOkResponse
,
ApiOperation
,
ApiParam
,
ApiProperty
,
OmitType
,
PartialType
,
}
from
'
@nestjs/swagger
'
;
import
{
Body
,
Delete
,
Get
,
Patch
,
Post
,
Query
,
Type
}
from
'
@nestjs/common
'
;
import
{
BlankPaginatedReturnMessageDto
,
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
:
Type
<
ReturnMessageDto
<
T
>>
;
readonly
entityArrayReturnMessageDto
:
Type
<
PaginatedReturnMessageDto
<
T
>>
;
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
);
this
.
entityReturnMessageDto
=
class
EntityReturnMessageDto
extends
(
BlankReturnMessageDto
)
{
data
:
T
;
};
ApiProperty
({
type
:
this
.
entityClass
})(
this
.
entityReturnMessageDto
.
prototype
,
'
data
'
,
);
this
.
entityArrayReturnMessageDto
=
class
EntityArrayReturnMessageDto
extends
(
BlankPaginatedReturnMessageDto
)
{
data
:
T
[];
};
ApiProperty
({
type
:
[
this
.
entityClass
]
})(
this
.
entityArrayReturnMessageDto
.
prototype
,
'
data
'
,
);
}
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
}),
]);
}
}
things/nest-typeorm/src/dto/PageSettings.dto.ts
deleted
100644 → 0
View file @
864e6f5c
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
:
'
第 n 页,从 1 开始
'
,
required
:
false
})
pageCount
:
number
;
@
NotWritable
()
@
IsPositive
()
@
IsInt
()
@
ApiProperty
({
description
:
'
每页显示的数量
'
,
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
());
}
}
things/nest-typeorm/src/dto/ReturnMessage.dto.ts
View file @
c6213c70
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
// Blank for nicot use.
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
:
'
返回状态
'
})
statusCode
:
number
;
@
ApiProperty
({
description
:
'
返回信息
'
})
message
:
string
;
@
ApiProperty
({
description
:
'
是否成功
'
})
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
:
number
;
@
ApiProperty
({
description
:
'
总页数
'
})
totalPages
:
number
;
@
ApiProperty
({
description
:
'
当前页
'
})
pageCount
:
number
;
@
ApiProperty
({
description
:
'
每页数量
'
})
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
:
'
返回数据
'
,
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
:
'
返回数据
'
,
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
:
'
返回内容
'
})
data
?:
string
;
constructor
(
statusCode
:
number
,
message
?:
string
,
data
?:
string
)
{
super
(
statusCode
,
message
);
this
.
data
=
data
;
}
}
things/nest-typeorm/src/dto/import-entry.dto.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
export
class
ImportEntryBaseDto
{
@
ApiProperty
({
description
:
'
导入结果
'
})
result
:
string
;
}
export
interface
ImportEntry
<
T
>
{
entry
:
T
;
result
:
string
;
}
things/nest-typeorm/src/entities/User.entity.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
Entity
,
SelectQueryBuilder
,
}
from
'
typeorm
'
;
import
{
ManualNameDescBase
}
from
'
./bases/ManualNameDescBase.entity
'
;
import
{
QueryWise
}
from
'
./interfaces/QueryWise
'
;
@
Entity
()
export
class
User
extends
ManualNameDescBase
implements
QueryWise
<
User
>
{
override
applyQuery
(
qb
:
SelectQueryBuilder
<
User
>
,
entityName
:
string
)
{
super
.
applyQuery
(
qb
,
entityName
);
}
}
things/nest-typeorm/src/entities/bases/AvatarBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/IdBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/IdNameBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/IdNameDescBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/ManualAvatarBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/ManualIdBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/ManualNameBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/ManualNameDescBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
);
}
}
things/nest-typeorm/src/entities/bases/TimeBase.entity.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
,
];
things/nest-typeorm/src/entities/decorators/base.ts
deleted
100644 → 0
View file @
864e6f5c
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
{
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
NotColumn
=
(
description
?:
string
,
swaggerExtras
:
ApiPropertyOptions
=
{},
):
PropertyDecorator
=>
MergePropertyDecorators
([
Exclude
(),
ApiProperty
({
description
,
required
:
false
,
readOnly
:
true
,
...
swaggerExtras
,
}),
]);
things/nest-typeorm/src/entities/decorators/extended.ts
deleted
100644 → 0
View file @
864e6f5c
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
);
things/nest-typeorm/src/entities/decorators/relation.ts
deleted
100644 → 0
View file @
864e6f5c
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
(),
]);
things/nest-typeorm/src/entities/decorators/transform.ts
deleted
100644 → 0
View file @
864e6f5c
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
'
]
});
things/nest-typeorm/src/entities/interfaces/QueryWise.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
SelectQueryBuilder
}
from
'
typeorm
'
;
export
interface
QueryWise
<
T
>
{
applyQuery
(
qb
:
SelectQueryBuilder
<
T
>
,
entityName
:
string
):
void
;
}
things/nest-typeorm/src/entities/interfaces/wises.ts
deleted
100644 → 0
View file @
864e6f5c
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
{}
things/nest-typeorm/src/entities/utility/bigint-transform.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
ValueTransformer
}
from
'
typeorm
'
;
export
class
BigintTransformer
implements
ValueTransformer
{
from
(
dbValue
)
{
if
(
dbValue
==
null
)
{
return
dbValue
;
}
return
parseInt
(
dbValue
);
}
to
(
entValue
):
any
{
return
entValue
;
}
}
things/nest-typeorm/src/entities/utility/query.ts
deleted
100644 → 0
View file @
864e6f5c
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
)[]
)
{
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
)[]
)
{
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
)[]
)
{
for
(
const
field
of
fields
)
{
if
(
obj
[
field
]
==
null
)
{
continue
;
}
qb
.
andWhere
(
`
${
entityName
}
.
${
field
}
like ('%' || :
${
field
}
|| '%')`
,
{
[
field
]:
obj
[
field
],
});
}
}
things/nest-typeorm/src/main.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
NestFactory
}
from
'
@nestjs/core
'
;
import
{
SwaggerModule
,
DocumentBuilder
}
from
'
@nestjs/swagger
'
;
import
{
NestExpressApplication
}
from
'
@nestjs/platform-express
'
;
import
{
AppModule
}
from
'
./app.module
'
;
async
function
bootstrap
()
{
const
app
=
await
NestFactory
.
create
<
NestExpressApplication
>
(
AppModule
);
app
.
enableCors
();
app
.
set
(
'
trust proxy
'
,
[
'
172.16.0.0/12
'
,
'
loopback
'
]);
const
documentConfig
=
new
DocumentBuilder
()
.
setTitle
(
'
app
'
)
.
setDescription
(
'
The app
'
)
.
setVersion
(
'
1.0
'
)
.
build
();
const
document
=
SwaggerModule
.
createDocument
(
app
,
documentConfig
);
SwaggerModule
.
setup
(
'
docs
'
,
app
,
document
);
await
app
.
listen
(
3000
);
}
bootstrap
();
things/nest-typeorm/src/utility/pipes.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
ValidationPipe
}
from
'
@nestjs/common
'
;
import
{
ClassConstructor
,
plainToClass
}
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
plainToClass
(
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
,
});
things/nest-typeorm/test/app.e2e-spec.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
INestApplication
}
from
'
@nestjs/common
'
;
import
*
as
request
from
'
supertest
'
;
import
{
AppModule
}
from
'
./../src/app.module
'
;
describe
(
'
AppController (e2e)
'
,
()
=>
{
let
app
:
INestApplication
;
beforeEach
(
async
()
=>
{
const
moduleFixture
:
TestingModule
=
await
Test
.
createTestingModule
({
imports
:
[
AppModule
],
}).
compile
();
app
=
moduleFixture
.
createNestApplication
();
await
app
.
init
();
});
/* it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
}); */
});
things/nest-typeorm/test/jest-e2e.json
deleted
100644 → 0
View file @
864e6f5c
{
"moduleFileExtensions"
:
[
"js"
,
"json"
,
"ts"
],
"rootDir"
:
"."
,
"testEnvironment"
:
"node"
,
"testRegex"
:
".e2e-spec.ts$"
,
"transform"
:
{
"^.+\\.(t|j)s$"
:
"ts-jest"
}
}
things/nest-typeorm/tsconfig.json
deleted
100644 → 0
View file @
864e6f5c
{
"compilerOptions"
:
{
"module"
:
"commonjs"
,
"declaration"
:
true
,
"removeComments"
:
true
,
"emitDecoratorMetadata"
:
true
,
"experimentalDecorators"
:
true
,
"allowSyntheticDefaultImports"
:
true
,
"target"
:
"es2021"
,
"sourceMap"
:
true
,
"outDir"
:
"./dist"
,
"baseUrl"
:
"./"
,
"incremental"
:
true
,
"esModuleInterop"
:
true
},
"compileOnSave"
:
true
,
"allowJs"
:
true
}
things/nest-typeorm2/Dockerfile
deleted
100644 → 0
View file @
864e6f5c
FROM
node:lts-bullseye-slim as base
LABEL
Author="Nanahira <nanahira@momobako.com>"
RUN
apt update
&&
apt
-y
install
python3 build-essential libpq-dev
&&
rm
-rf
/var/lib/apt/lists/
*
/tmp/
*
/var/tmp/
*
/var/log/
*
WORKDIR
/usr/src/app
COPY
./package*.json ./
FROM
base as builder
RUN
npm ci
&&
npm cache clean
--force
COPY
. ./
RUN
npm run build
FROM
base
ENV
NODE_ENV production
RUN
npm ci
&&
npm cache clean
--force
COPY
--from=builder /usr/src/app/dist ./dist
COPY
./config.example.yaml ./config.yaml
ENV
NODE_PG_FORCE_NATIVE=true
EXPOSE
3000
CMD
[ "npm", "run", "start:prod" ]
things/nest-typeorm2/nest-cli.json
deleted
100644 → 0
View file @
864e6f5c
{
"collection"
:
"@nestjs/schematics"
,
"sourceRoot"
:
"src"
,
"compilerOptions"
:
{
"plugins"
:
[
"@nestjs/swagger"
]
}
}
things/nest-typeorm2/src/app.module.ts
deleted
100644 → 0
View file @
864e6f5c
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
AppController
}
from
'
./app.controller
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
loadConfig
}
from
'
./utility/config
'
;
import
{
TypeOrmModule
}
from
'
@nestjs/typeorm
'
;
@
Module
({
imports
:
[
ConfigModule
.
forRoot
({
load
:
[
loadConfig
],
isGlobal
:
true
,
ignoreEnvVars
:
true
,
ignoreEnvFile
:
true
,
}),
TypeOrmModule
.
forRootAsync
({
inject
:
[
ConfigService
],
useFactory
:
async
(
config
:
ConfigService
)
=>
({
type
:
'
postgres
'
,
entities
:
[],
autoLoadEntities
:
true
,
synchronize
:
!
config
.
get
(
'
DB_NO_INIT
'
),
host
:
config
.
get
(
'
DB_HOST
'
),
port
:
parseInt
(
config
.
get
(
'
DB_PORT
'
))
||
5432
,
username
:
config
.
get
(
'
DB_USER
'
),
password
:
config
.
get
(
'
DB_PASS
'
),
database
:
config
.
get
(
'
DB_NAME
'
),
supportBigNumbers
:
true
,
bigNumberStrings
:
false
,
}),
}),
],
controllers
:
[
AppController
],
providers
:
[
AppService
],
})
export
class
AppModule
{}
things/nest-typeorm2/src/dto/ReturnMessage.dto.ts
deleted
100644 → 0
View file @
864e6f5c
// Blank for nicot use.
things/nest/src/dto/ReturnMessage.dto.ts
View file @
c6213c70
...
@@ -49,7 +49,10 @@ export function ReturnMessageDto<T extends ClassOrArray>(type: T) {
...
@@ -49,7 +49,10 @@ export function ReturnMessageDto<T extends ClassOrArray>(type: T) {
this
.
data
=
data
;
this
.
data
=
data
;
}
}
};
};
ApiProperty
({
description
:
'
Return data.
'
,
type
})(
cl
.
prototype
,
'
data
'
);
ApiProperty
({
description
:
'
Return data.
'
,
type
,
required
:
false
})(
cl
.
prototype
,
'
data
'
,
);
Object
.
defineProperty
(
cl
,
'
name
'
,
{
Object
.
defineProperty
(
cl
,
'
name
'
,
{
value
:
`
${
getClass
(
type
).
name
}
ReturnMessageDto`
,
value
:
`
${
getClass
(
type
).
name
}
ReturnMessageDto`
,
});
});
...
...
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