import { Category } from "../../../models/Category"; import { UpdateCategoryInput, UpdateCategoryResult } from "./types"; const updateCategory = async (userID: string, input: UpdateCategoryInput): Promise => { try { const { categoryID, ...updateFields } = input; const category = await Category.findOne({ _id: categoryID, userID }); if (!category) { return { message: "category-not-found", code: 404 }; } const updatedCategory = await Category.findByIdAndUpdate( categoryID, updateFields, { new: true //güncelledikten sonra döndürmesi için } ); if (!updatedCategory){ return { message: "category-not-found", code: 404 }; } return { message: "category-updated", code: 200, payload: { category: { _id: updatedCategory._id.toString(), title: updatedCategory.title, index: updatedCategory.index } } }; } catch (error) { console.error("UpdateCategory error:", error); return { message: "internal-server-error", code: 500 }; } }; export default updateCategory;