• Как проверить зарегистрирован пользователь в бд posqresql?

    @Holden3377
    Я решил это так:
    const candidate = await pool.query('SELECT EXISTS (SELECT * FROM customer WHERE email = $1);', [email])
            const isRowExists = candidate.rows[0]
            if (isRowExists.exists == true) {
                return res.status(400).json({message: `User with email:${email} is already exist`})
            } else {
                const hashPassword = await bcrypt.hash(password, 8)
                const newUser = await pool.query(`INSERT INTO customer (firstname, lastname, email, pass) values ($1, $2, $3, $4) RETURNING *;`, [firstName, lastName, email, hashPassword])
                return res.json({message: `User ${firstName} was created`})
            }
    Ответ написан
    Комментировать