Browse Source

feat: save delete with article

gemercheung 8 months ago
parent
commit
e235ceebac

+ 0 - 8
packages/backend/src/common/guards/jwt.guard.ts

@@ -1,11 +1,3 @@
-/**********************************
- * @Author: Ronnie Zhang
- * @LastEditor: Ronnie Zhang
- * @LastEditTime: 2023/12/07 20:24:51
- * @Email: zclzone@outlook.com
- * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
- **********************************/
-
 import { AuthGuard } from '@nestjs/passport';
 
 export class JwtGuard extends AuthGuard('jwt') {

+ 0 - 8
packages/backend/src/common/guards/local.guard.ts

@@ -1,11 +1,3 @@
-/**********************************
- * @Author: Ronnie Zhang
- * @LastEditor: Ronnie Zhang
- * @LastEditTime: 2023/12/07 20:24:58
- * @Email: zclzone@outlook.com
- * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
- **********************************/
-
 import { AuthGuard } from '@nestjs/passport';
 
 export class LocalGuard extends AuthGuard('local') {

+ 0 - 8
packages/backend/src/common/guards/permission.guard.ts

@@ -1,11 +1,3 @@
-/**********************************
- * @Author: Ronnie Zhang
- * @LastEditor: Ronnie Zhang
- * @LastEditTime: 2023/12/07 20:25:04
- * @Email: zclzone@outlook.com
- * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
- **********************************/
-
 import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
 import { Reflector } from '@nestjs/core';
 import { CustomException, ErrorCode } from '@/common/exceptions/custom.exception';

+ 0 - 8
packages/backend/src/common/guards/preview.guard.ts

@@ -1,11 +1,3 @@
-/**********************************
- * @Author: Ronnie Zhang
- * @LastEditor: Ronnie Zhang
- * @LastEditTime: 2023/12/07 20:25:11
- * @Email: zclzone@outlook.com
- * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
- **********************************/
-
 import { CanActivate, Injectable } from '@nestjs/common';
 import { CustomException, ErrorCode } from '@/common/exceptions/custom.exception';
 import { ConfigService } from '@nestjs/config';

+ 1 - 1
packages/backend/src/common/middleware/session.middleware.ts

@@ -8,7 +8,7 @@ import { RedisService } from '@/shared/redis.service';
 
 @Injectable()
 export class SessionMiddleware implements NestMiddleware {
-  constructor(@Inject(RedisService) private readonly redisService: RedisService) { }
+  constructor(@Inject(RedisService) private readonly redisService: RedisService) {}
 
   use(req: Request, res: Response, next: NextFunction) {
     return session({

+ 1 - 1
packages/backend/src/common/utils/treeUtil.ts

@@ -40,4 +40,4 @@ export function getTopMenuFragment(tree: TreeNode[], targetId: number): TreeNode
 
   // 如果整个树中都没有找到目标节点,返回 null
   return null;
-}
+}

+ 1 - 1
packages/backend/src/modules/article/article.entity.translation.ts

@@ -11,7 +11,7 @@ export class ArticleTranslation extends TranslationEntity<Article> {
   content?: string;
 
   @ManyToOne(() => Article, (article) => article.translations, {
-    onDelete: 'CASCADE',
+    // onDelete: 'CASCADE',
     createForeignKeyConstraints: false,
   })
   source?: Article | undefined;

+ 1 - 2
packages/backend/src/modules/article/article.entity.ts

@@ -69,8 +69,7 @@ export class Article extends TranslatableEntity<ArticleTranslation> {
   updateTime: Date;
 
   @OneToMany(() => ArticleTranslation, (articleTranslation) => articleTranslation.source, {
-    cascade: true,
-    onDelete: 'CASCADE',
+    cascade: ['insert', 'update', 'remove'],
   })
   translations?: Translation<ArticleTranslation>[] | undefined;
 

+ 10 - 1
packages/backend/src/modules/article/article.service.ts

@@ -61,7 +61,16 @@ export class ArticleService {
   }
 
   async remove(id: number) {
-    await this.articleRepo.delete(id);
+    const article = await this.articleRepo.findOne({
+      where: { id },
+      relations: {
+        translations: true,
+      },
+    });
+    article.translations.forEach(async (trans) => {
+      await this.articleTranslationRepo.delete(trans.id);
+    });
+    await this.articleRepo.remove(article);
     return true;
   }
 

+ 0 - 2
packages/backend/src/modules/auth/auth.service.ts

@@ -1,5 +1,3 @@
-
-
 import { Injectable } from '@nestjs/common';
 import { JwtService } from '@nestjs/jwt';
 import { compareSync } from 'bcryptjs';

+ 0 - 1
packages/backend/src/modules/auth/dto.ts

@@ -1,4 +1,3 @@
-
 import { ApiProperty } from '@nestjs/swagger';
 import { IsBoolean, IsNotEmpty, IsOptional, IsString, Length } from 'class-validator';
 

+ 0 - 1
packages/backend/src/modules/auth/jwt.strategy.ts

@@ -1,4 +1,3 @@
-
 import { CustomException, ErrorCode } from '@/common/exceptions/custom.exception';
 import { ACCESS_TOKEN_EXPIRATION_TIME, USER_ACCESS_TOKEN_KEY } from '@/constants/redis.contant';
 import { RedisService } from '@/shared/redis.service';

+ 0 - 2
packages/backend/src/modules/auth/local.strategy.ts

@@ -1,5 +1,3 @@
-
-
 import { Injectable } from '@nestjs/common';
 import { PassportStrategy } from '@nestjs/passport';
 import { Strategy } from 'passport-local';

+ 1 - 1
packages/backend/src/modules/menu/menu.module.ts

@@ -9,4 +9,4 @@ import { TypeOrmModule } from '@nestjs/typeorm';
   controllers: [MenuController],
   providers: [MenuService],
 })
-export class MenuModule { }
+export class MenuModule {}

+ 0 - 1
packages/backend/src/modules/role/role.service.ts

@@ -1,4 +1,3 @@
-
 import { BadRequestException, Injectable } from '@nestjs/common';
 import {
   AddRolePermissionsDto,

+ 1 - 6
packages/backend/src/modules/web/dto/query-web.dto.ts

@@ -1,6 +1 @@
-
-export class QueryPublicCategoryDto {
-
-
-
-}
+export class QueryPublicCategoryDto {}

+ 0 - 1
packages/backend/src/modules/web/web.module.ts

@@ -6,7 +6,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
 import { Menu } from '@/modules/menu/menu.entity';
 import { Article } from '@/modules/article/article.entity';
 
-
 @Module({
   imports: [TypeOrmModule.forFeature([Menu, Category, Article])],
   controllers: [WebController],