feat(categoria): Card 01 — bloquear delete de categoria em uso + filtro soft-deleted - #155
Merged
FernandoAlmeidaPinto merged 4 commits intoJul 26, 2026
Conversation
…orwardRef Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
FernandoAlmeidaPinto
deleted the
feature/crud-categoria-card-01-delete-enrichment
branch
July 26, 2026 05:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #153
Etapa 3 (CRUD Categoria) — Card 01. Enriquece o backend do
ms-simuladopara o CRUD de categorias.Summary
SimuladoRepository.countByCategoria(categoriaId)— conta simulados não-deletados que referenciam a categoria (filtro pelo campo booleanodeleted, correto — nãodeletedAt).CategoriaService.delete— 404 se a categoria não existe; 409 com payload{ message, simuladosUsando }se algum simulado a referencia; só então soft-delete. Efeito: as 6 categorias seedadas ficam naturalmente protegidas (todas têm simulados em uso).CategoriaRepository.getAll— passa a filtrar soft-deleted (deleted: { $ne: true }), preservando owheredo caller e o.populate('exame'). Guard posto por último no spread ({ ...where, deleted: { $ne: true } }) para o caller não conseguir sobrescrevê-lo.CategoriaModule ↔ SimuladoModuleresolvido comforwardRefnos dois lados (risco [003-007] Migração simulado - Nest #1 do card).Decisões
PATCH/update de categoria foi adicionada (confirmado no controller).getByIdinalterado: continua retornando mesmo categorias soft-deleted (compat com simulados históricos).@Inject(forwardRef(() => SimuladoRepository))noCategoriaServicecomo escolha defensiva. A app foi confirmada bootando (Nest application successfully started), então o ciclo resolve; o forwardRef no parâmetro é belt-and-suspenders e não causa dano.Test Plan
countByCategoria(filtro),delete(sucesso, 409 c/ contador, payload, 404),getAll(filtro + where + populate) — 6/6 passamnpm run buildlimpoNest application successfully started(ciclo de DI resolve)GET /v1/categorianão lista soft-deletedFora de escopo (registrado)
SimuladoRepository.getTotalEntity()/entityActived()filtram por{ deletedAt: null }(campo inexistente no schema — bug pré-existente nadevelop). Não corrigido aqui para não ampliar escopo.🤖 Generated with Claude Code