I writing script admin/extension/component. I use get, and del of useFetchClient. get working exacly, but del not working. I want to delete all entries on strapi of a collection types.
how can it help me. Thanks. This is my full source code.
const { get, post, del } = useFetchClient();
function transformObject(input: any): TransformedObject {
const transformed: TransformedObject = {};
for (const item in input) {
if (languages.includes(item)) {
transformed[item] = {
web: input[item].web,
mobi: input[item].mobi,
extension: input[item].extension,
};
}
transformed["key"] = input.key;
transformed["id"] = input.id;
}
return transformed;
}
const fetchStrapi = async () => {
try {
const { data } = await get("http://localhost:1337/api/i18ns/get");
console.log("fetchStrapi", data);
return data;
} catch (error) {
console.error("Error fetching data: ");
return null; // Optionally return null or some default value on error
}
};
const deleteAllStrapi = async () => {
try {
const dataStrapi = await fetchStrapi();
for (const index of dataStrapi) {
const id = index.id;
console.log("id", id);
try {
const { data } = await del(
`http://localhost:1337/api/i18ns/${id}`
);
console.log("data", data);
// return data;
} catch (error) {
console.log("error");
}
}
} catch (error) {}
};