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:
@@ -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 */
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user