fix: prevent deleting registry entries that would create sequence gaps

Only the last entry in a company+year sequence can be deleted. Trying
to delete an earlier number (e.g. #2 when #3 exists) returns a 409
error with a Romanian message explaining the restriction.

Also routes UI deletes through the API (like create/update) so they
get proper audit logging and sequence recalculation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-11 22:38:51 +02:00
parent 5cb438ef67
commit 34024404a5
3 changed files with 70 additions and 5 deletions
@@ -216,7 +216,12 @@ export function RegistraturaModule() {
};
const handleDelete = async (id: string) => {
await removeEntry(id);
try {
await removeEntry(id);
} catch (err) {
const msg = err instanceof Error ? err.message : "Eroare la ștergere";
alert(msg);
}
};
/** All closes go through the close dialog */
+11 -3
View File
@@ -15,7 +15,6 @@ import {
getAllEntries,
getFullEntry,
saveEntry,
deleteEntry,
} from "../services/registry-service";
import type { RegistryAuditEvent } from "../types";
import {
@@ -111,10 +110,19 @@ export function useRegistry() {
const removeEntry = useCallback(
async (id: string) => {
await deleteEntry(storage, blobStorage, id);
// Use the API for sequence validation + audit logging
const res = await fetch(`/api/registratura?id=${encodeURIComponent(id)}`, {
method: "DELETE",
});
const result = await res.json();
if (!result.success) {
throw new Error(result.error ?? "Failed to delete entry");
}
await refresh();
},
[storage, blobStorage, refresh],
[refresh],
);
const closeEntry = useCallback(