Skip to content

Commit

Permalink
RED-16 - atualizando os dados, pende os testes
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jul 21, 2024
1 parent b680213 commit 9e55b41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion service-node-koa/app/controllers/usuario.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
novoUsuario,
resetCategorias,
resetConta,
updateUser,
validaInvite,
} from "../services/index.mjs";
import { sign } from "../config/security/index.mjs";
Expand Down Expand Up @@ -48,5 +49,9 @@ export const updateUserRequest = async (ctx) => {
if (!senha) ctx.throw(400, "Senha requerida");
if (!editToken) ctx.throw(400, "editToken requerido");
if (id != usuario.id) ctx.throw(400, "Usuário incorreto!");

// TODO verificar/consumir o editToken
const affected = await updateUser({ id, nome, email, senha });
// ctx.response.status = 303
// ctx.set("Location", `/dashboard`) // XXX too fancy!
ctx.body = { status: "success", affected };
};
4 changes: 4 additions & 0 deletions service-node-koa/app/services/usuario.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export const login = async ({ email, senha }) => {
if (!user || decrypt(user.senha) !== senha) return null;
return user;
};

export const updateUser = async ({ id, nome, email, senha }) => {
return knex("usuario").where({ id }).update({ nome, email, senha: encrypt(senha) });
};

0 comments on commit 9e55b41

Please sign in to comment.