fix(classes): 修复依赖注入与 ESM 导入路径
- classes.module.ts: 移除 useFactory,改用直接 provider 注册 - classes.service.ts: 添加 @Inject 装饰器显式注入 Repository - health.module.ts: 修复 import 添加 .js 后缀(ESM 模式) - package.json: 补充 ioredis/kafkajs/typeform 等运行时依赖
This commit is contained in:
@@ -17,19 +17,22 @@
|
||||
"@nestjs/common": "^10.4.0",
|
||||
"@nestjs/core": "^10.4.0",
|
||||
"@nestjs/platform-express": "^10.4.0",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.50.0",
|
||||
"@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
|
||||
"@opentelemetry/sdk-node": "^0.53.0",
|
||||
"drizzle-orm": "^0.31.0",
|
||||
"ioredis": "^5.11.1",
|
||||
"kafkajs": "^2.2.0",
|
||||
"mysql2": "^3.11.0",
|
||||
"pino": "^9.4.0",
|
||||
"pino-http": "^10.0.0",
|
||||
"prom-client": "^15.1.0",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@opentelemetry/sdk-node": "^0.53.0",
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.50.0",
|
||||
"@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
|
||||
"zod": "^3.23.0",
|
||||
"uuid": "^10.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.0"
|
||||
"rxjs": "^7.8.0",
|
||||
"typeorm": "^1.0.0",
|
||||
"uuid": "^10.0.0",
|
||||
"zod": "^3.23.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.4.0",
|
||||
@@ -41,8 +44,8 @@
|
||||
"drizzle-kit": "^0.24.0",
|
||||
"eslint": "^9.10.0",
|
||||
"pino-pretty": "^11.2.0",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.6.0",
|
||||
"vitest": "^2.1.0",
|
||||
"tsx": "^4.19.0"
|
||||
"vitest": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ClassesController } from './classes.controller.js';
|
||||
import { ClassesService } from './classes.service.js';
|
||||
import { ClassesRepository } from './classes.repository.js';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { ClassesController } from "./classes.controller.js";
|
||||
import { ClassesService } from "./classes.service.js";
|
||||
import { ClassesRepository } from "./classes.repository.js";
|
||||
|
||||
@Module({
|
||||
controllers: [ClassesController],
|
||||
providers: [
|
||||
ClassesService,
|
||||
{
|
||||
provide: ClassesRepository,
|
||||
useFactory: () => new ClassesRepository(),
|
||||
},
|
||||
],
|
||||
providers: [ClassesService, ClassesRepository],
|
||||
})
|
||||
export class ClassesModule {}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { ClassesRepository } from './classes.repository.js';
|
||||
import { ValidationError, NotFoundError } from '../shared/errors/application-error.js';
|
||||
import type { CreateClassDto, UpdateClassDto } from './classes.dto.js';
|
||||
import type { Class, NewClass } from './classes.schema.js';
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { Inject } from "@nestjs/common";
|
||||
import { ClassesRepository } from "./classes.repository.js";
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
} from "../shared/errors/application-error.js";
|
||||
import type { CreateClassDto, UpdateClassDto } from "./classes.dto.js";
|
||||
import type { Class, NewClass } from "./classes.schema.js";
|
||||
|
||||
export class ClassesService {
|
||||
constructor(private readonly repository: ClassesRepository) {}
|
||||
constructor(
|
||||
@Inject(ClassesRepository) private readonly repository: ClassesRepository,
|
||||
) {}
|
||||
|
||||
async create(dto: CreateClassDto): Promise<Class> {
|
||||
const newClass: NewClass = {
|
||||
@@ -18,7 +24,7 @@ export class ClassesService {
|
||||
async getById(id: string): Promise<Class> {
|
||||
const result = await this.repository.findById(id);
|
||||
if (!result) {
|
||||
throw new NotFoundError('Class', id);
|
||||
throw new NotFoundError("Class", id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -29,11 +35,11 @@ export class ClassesService {
|
||||
|
||||
async update(id: string, dto: UpdateClassDto): Promise<Class> {
|
||||
if (Object.keys(dto).length === 0) {
|
||||
throw new ValidationError('No fields to update');
|
||||
throw new ValidationError("No fields to update");
|
||||
}
|
||||
const result = await this.repository.update(id, dto);
|
||||
if (!result) {
|
||||
throw new NotFoundError('Class', id);
|
||||
throw new NotFoundError("Class", id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -41,7 +47,7 @@ export class ClassesService {
|
||||
async delete(id: string): Promise<void> {
|
||||
const existing = await this.repository.findById(id);
|
||||
if (!existing) {
|
||||
throw new NotFoundError('Class', id);
|
||||
throw new NotFoundError("Class", id);
|
||||
}
|
||||
await this.repository.delete(id);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HealthController } from './health.controller';
|
||||
import { Module } from "@nestjs/common";
|
||||
import { HealthController } from "./health.controller.js";
|
||||
|
||||
/**
|
||||
* 健康检查模块。
|
||||
|
||||
Reference in New Issue
Block a user