- Backend: Fastify + Prisma/SQLite com autenticacao JWT - CRUD completo: usuarios, categorias, produtos, comandas - Sistema de comandas com itens, status, pagamento - Controle de estoque (entrada/saida automatica) - Relatorios e dashboard com KPIs - Notificacoes sonoras na cozinha - Frontend: SPA vanilla TS com tema dark glassmorphism - Mobile-first com bottom-sheet e cards compactos - Busca de comandas por periodo - Modal de detalhes com secao editavel colapsavel
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { prisma } from '../lib/prisma';
|
|
import bcrypt from 'bcrypt';
|
|
import { LoginInput } from '../schemas/auth.schema';
|
|
|
|
export async function loginService({ email, senha }: LoginInput) {
|
|
const user = await prisma.usuario.findUnique({
|
|
where: { email },
|
|
});
|
|
|
|
if (!user || !user.ativo) {
|
|
throw new Error('Credenciais inválidas ou usuário inativo');
|
|
}
|
|
|
|
const isPasswordValid = await bcrypt.compare(senha, user.senha);
|
|
|
|
if (!isPasswordValid) {
|
|
throw new Error('Credenciais inválidas ou usuário inativo');
|
|
}
|
|
|
|
return {
|
|
id: user.id,
|
|
nome: user.nome,
|
|
email: user.email,
|
|
role: user.role,
|
|
};
|
|
}
|
|
|
|
export async function changePassword(userId: string, senhaAtual: string, novaSenha: string) {
|
|
const user = await prisma.usuario.findUnique({ where: { id: userId } });
|
|
if (!user) throw new Error('Usuário não encontrado');
|
|
|
|
const isPasswordValid = await bcrypt.compare(senhaAtual, user.senha);
|
|
if (!isPasswordValid) throw new Error('Senha atual incorreta');
|
|
|
|
const passwordHash = await bcrypt.hash(novaSenha, 10);
|
|
await prisma.usuario.update({
|
|
where: { id: userId },
|
|
data: { senha: passwordHash },
|
|
});
|
|
}
|