{"size": 741, "ext": "js", "max_stars_repo_path": "app/controllers/auth.controller.js", "max_stars_repo_name": "rerissondaniel/bubbles-backend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/controllers/auth.controller.js", "max_issues_repo_name": "rerissondaniel/bubbles-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/controllers/auth.controller.js", "max_forks_repo_name": "rerissondaniel/bubbles-backend", "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": 28.5, "max_line_length": 69, "alphanum_fraction": 0.5870445344}
const log = require('../services/log.service');
const service = require('../services/auth.service');
const http = require('../services/http.service');

const login = async (req, res) => {
    try {
        const { email, password } = req.body;

        log.info('Iniciando login', { email });

        const result = await service.login(email, password);
        if (!result)
            return http.notFound(res, 'E-mail ou senha inválido(a)');

        log.info('Login finalizado', { email });

        const { user, token } = result;

        return http.ok(res, { user, token });
    } catch (e) {
        log.error('Erro ao realizar login', req.originalUrl, e);
        http.internalServerError(res);
    }
}

module.exports = { login }