{"size": 1079, "ext": "js", "max_stars_repo_path": "models/usuario/usuarioDAO.js", "max_stars_repo_name": "cyber-wave/ctrlapp-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/usuario/usuarioDAO.js", "max_issues_repo_name": "cyber-wave/ctrlapp-server", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/usuario/usuarioDAO.js", "max_forks_repo_name": "cyber-wave/ctrlapp-server", "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": 29.1621621622, "max_line_length": 87, "alphanum_fraction": 0.5764596849}
var pgp = require("pg-promise")();
var db = pgp('postgres://teste:ufc123@localhost:5432/ctrlapp');
var Usuario = require('./usuario');

class UsuarioDAO{
    /**
     * Get all users in the system.
     * @param {Function} success Called when receiving data
     * @param {Function} failure Called when there is an error
     */
    static getTodos(success, failure){
        db.any("SELECT * FROM usuario")
        .then(data => {
            success(data);
        })
        .catch(err => {
            failure(err);
        });
    }
    /**
     * Função que pega um usuario do banco
     * @param {String} login Login do usuario cadastrado
     * @returns Uma promise com um Usuario pendentes
     */
     static async getUsuario(login){
        var data = await db.one("SELECT * FROM usuario WHERE usuario.login = $1",login)
        
        if(!data){
            //o usuario nao existe
            throw new Error("Usuario nao existe");
        }
        return new Usuario(data.login, data.email, data.senha, data.msg_id);
        
    }
}

module.exports = UsuarioDAO;