【发布时间】:2020-05-20 22:55:15
【问题描述】:
在我的 Nestjs 应用下,我使用 @nestjsx/crud 来处理 crud 操作
但是对于某些路径和某些情况,我需要手动实现对服务的调用,这会运行一些 sql 查询。
我的控制器看起来像这样
import {Controller, Get} from '@nestjs/common';
import { Crud, CrudController } from '@nestjsx/crud';
import { TodoEntity } from './todo.entity';
import { TodoService } from './todo.service';
@Crud({
model: {
type: TodoEntity
}
})
@Controller('todo')
export class TodoController implements CrudController<TodoEntity> {
constructor(public todoService: TodoService) {}
// I WANT TO DO THIS in addition to the previous tremanet->
@Get('/mypath')
public async myManulaTreatment() {
return await this.todoService.getManual();
}
}
我的服务如下所示:
import { Injectable } from '@nestjs/common';
import { TypeOrmCrudService } from "@nestjsx/crud-typeorm";
import { TodoEntity } from './todo.entity';
import { InjectRepository } from '@nestjs/typeorm';
import {getManager , getConnection} from "typeorm";
@Injectable()
export class TodoService extends TypeOrmCrudService<TodoEntity>{
constructor(@InjectRepository(TodoEntity) repo) {
super(repo)
}
// THIS IS MY MANUAL TREATMENT
async getManual(){
const entityManager = await getConnection().manager.query("SELECT * FROM "+process.env.DATABASE_DB.mytable);
}
}
但我收到了这个错误:
Class 'TodoController' incorrectly implements interface 'CrudController<TodoEntity>'.
Property 'service' is missing in type 'TodoController' but required in type 'CrudController<TodoEntity>'.
建议?
【问题讨论】:
标签: javascript typescript nestjs typeorm