{"size": 1493, "ext": "js", "max_stars_repo_path": "src/auth/models/user.js", "max_stars_repo_name": "emranaloul/book-your-appointment-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auth/models/user.js", "max_issues_repo_name": "emranaloul/book-your-appointment-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auth/models/user.js", "max_forks_repo_name": "emranaloul/book-your-appointment-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.9318181818, "max_line_length": 176, "alphanum_fraction": 0.6282652378}
// const {Client} = require('pg')
// require('dotenv').config()
// const client = new Client({connectionString:process.env.DATABASE_URL}) ;
// client.connect()

const client = require('../../db')
// client.connect()
const bcrypt = require('bcrypt')
const signup = async (data) => {
    try {
        let {firstName, lastName, email, password, role, commercialName, service_type, description} = data;
        let hashedPassword = await bcrypt.hash(password,10);
        let SQL = `INSERT INTO client (first_name, last_name, email, password, role, commercial_name, service_type, description) VAlUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING *;`;
        let safeValues = [firstName, lastName, email, hashedPassword, role, commercialName, service_type, description];
        let result = await client.query(SQL,safeValues);
        return result.rows[0];
    } catch (error) {
        throw new Error(error.message)
    }
}

const getSellers = async () =>{
    try {
        let SQL = 'SELECT * FROM client WHERE role=$1;'
        let result = await client.query(SQL,['seller'])
        return result.rows;
    } catch (error) {
        throw new Error(error.message)
    }
}

const getUserById = async id => {
    try {
        let SQL = `SELECT * FROM client WHERE id=$1;`;
        let safeValue = [id];
        let result = await client.query(SQL, safeValue);
        return result.rows[0];
    } catch (error) {
        console.log(error)
    }
};


module.exports = {signup,getSellers,getUserById}