fix(01): align image upload field name and wrap category delete in transaction
This commit is contained in:
@@ -52,7 +52,7 @@ export async function apiDelete<T>(url: string): Promise<T> {
|
|||||||
|
|
||||||
export async function apiUpload<T>(url: string, file: File): Promise<T> {
|
export async function apiUpload<T>(url: string, file: File): Promise<T> {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("image", file);
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
|
|||||||
@@ -63,14 +63,15 @@ export function deleteCategory(
|
|||||||
return { success: false, error: "Category not found" };
|
return { success: false, error: "Category not found" };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reassign items to Uncategorized (id=1), then delete
|
// Reassign items to Uncategorized (id=1), then delete atomically
|
||||||
// Use a transaction for atomicity
|
db.transaction(() => {
|
||||||
db.update(items)
|
db.update(items)
|
||||||
.set({ categoryId: 1 })
|
.set({ categoryId: 1 })
|
||||||
.where(eq(items.categoryId, id))
|
.where(eq(items.categoryId, id))
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
db.delete(categories).where(eq(categories.id, id)).run();
|
db.delete(categories).where(eq(categories.id, id)).run();
|
||||||
|
});
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user