diff --git a/packages/canyon-backend/.eslintrc.js b/packages/canyon-backend/.eslintrc.js index 9ade1ea0..791ca93b 100755 --- a/packages/canyon-backend/.eslintrc.js +++ b/packages/canyon-backend/.eslintrc.js @@ -1,25 +1,25 @@ module.exports = { - parser: "@typescript-eslint/parser", - parserOptions: { - project: "tsconfig.json", - tsconfigRootDir: __dirname, - sourceType: "module", - }, - plugins: ["@typescript-eslint/eslint-plugin"], - extends: [ - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - ], - root: true, - env: { - node: true, - jest: true, - }, - ignorePatterns: [".eslintrc.js"], - rules: { - "@typescript-eslint/interface-name-prefix": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-explicit-any": "off", - }, + parser: "@typescript-eslint/parser", + parserOptions: { + project: "tsconfig.json", + tsconfigRootDir: __dirname, + sourceType: "module", + }, + plugins: ["@typescript-eslint/eslint-plugin"], + extends: [ + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended", + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: [".eslintrc.js"], + rules: { + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-explicit-any": "off", + }, }; diff --git a/packages/canyon-backend/src/app.module.ts b/packages/canyon-backend/src/app.module.ts index 7faf5d7f..5fabb278 100755 --- a/packages/canyon-backend/src/app.module.ts +++ b/packages/canyon-backend/src/app.module.ts @@ -13,7 +13,6 @@ import { SourcecodeService } from "./sourcecode/sourcecode.service"; import { SourcecodeModule } from "./sourcecode/sourcecode.module"; import { join } from "path"; import { ServeStaticModule } from "@nestjs/serve-static"; -import { PlaygroundModule } from "./playground/playground.module"; import { CoverageModule } from "./cov/coverage.module"; @Module({ @@ -26,7 +25,6 @@ import { CoverageModule } from "./cov/coverage.module"; CoverageModule, CodechangeModule, SourcecodeModule, - PlaygroundModule, PrismaModule, ServeStaticModule.forRoot({ rootPath: join(__dirname, "../../canyon-platform", "dist"), diff --git a/packages/canyon-backend/src/filter/global-exception.filter.ts b/packages/canyon-backend/src/filter/global-exception.filter.ts deleted file mode 100644 index ba12a888..00000000 --- a/packages/canyon-backend/src/filter/global-exception.filter.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - ExceptionFilter, - Catch, - ArgumentsHost, - HttpException, -} from "@nestjs/common"; -import { Request, Response } from "express"; -import { logger } from "../logger"; - -@Catch() -export class GlobalExceptionFilter implements ExceptionFilter { - catch(exception: unknown, host: ArgumentsHost) { - const ctx = host.switchToHttp(); - const request = ctx.getRequest(); - const response = ctx.getResponse(); - const status = - exception instanceof HttpException ? exception.getStatus() : 500; - // 1.在控制台打印错误,便于调试 - console.error(exception); - - // 2.记录日志 - logger({ - type: "error", - title: String(exception), - message: `exception:${String( - exception instanceof HttpException - ? exception.getResponse() - : "Internal server error", - )}|url:${request.url}`, - }); - - response.status(status).json({ - statusCode: status, - timestamp: new Date().toISOString(), - path: request.url, - message: - exception instanceof HttpException - ? JSON.stringify(exception.getResponse()) - : "Internal server error", - }); - } -} diff --git a/packages/canyon-backend/src/playground/playground.controller.ts b/packages/canyon-backend/src/playground/playground.controller.ts deleted file mode 100755 index 5f4b74a8..00000000 --- a/packages/canyon-backend/src/playground/playground.controller.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Controller } from "@nestjs/common"; -import { PrismaService } from "../prisma/prisma.service"; - -@Controller() -export class PlaygroundController { - constructor(private readonly prismaService: PrismaService) { - console.log("PlaygroundController created"); - } -} diff --git a/packages/canyon-backend/src/playground/playground.module.ts b/packages/canyon-backend/src/playground/playground.module.ts deleted file mode 100755 index 586ed349..00000000 --- a/packages/canyon-backend/src/playground/playground.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from "@nestjs/common"; -import { PlaygroundService } from "./playground.service"; -import { PrismaModule } from "src/prisma/prisma.module"; -import { PlaygroundController } from "./playground.controller"; - -@Module({ - imports: [PrismaModule], - controllers: [PlaygroundController], - providers: [PlaygroundService], - exports: [PlaygroundService], -}) -export class PlaygroundModule {} diff --git a/packages/canyon-backend/src/playground/playground.service.ts b/packages/canyon-backend/src/playground/playground.service.ts deleted file mode 100755 index a4d48a6e..00000000 --- a/packages/canyon-backend/src/playground/playground.service.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Injectable } from "@nestjs/common"; -import { PrismaService } from "src/prisma/prisma.service"; -@Injectable() -export class PlaygroundService { - constructor(private prisma: PrismaService) {} -} diff --git a/packages/canyon-backend/src/role/enums/role.enum.ts b/packages/canyon-backend/src/role/enums/role.enum.ts deleted file mode 100755 index 454d14a3..00000000 --- a/packages/canyon-backend/src/role/enums/role.enum.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum Role { - User = "user", - Admin = "admin", -} diff --git a/packages/canyon-backend/src/role/guard/roles.guard.ts b/packages/canyon-backend/src/role/guard/roles.guard.ts deleted file mode 100755 index 473917b9..00000000 --- a/packages/canyon-backend/src/role/guard/roles.guard.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { CanActivate, ExecutionContext, Injectable } from "@nestjs/common"; -import { Reflector } from "@nestjs/core"; -import { Role } from "../enums/role.enum"; -import { ROLES_KEY } from "../roles.decorator"; - -@Injectable() -export class RolesGuard implements CanActivate { - constructor(private reflector: Reflector) {} - - canActivate(context: ExecutionContext): boolean { - const requiredRoles = this.reflector.getAllAndOverride( - ROLES_KEY, - [context.getHandler(), context.getClass()], - ); - if (!requiredRoles) { - return true; - } - const getRequest = context.switchToHttp().getRequest(); - return requiredRoles.some((role) => - getRequest.user.roles?.includes(role), - ); - } -} diff --git a/packages/canyon-backend/src/role/roles.decorator.ts b/packages/canyon-backend/src/role/roles.decorator.ts deleted file mode 100755 index 457ae101..00000000 --- a/packages/canyon-backend/src/role/roles.decorator.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { SetMetadata } from "@nestjs/common"; -import { Role } from "./enums/role.enum"; - -export const ROLES_KEY = "roles"; -export const Roles = (...roles: Role[]) => SetMetadata(ROLES_KEY, roles);