首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我没有使用typeorm和nest.js进行重载匹配

为什么我没有使用typeorm和nest.js进行重载匹配
EN

Stack Overflow用户
提问于 2022-04-07 15:33:23
回答 1查看 579关注 0票数 -2

嘿,我在尝试为任务创建一个实体,并使用这个实体,

这是我的任务实体:

代码语言:javascript
运行
复制
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Status } from './Status.entity';
import { User } from './User.entity';

@Entity()
export class Task {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'task_id',
  })
  id: number;

  @Column()
  title: string;

  @Column()
  description: string;

  @OneToOne(() => Status)
  @JoinColumn()
  status: Status;

  @OneToOne(() => User)
  @JoinColumn()
  createdBy: User;

  @OneToOne(() => User)
  @JoinColumn()
  updatedBy: User;

  @CreateDateColumn({
    type: 'timestamp',
    name: 'created_at',
  })
  createdAt: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    name: 'updated_at',
  })
  updateAt: Date;
}

项目中的其他所有内容都已经像状态实体和用户实体一样。

当我试图创建这样一个任务时

代码语言:javascript
运行
复制
 async insertTask(title: string, description: string, userId: number) {
    const userDetails = await this.findUser(userId)
    const newTask = this.TaskRepository.create({
      title,
      description,
      createdBy: userDetails,
    });

    const res = await this.TaskRepository.save(newTask)

    return res;
  }

我知道这个错误:

代码语言:javascript
运行
复制
(node:5772) UnhandledPromiseRejectionWarning: QueryFailedError: Duplicate entry '8' for key 'task.REL_91d76dd2ae372b9b7dfb6bf3fd'
    at Query.onResult (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\src\driver\mysql\MysqlQueryRunner.ts:222:33)
    at Query.execute (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\node_modules\mysql2\lib\commands\command.js:36:14)
    at PoolConnection.handlePacket (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\node_modules\mysql2\lib\connection.js:456:32)       
    at PacketParser.onPacket (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\node_modules\mysql2\lib\connection.js:85:12)
    at PacketParser.executeStart (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\node_modules\mysql2\lib\packet_parser.js:75:16)       
    at Socket.<anonymous> (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\node_modules\mysql2\lib\connection.js:92:25)
    at Socket.emit (events.js:375:28)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:265:9)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5772) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5772) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:5772) UnhandledPromiseRejectionWarning: NotFoundException: User Not Found
    at TasksService.findUser (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\src\tasks\tasks.service.ts:70:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at TasksService.insertTask (C:\Users\Kryolos.Hakeem\desktop\vodafone-tech-test\back-end\vodafone-test\src\tasks\tasks.service.ts:19:25)
(node:5772) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

我已经坚持了很长一段时间了,任何帮助都将不胜感激,谢谢

EN

Stack Overflow用户

发布于 2022-04-07 16:01:26

这是因为updatedBycreatedBy字段在Task上的类型是User,但是您提供了一个number ( userId参数)。

票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71784996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档