Skip to content
Merged

Djh #26

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ArticleService {
articleAuthor,
startTime,
endTime,
showAll = false, // 默认只显示激活的文章
isActive,
} = query;
const skip = (page - 1) * limit;

Expand Down Expand Up @@ -97,12 +97,17 @@ export class ArticleService {
);
}

// 如果不是显示所有,只显示激活的文章
if (!showAll) {
queryBuilder.andWhere('article.isActive = :isActive', { isActive: true })
.andWhere('(article.startTime IS NULL OR article.startTime <= :now)')
.andWhere('(article.endTime IS NULL OR article.endTime >= :now)')
.setParameter('now', new Date());
// 根据激活状态过滤
if (isActive !== undefined) {
queryBuilder.andWhere('article.isActive = :isActive', { isActive });

// 如果是查询激活的文章,还需要检查时间范围
if (isActive === true) {
queryBuilder
.andWhere('(article.startTime IS NULL OR article.startTime <= :now)')
.andWhere('(article.endTime IS NULL OR article.endTime >= :now)')
.setParameter('now', new Date());
}
}

// 执行查询并获取结果
Expand Down
4 changes: 2 additions & 2 deletions src/article/dto/query-article.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class QueryArticleDto {
* 只有管理员可以设置为true
*/
@IsOptional()
@IsBoolean({ message: '显示所有文章必须是布尔值' })
@IsBoolean({ message: '文章状态必须是布尔值' })
@Type(() => Boolean)
showAll?: boolean = false;
isActive?: boolean;
}
Loading