Skip to content

Commit

Permalink
RED-16 - atualiza dados do usuário e ajustes menores
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jul 21, 2024
1 parent 9e55b41 commit f8e0602
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions service-node-koa/app/controllers/usuario.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
delUsuario,
delUsuario, getById,
login,
novoUsuario,
resetCategorias,
resetConta,
updateUser,
validaInvite,
} from "../services/index.mjs";
validaInvite
} from '../services/index.mjs'
import { sign } from "../config/security/index.mjs";

export const userLoginRequest = async (ctx) => {
Expand Down Expand Up @@ -43,12 +43,10 @@ export const delUsuarioRequest = async (ctx) => {
export const updateUserRequest = async (ctx) => {
const { usuario_id: id } = ctx.params;
const { nome, email, senha, editToken } = ctx.request.body;
const usuario = await login({ email, senha });
if (!nome) ctx.throw(400, "Nome de usuário requerido");
if (!email) ctx.throw(400, "Email requerido");
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
Expand Down
3 changes: 3 additions & 0 deletions service-node-koa/app/services/usuario.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ export const login = async ({ email, senha }) => {
export const updateUser = async ({ id, nome, email, senha }) => {
return knex("usuario").where({ id }).update({ nome, email, senha: encrypt(senha) });
};

export const getById = async ({id}) =>
knex("usuario").where({ id }).first();

0 comments on commit f8e0602

Please sign in to comment.