I have a method
@ApiOkResponse({
type: Bird,
})
@Get('demoBird')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async demo(@Query('dummy') _dummy: string) {
this.logger.log('findDemoBird');
return this.service.findDemoBird();
}
This works fine. If I remove @Query('dummy') _dummy: string
, the call fails:
error Application: Cannot read properties of undefined (reading 'findDemoBird')
In some other controllers I have a parameter-less methods working fine.
Package json:
"@nestjs/core": "^9.0.0",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
Update:
controller
import {
Body,
Controller,
Delete,
Get,
Inject,
Param,
Patch,
Post,
Put,
Query,
} from '@nestjs/common';
import { UpdateBirdDto } from './dtos/update-bird.dto';
import { BirdService } from './bird.service';
import { TraceableLogger } from 'src/common/logger/TraceableLogger';
import { Bird } from './bird.schema';
import {
ApiTags,
ApiOperation,
ApiParam,
ApiOkResponse,
ApiExtraModels,
ApiNotFoundResponse,
ApiInternalServerErrorResponse,
getSchemaPath,
ApiQuery,
ApiBody,
} from '@nestjs/swagger';
import { Subscription } from 'src/billing/subscription/subscription.schema';
import { UpdateLoansGdprDto } from '../loan/dtos/update-loans-gdpr.dto';
@Controller('birds')
export class BirdController {
constructor(
@Inject('BirdLogger') private readonly logger: TraceableLogger,
private readonly service: BirdService,
) {
this.logger.setContext(BirdController.name);
}
Fix:
@Injectable()
export class BirdService {
constructor(
private readonly repository: BirdRepository,
//// @Inject(forwardRef(() => SubscriptionService))
private readonly subscriptionService: SubscriptionService,
private readonly autoService: CarService,
private readonly katzenService: CatService,
@Inject('BirdLogger') private readonly logger: TraceableLogger,
) {
this.logger.setContext(PracticeService.name);
}
After line marked by ////
is removed/commented out everything works fine.
Update:
Subscription constructor:
@Injectable()
export class SubscriptionService {
private schemaFields: string;
private readonly logger = new Logger(SubscriptionService.name);
constructor(
@InjectModel(Subscription.name, 'birds')
private readonly model: Model<Subscription>,
private readonly configService: ConfigService,
) {
this.schemaFields = Object.keys(SubscriptionSchema.paths).join(' ');
}
4