Browse Source

feat: fix

gemercheung 6 months ago
parent
commit
e858bf7653
1 changed files with 14 additions and 7 deletions
  1. 14 7
      packages/backend/src/modules/web/web.service.ts

+ 14 - 7
packages/backend/src/modules/web/web.service.ts

@@ -71,7 +71,7 @@ export class WebService {
 
   async setArticleCount(id: number) {
     const article = await this.articleRepo.findOne({
-      where: { id },
+      where: { id, enable: true },
     });
     if (!article) {
       return false;
@@ -84,7 +84,7 @@ export class WebService {
 
   async getTopCategory1(id: number) {
     let currentCategory = await this.categoryRepo.findOne({
-      where: { id },
+      where: { id, enable: true },
       relations: { parent: true },
     });
 
@@ -101,7 +101,7 @@ export class WebService {
     console.log('currentCategory', currentCategory);
     return currentCategory.id
       ? this.categoryRepo.findOne({
-        where: { id: currentCategory.id },
+        where: { id: currentCategory.id, enable: true },
         relations: { children: true },
       })
       : null;
@@ -111,6 +111,7 @@ export class WebService {
     const lang = this.sharedService.handleValidLang(locale);
 
     const categories = await this.categoryRepo.find({
+      where: { enable: true },
       relations: { children: true, translations: true },
     });
     const data = this.sharedService.handleTree(categories.map((cate) => cate.translate(lang)));
@@ -122,6 +123,9 @@ export class WebService {
     const articles = await this.articleRepo.find({
       where: [
         {
+          enable: true,
+        },
+        {
           translations: {
             locale: lang,
             title: Like(`%${key || ''}%`),
@@ -143,7 +147,7 @@ export class WebService {
     const childIds: number[] = [];
     // 递归查找所有子菜单的 id
     const findChildren = async (id: number) => {
-      const children = await this.categoryRepo.find({ where: { parentId: id } });
+      const children = await this.categoryRepo.find({ where: { parentId: id, enable: true } });
       for (const child of children) {
         childIds.push(child.id);
         await findChildren(child.id); // 递归查找子菜单的子菜单
@@ -167,6 +171,7 @@ export class WebService {
     const articles = await this.articleRepo.find({
       where: {
         categoryId: id,
+        enable: true,
       },
       relations: { translations: true },
     });
@@ -174,20 +179,22 @@ export class WebService {
   }
   async getNearArticle(currentId: number, locale?: string) {
     const lang = this.sharedService.handleValidLang(locale);
-    const currentEntity = await this.articleRepo.findOne({ where: { id: currentId } });
+    const currentEntity = await this.articleRepo.findOne({
+      where: { id: currentId, enable: true },
+    });
     if (!currentEntity) {
       // throw new CustomException(ErrorCode.ERR_4000, '当前数据不存在');
       return [];
     }
 
     const prevEntity = await this.articleRepo.findOne({
-      where: { id: LessThan(currentId), categoryId: currentEntity.categoryId },
+      where: { id: LessThan(currentId), categoryId: currentEntity.categoryId, enable: true },
       order: { id: 'DESC' },
       relations: { translations: true },
     });
 
     const nextEntity = await this.articleRepo.findOne({
-      where: { id: MoreThan(currentId), categoryId: currentEntity.categoryId },
+      where: { id: MoreThan(currentId), categoryId: currentEntity.categoryId, enable: true },
       order: { id: 'ASC' },
       relations: { translations: true },
     });