Skip to content

Commit

Permalink
Revert database part of "Replace token_autenticacao with Authorization"
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaiacs committed Jul 12, 2020
1 parent b82e521 commit b1f4796
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/migrations/20191230204519-sessao_usuario.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
type: Sequelize.STRING(100),
allowNull: false
},
Authorization: {
token_autenticacao: {
type: Sequelize.STRING(100),
allowNull: false
},
Expand Down
4 changes: 2 additions & 2 deletions src/models/SessaoUsuarioModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,7 +17,7 @@ class SessaoUsuarioModel extends Model {

super.init({
email: DataTypes.STRING,
Authorization: DataTypes.STRING
token_autenticacao: DataTypes.STRING
},
{
defaultScope: {
Expand Down
18 changes: 9 additions & 9 deletions src/repositorios/sessao_repositorio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/repositorios/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe(
() => {
return SessionDAO.criarRegistroDeSessao(
"jest@test.database.cric.com.br",
"Authorization"
"token_autenticacao"
)
.then(
data => {
Expand All @@ -21,7 +21,7 @@ describe(
{
id: expect.any(Number),
email: "jest@test.database.cric.com.br",
Authorization: "Authorization"
token_autenticacao: "token_autenticacao"
}
);
}
Expand All @@ -33,7 +33,7 @@ describe(
"validarTokenAutenticacao",
() => {
return SessionDAO.validarTokenAutenticacao(
"Authorization"
"token_autenticacao"
)
.then(
data => {
Expand All @@ -42,7 +42,7 @@ describe(
{
id: expect.any(Number),
email: "jest@test.database.cric.com.br",
Authorization: "Authorization"
token_autenticacao: "token_autenticacao"
}
);
}
Expand Down

0 comments on commit b1f4796

Please sign in to comment.