Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
cxcy-scoresheet
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
MathWeb
cxcy-scoresheet
Commits
cde328f6
Commit
cde328f6
authored
May 21, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some desc
parent
7a749a58
Pipeline
#3298
canceled with stages
in 11 minutes and 11 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
15 deletions
+51
-15
nest-cli.json
nest-cli.json
+4
-1
src/app.controller.ts
src/app.controller.ts
+22
-10
src/main.ts
src/main.ts
+1
-0
src/messages/CxcyReturnMessage.ts
src/messages/CxcyReturnMessage.ts
+24
-4
No files found.
nest-cli.json
View file @
cde328f6
{
{
"collection"
:
"@nestjs/schematics"
,
"collection"
:
"@nestjs/schematics"
,
"sourceRoot"
:
"src"
"sourceRoot"
:
"src"
,
"compilerOptions"
:
{
"plugins"
:
[
"@nestjs/swagger"
]
}
}
}
src/app.controller.ts
View file @
cde328f6
...
@@ -19,6 +19,7 @@ import {
...
@@ -19,6 +19,7 @@ import {
ApiInternalServerErrorResponse
,
ApiInternalServerErrorResponse
,
ApiOkResponse
,
ApiOkResponse
,
ApiQuery
,
ApiQuery
,
ApiTags
,
}
from
'
@nestjs/swagger
'
;
}
from
'
@nestjs/swagger
'
;
@
Controller
(
'
api
'
)
@
Controller
(
'
api
'
)
...
@@ -26,11 +27,18 @@ export class AppController {
...
@@ -26,11 +27,18 @@ export class AppController {
constructor
(
private
readonly
appService
:
AppService
)
{}
constructor
(
private
readonly
appService
:
AppService
)
{}
@
Get
(
'
user/report.pdf
'
)
@
Get
(
'
user/report.pdf
'
)
@
ApiTags
(
'
user
'
)
@
ApiHeader
({
name
:
'
Authorization
'
,
description
:
'
用户 token
'
})
@
ApiHeader
({
name
:
'
Authorization
'
,
description
:
'
用户 token
'
})
@
ApiQuery
({
name
:
'
request_id
'
,
description
:
'
请求 id,直接返回。
'
})
@
ApiQuery
({
name
:
'
request_id
'
,
description
:
'
请求 id,直接返回。
'
})
@
ApiOkResponse
({
description
:
'
成功,会直接提供文件下载。
'
})
@
ApiOkResponse
({
description
:
'
成功,会直接提供文件下载。
'
})
@
ApiBadRequestResponse
({
description
:
'
用户不存在或者没有登录。
'
})
@
ApiBadRequestResponse
({
@
ApiInternalServerErrorResponse
({
description
:
'
报告生成过程中出现问题。
'
})
description
:
'
用户不存在或者没有登录。
'
,
type
:
CxcyReturnMessage
,
})
@
ApiInternalServerErrorResponse
({
description
:
'
报告生成过程中出现问题。
'
,
type
:
CxcyReturnMessage
,
})
async
getPdf
(
async
getPdf
(
@
Headers
(
'
Authorization
'
)
userToken
:
string
,
@
Headers
(
'
Authorization
'
)
userToken
:
string
,
@
Query
(
'
request_id
'
)
requestId
:
string
,
@
Query
(
'
request_id
'
)
requestId
:
string
,
...
@@ -38,9 +46,12 @@ export class AppController {
...
@@ -38,9 +46,12 @@ export class AppController {
res
:
Response
,
res
:
Response
,
)
{
)
{
if
(
!
userToken
)
{
if
(
!
userToken
)
{
res
new
CxcyReturnMessage
(
.
status
(
401
)
requestId
,
.
json
(
new
CxcyReturnMessage
(
requestId
,
401
,
'
Empty user token.
'
,
null
));
401
,
'
Empty user token.
'
,
null
,
).
writeResponse
(
res
);
return
;
return
;
}
}
const
data
:
CxcyReturnMessageLike
<
any
>
=
await
this
.
appService
.
getUserData
(
const
data
:
CxcyReturnMessageLike
<
any
>
=
await
this
.
appService
.
getUserData
(
...
@@ -52,11 +63,12 @@ export class AppController {
...
@@ -52,11 +63,12 @@ export class AppController {
return
;
return
;
}
}
if
(
!
data
.
data
||
!
data
.
data
.
user
)
{
if
(
!
data
.
data
||
!
data
.
data
.
user
)
{
res
new
CxcyReturnMessage
(
.
status
(
500
)
requestId
,
.
json
(
401
,
new
CxcyReturnMessage
(
requestId
,
401
,
'
Some contents missing.
'
,
null
),
'
Some contents missing.
'
,
);
null
,
).
writeResponse
(
res
);
return
;
return
;
}
}
const
userData
=
data
.
data
.
user
;
const
userData
=
data
.
data
.
user
;
...
...
src/main.ts
View file @
cde328f6
...
@@ -10,6 +10,7 @@ async function bootstrap() {
...
@@ -10,6 +10,7 @@ async function bootstrap() {
.
setTitle
(
'
cxcy-scoresheet
'
)
.
setTitle
(
'
cxcy-scoresheet
'
)
.
setDescription
(
'
创新创业报告生成模块
'
)
.
setDescription
(
'
创新创业报告生成模块
'
)
.
setVersion
(
'
1.0
'
)
.
setVersion
(
'
1.0
'
)
.
addTag
(
'
user
'
,
'
用户接口
'
)
.
build
();
.
build
();
const
document
=
SwaggerModule
.
createDocument
(
app
,
documentConfig
);
const
document
=
SwaggerModule
.
createDocument
(
app
,
documentConfig
);
...
...
src/messages/CxcyReturnMessage.ts
View file @
cde328f6
import
moment
from
'
moment
'
;
import
moment
from
'
moment
'
;
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
Response
}
from
'
express
'
;
export
interface
CxcyReturnMessageLike
<
T
>
{
export
interface
CxcyReturnMessageLike
<
T
>
{
success
:
boolean
;
success
:
boolean
;
...
@@ -10,15 +12,33 @@ export interface CxcyReturnMessageLike<T> {
...
@@ -10,15 +12,33 @@ export interface CxcyReturnMessageLike<T> {
}
}
export
class
CxcyReturnMessage
<
T
>
implements
CxcyReturnMessageLike
<
T
>
{
export
class
CxcyReturnMessage
<
T
>
implements
CxcyReturnMessageLike
<
T
>
{
@
ApiProperty
({
description
:
'
是否成功
'
})
success
:
boolean
;
success
:
boolean
;
@
ApiProperty
({
description
:
'
请求日期
'
})
timestamp
:
number
;
timestamp
:
number
;
@
ApiProperty
({
description
:
'
请求中的请求 ID。
'
})
public
request_id
:
string
;
@
ApiProperty
({
description
:
'
状态码
'
})
public
status_code
:
number
;
@
ApiProperty
({
description
:
'
提示信息
'
})
public
message
:
string
;
@
ApiProperty
({
description
:
'
返回内容
'
})
public
data
:
T
;
constructor
(
constructor
(
public
request_id
:
string
,
request_id
:
string
,
public
status_code
:
number
,
status_code
:
number
,
public
message
:
string
,
message
:
string
,
public
data
:
T
,
data
:
T
,
)
{
)
{
this
.
request_id
=
request_id
;
this
.
status_code
=
status_code
;
this
.
message
=
message
;
this
.
data
=
data
;
this
.
success
=
status_code
<
400
;
this
.
success
=
status_code
<
400
;
this
.
timestamp
=
moment
().
unix
();
this
.
timestamp
=
moment
().
unix
();
}
}
writeResponse
(
res
:
Response
)
{
res
.
status
(
this
.
status_code
).
json
(
this
);
}
}
}
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