How to get multiple data with the same user ID from a table in Nest.js? Assuming I have a users table, how do I get the data that matches the user ID?
P粉116654495
P粉116654495 2023-11-16 20:41:42
0
2
813

How to get multiple data with the same user ID from a table in Nestjs? Let's say I have a users table. How to get user ID matching data?

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { usertbl } from './usertbl.entity';


  


@Injectable()
export class UsersService {
  constructor(
    @InjectRepository(usertbl)
    private UsertblRepository: Repository<usertbl>,
  ) {}

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

  findOne(User_ID: string): Promise<usertbl> {
    return this.UsertblRepository.findOneBy({ User_ID });
  }

createusertbl(Usertbl: usertbl ): Promise<usertbl> {
    return this.UsertblRepository.save(Usertbl);
}
}


P粉116654495
P粉116654495

reply all(2)
P粉998100648

If you want multiple matches, you should use the findBy method instead of findOne.

const Usertbl = await this.usersService.findBy({ id: 111 });

You can find more information on the type orm documentation .

P粉423694341
cosnt usertbl = await this.usersService.find({where: {User_ID: User_ID }})

This should work, but I recommend checking the typeorm documentation or wanago.

I would also recommend changing the variable names and try to follow camel case and uppercase type.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template