Home>

Trying to make a query in the database using Typeorm in this way:

@injectable ()
Export Class AppService {
  ASYNC CheckexistenceUser (Data: Any): Promise <
Any >
 {
    const iissers= new users ();
    Const User= await getConnection ()
      .createQueryBuilder ()
      .Select ('NickName')
      .from (Iusers, 'Users')
      .where ('users.nickname=: nickname', {
        Nickname: Data.NickName,
      })
      .getone ();
  }
}

But in the FROM string, connected by Entity Users gives out such an error:

Entity itself:

@Entity ('Users')
Export Class Users Extends Basentity {
  @PrimaryGeneratedColumn ()
  ID: Number;
  @Column ()
  Nickname: String;
  @Column ()
  Password: String;
  @CreatDateColumn ()
  Registration_date: Number;
}

Tell me what is the problem. Just in case I put a link to Repository

UPD: Put ANY when creating instance Users:

Const iissers: Any= New Users ();

got a mistake:

I understand me and the request is wrong, although I copied it from docks.

  • Answer # 1

    I missed the advertisement of the repository in the service class:

    Constructor (
        @InjectRepository (User)
        Private UsersRepository: Repository <
    User >
    .
      ) {}
    
  • Answer # 2

    I missed the advertisement of the repository in the service class:

    Constructor (
        @InjectRepository (User)
        Private UsersRepository: Repository <
    User >
    .
      ) {}