为什么我没有得到与typeorm和nest.js的重载匹配



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

这是我的任务实体:

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;
}

我已经拥有了项目中的其他一切,比如状态实体和用户实体

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

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;
}

我得到这个错误:

(node:5772) UnhandledPromiseRejectionWarning: QueryFailedError: Duplicate entry '8' for key 'task.REL_91d76dd2ae372b9b7dfb6bf3fd'
at Query.onResult (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testsrcdrivermysqlMysqlQueryRunner.ts:222:33)
at Query.execute (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testnode_modulesmysql2libcommandscommand.js:36:14)
at PoolConnection.handlePacket (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testnode_modulesmysql2libconnection.js:456:32)       
at PacketParser.onPacket (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testnode_modulesmysql2libconnection.js:85:12)
at PacketParser.executeStart (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testnode_modulesmysql2libpacket_parser.js:75:16)       
at Socket.<anonymous> (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testnode_modulesmysql2libconnection.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:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testsrctaskstasks.service.ts:70:11)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at TasksService.insertTask (C:UsersKryolos.Hakeemdesktopvodafone-tech-testback-endvodafone-testsrctaskstasks.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)

我已经被这件事困扰了很长一段时间了,任何帮助都将不胜感激,感谢

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

最新更新