-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
powerfulyang
committed
Dec 5, 2023
1 parent
d5321c0
commit 5fe6118
Showing
11 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Type } from '@nestjs/common'; | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger'; | ||
|
||
export const ApiOkPaginateQueryResponse = <T extends Type>(options: { | ||
model: T; | ||
description?: string; | ||
}) => { | ||
const { model, description } = options; | ||
const ref = { $ref: getSchemaPath(model) }; | ||
return applyDecorators( | ||
ApiExtraModels(model), | ||
ApiOkResponse({ | ||
description, | ||
schema: { | ||
type: 'array', | ||
items: { | ||
oneOf: [ | ||
{ | ||
type: 'array', | ||
items: ref, | ||
}, | ||
{ | ||
type: 'number', | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { PaginatedBaseQuery } from '@/common/decorator/pagination/PaginationQuery'; | ||
import { RequestLog } from '@/request-log/entities/request-log.entity'; | ||
import { ApiProperty, IntersectionType, OmitType } from '@nestjs/swagger'; | ||
|
||
export class QueryRequestLogDto extends IntersectionType( | ||
PaginatedBaseQuery, | ||
OmitType(RequestLog, ['createdAt', 'updatedAt']), | ||
) { | ||
@ApiProperty({ | ||
description: '创建时间', | ||
type: [Date, Date], | ||
}) | ||
createdAt: [Date, Date]; | ||
|
||
@ApiProperty({ | ||
description: '更新时间', | ||
type: [Date, Date], | ||
}) | ||
updatedAt: [Date, Date]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { AdminAuthGuard } from '@/common/decorator/auth-guard.decorator'; | ||
import { BodyPagination } from '@/common/decorator/pagination/pagination.decorator'; | ||
import { LoggerService } from '@/common/logger/logger.service'; | ||
import { ApiOkPaginateQueryResponse } from '@/common/swagger/ApiOkPaginateQueryResponse'; | ||
import { QueryRequestLogDto } from '@/request-log/dto/query-request-log.dto'; | ||
import { RequestLog } from '@/request-log/entities/request-log.entity'; | ||
import { RequestLogService } from '@/request-log/request-log.service'; | ||
import { Controller, Post } from '@nestjs/common'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
|
||
@Controller('request-log-manage') | ||
@ApiTags('request-log-manage') | ||
@AdminAuthGuard() | ||
export class RequestLogController { | ||
constructor( | ||
private readonly logger: LoggerService, | ||
private readonly requestLogService: RequestLogService, | ||
) { | ||
this.logger.setContext(RequestLogController.name); | ||
} | ||
|
||
@Post('query-logs') | ||
@ApiOperation({ | ||
summary: '分页查询请求日志', | ||
operationId: 'queryLogs', | ||
}) | ||
@ApiOkPaginateQueryResponse({ | ||
model: RequestLog, | ||
description: '分页查询请求日志响应', | ||
}) | ||
queryLogs(@BodyPagination() paginateQueryRequestLogDto: QueryRequestLogDto) { | ||
return this.requestLogService.queryLogs(paginateQueryRequestLogDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters