diff --git a/src/migrations/20191230204519-sessao_usuario.js b/src/migrations/20191230204519-sessao_usuario.js index d4ce74d..d994a66 100644 --- a/src/migrations/20191230204519-sessao_usuario.js +++ b/src/migrations/20191230204519-sessao_usuario.js @@ -15,7 +15,7 @@ module.exports = { type: Sequelize.STRING(100), allowNull: false }, - Authorization: { + token_autenticacao: { type: Sequelize.STRING(100), allowNull: false }, diff --git a/src/models/SessaoUsuarioModel.js b/src/models/SessaoUsuarioModel.js index ee9fe22..7f87f8f 100644 --- a/src/models/SessaoUsuarioModel.js +++ b/src/models/SessaoUsuarioModel.js @@ -7,7 +7,7 @@ const { Model, DataTypes } = require("sequelize"); * @constructor * @param {Object} data - Data sent to server. * @param {string} data.email - Email address of user. - * @param {string} data.Authorization - Authorization token assigned to the email address. + * @param {string} data.token_autenticacao - Authorization token assigned to the email address. * @returns {Promise} Promise instance of Sequelize object that was created. */ class SessaoUsuarioModel extends Model { @@ -17,7 +17,7 @@ class SessaoUsuarioModel extends Model { super.init({ email: DataTypes.STRING, - Authorization: DataTypes.STRING + token_autenticacao: DataTypes.STRING }, { defaultScope: { diff --git a/src/repositorios/sessao_repositorio.js b/src/repositorios/sessao_repositorio.js index da287f3..4497527 100644 --- a/src/repositorios/sessao_repositorio.js +++ b/src/repositorios/sessao_repositorio.js @@ -7,31 +7,31 @@ const db = require("../database"); module.exports = { - async criarRegistroDeSessao(email, Authorization) { + async criarRegistroDeSessao(email, token_autenticacao) { return await SessaoUsuarioModel.create({ email: email, - Authorization: Authorization + token_autenticacao: token_autenticacao }); }, - async validarTokenAutenticacao(Authorization) { + async validarTokenAutenticacao(token_autenticacao) { return SessaoUsuarioModel.findOne({ where: { - Authorization: Authorization + token_autenticacao: token_autenticacao } }); }, - async anularRegistroDeSessao(Authorization) { + async anularRegistroDeSessao(token_autenticacao) { let resultado; const token_nulo = "--------------------------------------------------"; const sqlQuery = ` UPDATE sessao_usuario - SET Authorization = '${token_nulo}' - WHERE Authorization = '${Authorization}'`; + SET token_autenticacao = '${token_nulo}' + WHERE token_autenticacao = '${token_autenticacao}'`; await db.query( sqlQuery, @@ -46,11 +46,11 @@ module.exports = { return resultado; }, - async excluirRegistroDeSessao(Authorization) { + async excluirRegistroDeSessao(token_autenticacao) { return await SessaoUsuarioModel.destroy({ where: { - Authorization: Authorization + token_autenticacao: token_autenticacao } }); } diff --git a/src/repositorios/session.test.js b/src/repositorios/session.test.js index 9e54f19..3dd1491 100644 --- a/src/repositorios/session.test.js +++ b/src/repositorios/session.test.js @@ -12,7 +12,7 @@ describe( () => { return SessionDAO.criarRegistroDeSessao( "jest@test.database.cric.com.br", - "Authorization" + "token_autenticacao" ) .then( data => { @@ -21,7 +21,7 @@ describe( { id: expect.any(Number), email: "jest@test.database.cric.com.br", - Authorization: "Authorization" + token_autenticacao: "token_autenticacao" } ); } @@ -33,7 +33,7 @@ describe( "validarTokenAutenticacao", () => { return SessionDAO.validarTokenAutenticacao( - "Authorization" + "token_autenticacao" ) .then( data => { @@ -42,7 +42,7 @@ describe( { id: expect.any(Number), email: "jest@test.database.cric.com.br", - Authorization: "Authorization" + token_autenticacao: "token_autenticacao" } ); }