fix: remove post model hide field
This commit is contained in:
2
.npmrc
2
.npmrc
@@ -1,3 +1,5 @@
|
||||
public-hoist-pattern[]=*fastify*
|
||||
public-hoist-pattern[]=mongodb
|
||||
public-hoist-pattern[]=*eslint*
|
||||
|
||||
registry=https://registry.npmjs.org
|
||||
@@ -20,7 +20,6 @@ import { ApiName } from '~/common/decorator/openapi.decorator'
|
||||
import { IsMaster } from '~/common/decorator/role.decorator'
|
||||
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import { addConditionToSeeHideContent } from '~/utils/query.util'
|
||||
import { PostService } from '../post/post.service'
|
||||
import {
|
||||
MultiCategoriesQueryDto,
|
||||
@@ -57,10 +56,7 @@ export class CategoryController {
|
||||
await Promise.all(
|
||||
ids.map(async (id) => {
|
||||
const item = await this.postService.model
|
||||
.find(
|
||||
{ categoryId: id, ...addConditionToSeeHideContent(isMaster) },
|
||||
ignoreKeys,
|
||||
)
|
||||
.find({ categoryId: id }, ignoreKeys)
|
||||
.sort({ created: -1 })
|
||||
.lean()
|
||||
|
||||
@@ -76,10 +72,7 @@ export class CategoryController {
|
||||
await Promise.all(
|
||||
ids.map(async (id) => {
|
||||
const posts = await this.postService.model
|
||||
.find(
|
||||
{ categoryId: id, ...addConditionToSeeHideContent(isMaster) },
|
||||
ignoreKeys,
|
||||
)
|
||||
.find({ categoryId: id }, ignoreKeys)
|
||||
.sort({ created: -1 })
|
||||
.lean()
|
||||
const category = await this.categoryService.findCategoryById(id)
|
||||
@@ -114,10 +107,7 @@ export class CategoryController {
|
||||
if (tag === true) {
|
||||
return {
|
||||
tag: query,
|
||||
data: await this.categoryService.findArticleWithTag(
|
||||
query,
|
||||
addConditionToSeeHideContent(isMaster),
|
||||
),
|
||||
data: await this.categoryService.findArticleWithTag(query),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,10 +128,7 @@ export class CategoryController {
|
||||
|
||||
const children =
|
||||
(await this.categoryService.findCategoryPost(res._id, {
|
||||
$and: [
|
||||
tag ? { tags: tag } : {},
|
||||
addConditionToSeeHideContent(isMaster),
|
||||
],
|
||||
$and: [tag ? { tags: tag } : {}],
|
||||
})) || []
|
||||
return { data: { ...res, children } }
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@ import { VisitDocument } from '~/common/decorator/update-count.decorator'
|
||||
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
|
||||
import { CountingService } from '~/processors/helper/helper.counting.service'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import {
|
||||
addConditionToSeeHideContent,
|
||||
addYearCondition,
|
||||
} from '~/utils/query.util'
|
||||
import { addYearCondition } from '~/utils/query.util'
|
||||
import { CategoryAndSlugDto, PostQueryDto } from './post.dto'
|
||||
import { PartialPostModel, PostModel } from './post.model'
|
||||
import { PostService } from './post.service'
|
||||
@@ -47,7 +44,6 @@ export class PostController {
|
||||
return await this.postService.findWithPaginator(
|
||||
{
|
||||
...addYearCondition(year),
|
||||
...addConditionToSeeHideContent(master),
|
||||
},
|
||||
{
|
||||
limit: size,
|
||||
@@ -60,10 +56,10 @@ export class PostController {
|
||||
|
||||
@Get('/:id')
|
||||
@VisitDocument('Post')
|
||||
async getById(@Param() params: MongoIdDto, @IsMaster() isMaster: boolean) {
|
||||
async getById(@Param() params: MongoIdDto) {
|
||||
const { id } = params
|
||||
const doc = await this.postService.model.findById(id)
|
||||
if (!doc || (doc.hide && !isMaster)) {
|
||||
if (!doc) {
|
||||
throw new CannotFindException()
|
||||
}
|
||||
return doc
|
||||
@@ -71,20 +67,14 @@ export class PostController {
|
||||
|
||||
@Get('/latest')
|
||||
@VisitDocument('Post')
|
||||
async getLatest(@IsMaster() isMaster: boolean) {
|
||||
return this.postService.model
|
||||
.findOne({ ...addConditionToSeeHideContent(isMaster) })
|
||||
.sort({ created: -1 })
|
||||
.lean()
|
||||
async getLatest() {
|
||||
return this.postService.model.findOne({}).sort({ created: -1 }).lean()
|
||||
}
|
||||
|
||||
@Get('/:category/:slug')
|
||||
@ApiOperation({ summary: '根据分类名和自定义别名获取' })
|
||||
@VisitDocument('Post')
|
||||
async getByCateAndSlug(
|
||||
@Param() params: CategoryAndSlugDto,
|
||||
@IsMaster() isMaster: boolean,
|
||||
) {
|
||||
async getByCateAndSlug(@Param() params: CategoryAndSlugDto) {
|
||||
const { category, slug } = params
|
||||
|
||||
const categoryDocument = await this.postService.getCategoryBySlug(category)
|
||||
@@ -100,7 +90,7 @@ export class PostController {
|
||||
})
|
||||
.populate('category')
|
||||
|
||||
if (!postDocument || (postDocument.hide && !isMaster)) {
|
||||
if (!postDocument) {
|
||||
throw new CannotFindException()
|
||||
}
|
||||
return postDocument.toJSON()
|
||||
|
||||
@@ -68,11 +68,6 @@ export class PostModel extends WriteBaseModel {
|
||||
@ApiHideProperty()
|
||||
public category: Ref<Category>
|
||||
|
||||
@prop({ default: false })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
hide?: boolean
|
||||
|
||||
@prop({ default: true })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
|
||||
@@ -26,7 +26,7 @@ export class SearchController {
|
||||
type = type.toLowerCase()
|
||||
switch (type) {
|
||||
case 'post': {
|
||||
return this.searchService.searchPost(query, isMaster)
|
||||
return this.searchService.searchPost(query)
|
||||
}
|
||||
case 'note':
|
||||
return this.searchService.searchNote(query, isMaster)
|
||||
|
||||
@@ -9,7 +9,6 @@ import algoliasearch from 'algoliasearch'
|
||||
import { SearchDto } from '~/modules/search/search.dto'
|
||||
import { DatabaseService } from '~/processors/database/database.service'
|
||||
import { Pagination } from '~/shared/interface/paginator.interface'
|
||||
import { addConditionToSeeHideContent } from '~/utils/query.util'
|
||||
import { transformDataToPaginate } from '~/utils/transfrom.util'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { NoteService } from '../note/note.service'
|
||||
@@ -60,7 +59,7 @@ export class SearchService {
|
||||
)
|
||||
}
|
||||
|
||||
async searchPost(searchOption: SearchDto, showHidden: boolean) {
|
||||
async searchPost(searchOption: SearchDto) {
|
||||
const { keyword, page, size } = searchOption
|
||||
const select = '_id title created modified categoryId slug'
|
||||
const keywordArr = keyword
|
||||
@@ -70,7 +69,6 @@ export class SearchService {
|
||||
await this.postService.findWithPaginator(
|
||||
{
|
||||
$or: [{ title: { $in: keywordArr } }, { text: { $in: keywordArr } }],
|
||||
$and: [{ ...addConditionToSeeHideContent(showHidden) }],
|
||||
},
|
||||
{
|
||||
limit: size,
|
||||
|
||||
Reference in New Issue
Block a user