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:
@@ -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