devlog_owen
240102 [TIL] nest.js,typescript 개인프로젝트 과제 오류정리 본문
728x90
1. findOne 메서드에 잘못된 인자가 전달되었을때
"[nestjs/typeorm] Object literal may only specify known properties, and 'id' does not exist in type 'FindOneOptions'"
이 오류는 findOne 메서드에 잘못된 인자가 전달되었을 때 발생합니다. findOne 메서드는 FindOneOptions 타입의 객체를 인자로 받아야 하는데, id라는 프로퍼티는 FindOneOptions 타입에 존재하지 않습니다. 이 오류를 해결하려면 findOne 메서드에 올바른 형식의 인자를 전달해야 합니다.
예를 들어, { where: { id: createBookingDto.eventId } }와 같은 형태로 전달하면 된다.
Repository의 의존성을 해결할 수 없을 때
"Nest can't resolve dependencies of the BookingService (BookingRepository, ?). Please make sure that the argument "EventRepository" at index [1] is available in the BookingModule context."
이 오류는 BookingService가 EventRepository의 의존성을 해결할 수 없을 때 발생합니다. BookingModule에 EventRepository가 제공되지 않았기 때문이다. 이 오류를 해결하려면, BookingModule에 Event 엔티티를 import해야 합니다. 이를 위해 TypeOrmModule.forFeature 메서드를 사용하여 BookingModule에 Event 엔티티를 추가하면 됩니다.
@Module({
imports: [TypeOrmModule.forFeature([Booking, UserModule, Event])],
providers: [BookingService],
controllers: [BookingController],
})
export class BookingModule {}
728x90
'TIL' 카테고리의 다른 글
240104 [TIL] autoLoadEntities, logging/ValidationPipe/swagger 사용법 (2) | 2024.01.05 |
---|---|
240103 [TIL] nest.js로 공연예매사이트 만들기 (2) | 2024.01.04 |
231229 [TIL]TYPEORM을 쓰면 따로 레파지토리 파일을 안만들어도 되는 이유 (0) | 2024.01.02 |
231228 [TIL] 개인프로젝트 3일차 (1) | 2023.12.29 |
231227 [TIL] typescript,nest.js 공연예매사이트 만들기 2일차 (0) | 2023.12.27 |