Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
TypeORM (+express) .findOne promesa no funciona

Hola espero que estés bien,

Me encuentro con un problema molesto al usar typeORM. No puedo usar .then().catch(); justo después de 'userRepo.findOne'. Pero estoy casi seguro de que .findOne genera una Promesa...

¿Me podría ayudar?

Gracias de antemano por tu ayuda.

Encuentre debajo de mi entidad de usuario:

 import {Entity, PrimaryGeneratedColumn, Column, OneToMany} from "typeorm"; import { Post } from "./Post"; @Entity( {name : "Table_Personnes"} ) export class User { @PrimaryGeneratedColumn("uuid") Person_ID: number; @Column({ type: "varchar", length: 80}) Person_Email: string; @Column() Person_Login: string; @Column() Person_Password: string; @Column() Person_Picture: string; @OneToMany( (type) => Post, (Post) => Post.User) Table_Post: Promise<Post[]>; }

Encuentre debajo de mi controlador de usuario:

 import {getRepository} from "typeorm"; import {NextFunction, Request, Response} from "express"; //Import bcrypt import {bcrypt} from 'bcrypt' //Import token library import {jwt} from 'jsonwebtoken' //Import the entity model import {User} from "../entity/User"; import {Post} from "../entity/Post"; exports.login = (req, res, next) => { const userRepo = getRepository(User); userRepo.findOne({ Person_Email: req.body.user_email.toString().toLowerCase() }); .then((user) => { console.log("User that logged in: ", user); if (!user) { return res.status(401).json({ error: 'User not found !' }); } bcrypt.compare(req.body.password, user.Person_Password) .then(valid => { if (!valid) { return res.status(401).json({ error: 'wrong password !' }); } res.status(200).json({ userId: user._id, token: jwt.sign( { userId: user._id }, 'RANDOM_TOKEN_SECRET', { expiresIn: '24h' } ) }); }) .catch(error => res.status(500).json({ error })); }) .catch(error => res.status(500).json({ error })); };
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!