|
@@ -56,10 +56,12 @@ export const UsuarioController = {
|
|
|
if (Nivel !== undefined) updates.Nivel = Nivel;
|
|
if (Nivel !== undefined) updates.Nivel = Nivel;
|
|
|
if (Setor !== undefined) updates.Setor = Setor.trim();
|
|
if (Setor !== undefined) updates.Setor = Setor.trim();
|
|
|
|
|
|
|
|
- const usuario = await Usuario.query().patchAndFetchById(id, updates);
|
|
|
|
|
|
|
+ const usuario = await Usuario.query().findById(id);
|
|
|
if (!usuario) throw new NotFoundError("Usuário não encontrado");
|
|
if (!usuario) throw new NotFoundError("Usuário não encontrado");
|
|
|
|
|
|
|
|
- return res.status(200).send({ status: true, usuario: formatarUsuario(usuario) });
|
|
|
|
|
|
|
+ const atualizado = await usuario.$query().patchAndFetch(updates);
|
|
|
|
|
+
|
|
|
|
|
+ return res.status(200).send({ status: true, usuario: formatarUsuario(atualizado) });
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
return next(error);
|
|
return next(error);
|
|
|
}
|
|
}
|
|
@@ -74,7 +76,7 @@ export const UsuarioController = {
|
|
|
if (!usuario) throw new NotFoundError("Usuário não encontrado");
|
|
if (!usuario) throw new NotFoundError("Usuário não encontrado");
|
|
|
|
|
|
|
|
const novoStatus = String(usuario.Status) === "1" ? "0" : "1";
|
|
const novoStatus = String(usuario.Status) === "1" ? "0" : "1";
|
|
|
- await Usuario.query().findById(id).patch({ Status: novoStatus });
|
|
|
|
|
|
|
+ await usuario.$query().patch({ Status: novoStatus });
|
|
|
|
|
|
|
|
return res.status(200).send({ status: true, novoStatus });
|
|
return res.status(200).send({ status: true, novoStatus });
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -102,7 +104,7 @@ export const UsuarioController = {
|
|
|
if (!senhaValida) throw new AppError("Senha atual incorreta", 401);
|
|
if (!senhaValida) throw new AppError("Senha atual incorreta", 401);
|
|
|
|
|
|
|
|
const novaHash = bcrypt.hashSync(senhaNova, 10);
|
|
const novaHash = bcrypt.hashSync(senhaNova, 10);
|
|
|
- await Usuario.query().findById(id).patch({ Senha: novaHash });
|
|
|
|
|
|
|
+ await usuario.$query().patch({ Senha: novaHash });
|
|
|
|
|
|
|
|
return res.status(200).send({ status: true, msg: "Senha alterada com sucesso!" });
|
|
return res.status(200).send({ status: true, msg: "Senha alterada com sucesso!" });
|
|
|
} catch (error) {
|
|
} catch (error) {
|