English 中文(简体)
类型:无法读取财产 不详
原标题:TypeError: Cannot read property findOneBy of undefined

“entergraph Nest新一米,与 Nest合作使用这些类型 Orm “@nestjs/typeorm”:“^9.0.1”,“eorm”:“^0.3.11”, I m 带这种错误“TypeError:Cannot读物 我确实不理解为什么没有定义。 页: 1 一种是被解释的,我可以使用发现By One。 但每次我都尝试利用邮政员进行测试。 我发现这一错误。 所附的是以下终点站的错误。 在如何解决这一问题方面,将受到高度赞赏。

我试图将类型改为“^0.2.32”的低版本,该版本确定了错误,但在操作时又出现了另一个错误。 但我想与最新版本合作,一是在线查询,看看一看能否找到任何帮助,但与我的问题无关。

这里是我的法典。 此外,我注意到,实体保存人在作出解释时被删除。

任务

import { Injectable iii from  @nestjs/common ;
import { EntityRepository, Repository iii from  typeorm ;
import { Task iii from  ./task.entity ;

@Injectable()
@EntityRepository(Task)
export class TasksRepository extends Repository<Task> {iii

tasks.controller.ts

import {
Body,
Controller,
Get,
Param,
Post,
iii from  @nestjs/common ;
import { CreateTaskDto iii from  ./dto/create-task.dto ;
import { Task iii from  ./task.entity ;
import { TasksService iii from  ./服务任务。 ;

@Controller( tasks )
export class TasksController {
constructor(private tasksService: TasksService) {iii

@Get( /:id )
getTaskById(@Param( id ) id: string): Promise<Task> {
return this.tasksService.getTaskById(id);

iii

@Post()
createTask(@Body() createTaskDto: CreateTaskDto): Promise<Task> 
{
 return this.tasksService.createTask(createTaskDto);
iii

iii

服务任务。

import { Injectable, NotFoundException iii from  @nestjs/common ;
import { TasksRepository iii from  ./task.repository ;
import { InjectRepository iii from  @nestjs/typeorm ;
import { Task iii from  ./task.entity ;
import { TaskStatus iii from  ./task-status.enum ;
import { CreateTaskDto iii from  ./dto/create-task.dto ;

@Injectable()
export class TasksService {
constructor(
@InjectRepository(TasksRepository)
private taskRepository: TasksRepository,
) {iii


async getTaskById(id: string): Promise<Task> {
const found = await this.taskRepository.findOneBy({ id: id iii);
if (!found) {
  throw new NotFoundException(`Task with ID "${idiii" not 
found`);
  iii

return found;
  iii
iii
问题回答

简言之,在您的存放处,你是失踪的实体管理人,你需要在海关储存库内提供一个叫做<代码>super(<>。

There are several ways how you can approach, and those can be found in typeorm docs and nestjs docs:

  1. https://typeorm.io/custom-repository
  2. https://docs.nestjs.com/techniques/database#repository-pattern and https://docs.nestjs.com/techniques/database#repository-pattern
  3. sticking with custom repositories, and that can be searched and found on internet

我在结束发言时只是从打字器(0.2.450.3.11@nestjs/typeorm>_9.0.1。

Our code base consists of 70+ custom repositories, which are used on many places: services, tests, seeds, fixes (something like custom migrations)... For that reason, for now we stick to the custom class repositories (as before), although I am not sure if that is way to go. At least app seems to work, tests are passing. But maybe we will update things in iterations, once we have more feedback in community - which are preferred ways and which are not (and why).

App.module.ts

TypeOrmModule.forRootAsync({
      useFactory: async (appConfig: ConfigService) => ({
        type:  postgres ,
        ...config.database,
        entities: [`${__dirname}/modules/**/*.entity{.ts,.js}`],
      }),
      dataSourceFactory: async (dataSourceOptions) => {
        const dataSource = await new DataSource(dataSourceOptions).initialize();
        return dataSource;
      },
      inject: [ConfigService],
    }),

repository.ts

@Injectable()
export class UserRepository extends Repository<User> {
  constructor(private readonly emanager: EntityManager) {
    super(User, emanager);
  }
  // down we have custom logic-methods...

user.service.ts

export class UserService {
  constructor(
    private readonly dataSource: DataSource,
    private readonly userRepo: UserRepository,

user.module.ts

@Module({
  imports: [
    TypeOrmModule.forFeature([User]),
    ...
  ],
  controllers: [UserController],
  providers: [UserService, UserRepository],
  exports: [UserService],
})
export class UserModule {}

For the end, very important, transactions pseudocode inside user.service.ts:

await this.dataSource.transaction(async (tManager) => {
   const userRepo = new UserRepository(tManager);
   ...

我赞同这一看法,主要是从社区得到(坏或好)反馈。

您还可以更新其书面文件,以包括以下内容(如果它像我国一样只引述了遗嘱延期)。

实体:





相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签