feat(dict): delete dictionary endpoint + UI button с cascade safety

This commit is contained in:
Александр Зимин
2026-06-05 09:47:05 +00:00
parent cdffa4261c
commit 5c6801f993
10 changed files with 437 additions and 4 deletions
+26
View File
@@ -136,6 +136,32 @@ export const useUpdateDictionary = () => {
})
}
/**
* Удаление справочника. Cascade на records + drafts + schema_drafts через
* FK ON DELETE CASCADE (migration 0030). Только admin role.
*
* <p>Backend errors:
* <ul>
* <li>403 {@code forbidden_role} — не admin.</li>
* <li>404 {@code dictionary_not_found} — нет либо вне scope.</li>
* <li>409 {@code has_dependents} — другой dict ссылается через
* x-references. message содержит список dependents. UI показывает
* их юзеру и предлагает либо убрать FK у зависимых, либо force.</li>
* </ul>
*/
export const useDeleteDictionary = () => {
const qc = useQueryClient()
return useMutation({
mutationFn: async (params: { name: string; force?: boolean }): Promise<void> => {
const qs = params.force ? '?force=true' : ''
await apiClient.delete(`/dictionaries/${params.name}${qs}`)
},
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['dictionaries'] })
},
})
}
/**
* Create-record mutation. {@code idempotencyKey} — required, передаётся caller'ом
* (один на жизнь формы; см. {@link useFormIdempotencyKey}). Это защищает от