The object literal is restricted to defining existing properties, and 'id' is not a recognized property in the type 'FindOptionsWhere<Teacher>'

I encountered a persistent error within my teachers.service:

Object literal may only specify known properties, and 'id' does not exist in type 'FindOptionsWhere | FindOptionsWhere[]'.ts(2353) FindOneOptions.d.ts(23, 5): The expected type comes from property 'where' which is declared here on type 'FindOneOptions' (property) id: number No quick fixes available

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, UpdateResult, DeleteResult } from 'typeorm';
import { Teacher } from '../entities/teacher.entity';

@Injectable()
export class TeachersService {
  constructor(
    @InjectRepository(Teacher)
    private teachersRepository: Repository<Teacher>,
  ) {}

  findAll(): Promise<Teacher[]> {
    return this.teachersRepository.find();
  }

  async findOne(id: number): Promise<Teacher | null> {
    return this.teachersRepository.findOne({
      where: {
        id,
      },
    });
  }

  create(teacher: Teacher): Promise<Teacher> {
    return this.teachersRepository.save(teacher);
  }

  async update(id: number, teacher: Teacher): Promise<Teacher> {
    await this.teachersRepository.update(id, teacher);
    return this.findOne(id);
  }

  async remove(id: number): Promise<void> {
    await this.teachersRepository.delete(id);
  }
}

Here is the structure of my Teacher entity:

import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm'; 
import { Class } from './class.entity'; 

@Entity() 
export class Teacher { 
  @PrimaryGeneratedColumn() 
  teacher_id: number; 

  @Column() 
  teacher_name: string; 

  @Column() 
  teacher_lastname: string; 

  @Column() 
  teacher_email: string; 

  @OneToMany(() => Class, (classEntity) => classEntity.teacher) 
  classes: Class[]; 
} 

Answer №1

Sorry, but the field id does not exist for the entity Teacher. Please make sure to only use fields that actually exist in your entity when specifying conditions in the where clause.

async findOne(id: number): Promise<Teacher | null> {
  return this.teachersRepository.findOne({
    where: {
      id,
    },
  });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I confirm if a class is an instance of a function-defined class?

I have been attempting to export a class that is defined within a function. In my attempts, I decided to declare the class export in the following way: export declare class GameCameraComponent extends GameObject { isMainCamera: boolean; } export abstra ...

Utilizing RxJs Observables in a service across various pages necessitates manual triggering of change detection

I have an observable in a shared service that is being used by multiple pages. The issue arises when the value of the observable is changed on one page and then I navigate to another page, as the subscription on the second page does not detect any change ...

Tips for identifying the cause of a memory leak in browser notifications

I am looking to implement browser notifications in a browser extension. However, I have noticed that the memory usage does not decrease after closing the notification. Can someone explain why this may be happening? Allow StackOverflow show notifications i ...

Utilize Typescript to aim for the most recent edition of EcmaScript

Are you looking to configure your typescript build to compile to the most recent version or the most current stable release of EcmaScript? For example, using this command: tsc --target <get latest version> Alternatively, in a tsconfig file: { & ...

Arrange an array of objects by making a nested API call in Angular

My task involves sorting an array of objects based on the response from the first API call in ascending order. The initial API call returns a list of arrays which will be used for the subsequent API call. The first API call fetches something like this: [0 ...

A circular reference occurs when a base class creates a new instance of a child class within its own definition

My goal is to instantiate a child class within a static method of the base class using the following code: class Baseclass { public static create(){ const newInstance = new Childclass(); return newInstance; } } class Childclass ex ...

What is the best way to verify if the ReactDOM.render method has been invoked with a React component as an argument

Here's the code snippet: index.tsx: import React, { Component } from 'react'; import ReactDOM from 'react-dom'; export function Loading(props) { return <div {...props}>loading...</div>; } export class MyComponent e ...

What is the process for including a selected-by option in a VIS network graph?

I'm trying to outline the neighboring nodes of the node that has been selected (highlightNearest). https://i.sstatic.net/lynhu.png Unfortunately, I haven't had success achieving this using JavaScript. Link to StackBlitz ...

Deducing the return type of asynchronously generated functions

My expectation is to automatically determine the return type of async functions when they are yielded as values from a generator. In the following example, the inference of the type of the yielded async functions appears to work correctly (detected as () ...

What is the best way to showcase nested array JSON data in an HTML Table?

https://i.stack.imgur.com/OHL0A.png I attempted to access the following link http://jsfiddle.net/jlspake/v2L1ny8r/7/ but without any success. This is my TypeScript code: var viewModel = function(data){ var self = this; self.orders = ko.observableArr ...

Inter-component communication within nested structures in Angular 2

Working on an Angular2 project that involves multiple nested components, I have successfully sent data from a child component to its immediate parent. However, when dealing with three levels of nesting, the question arises: How can I send or modify data ac ...

Tips for setting up a basic JSON server deployment

After completing an online React course, I successfully deployed my application to Heroku. Throughout the development process, I utilized the 'json-server' module from https://github.com/typicode/json-server. This allowed me to create a folder on ...

Generating a random number to be input into the angular 2 form group index can be done by following these

One interesting feature of my form is the dynamic input field where users can easily add more fields by simply clicking on a button. These input fields are then linked to the template using ngFor, as shown below: *ngFor="let data of getTasks(myFormdata); ...

Implementing Global Value Assignment Post Angular Service Subscription

Is there a way to globally assign a value outside of a method within my app component? This is how my service is structured: import { NumberInput } from '@angular/cdk/coercion'; import { HttpClient } from '@angular/common/http'; import ...

When the boolean is initially set to false, it will return true in an if statement without using

My Angular component contains a component-level boolean variable and an onClick event. Here's what the HTML file looks like: <div class="divClass" (click)="onClick($event)"></div> The relevant code from the TypeScript file is as follows: ...

the process of triggering animation to start automatically when a button is clicked in Web Development

I'm looking to create a React component that triggers an animation when clicked. I have a few options in mind: If the props are changed in the middle of the animation, it should restart the animation. The props can be changed by clicking a button on ...

Identifying a shift in data model within a component

It seems like there's a piece I might be overlooking, but here's my current situation - I have data that is being linked to the ngModel input of a component, like so: Typescript: SomeData = { SomeValue: 'bar' } Snippet from the vie ...

Achieve top-notch performance with an integrated iFrame feature in Angular

I am trying to find a method to determine if my iframe is causing a bottleneck and switch to a different source if necessary. Is it possible to achieve this using the Performance API? This is what I currently have in my (Angular) Frontend: <app-player ...

The type 'void' cannot be assigned to the type 'ReactNode'

Having trouble with the total amount calculation due to the nature of the calculateTotal function import CartItem from "./CartItem" import {CartItemType} from '../App' import {Typography,Stack} from '@mui/material'; type Props ...

Set up a remapping for Istanbul to encompass every source file

Currently, I am setting up my Ionic 2 application with Angular 2 and TypeScript to produce code coverage reports for my test files. For unit testing and coverage report generation, I am utilizing Jasmine, Karma, and remap-istanbul. I came across an inform ...