turkmen-expo/services/contacts.ts

32 lines
724 B
TypeScript
Raw Normal View History

2025-10-12 17:42:17 +00:00
import { FormType } from "@/components/shared/contacts-form";
import { baseAPI } from "@/lib/API";
import { ContactsDataType } from "@/lib/types/Contacts.type";
export const getContacts = async (lang: string) => {
const res = await fetch(`${baseAPI}contacts`, {
headers: {
"Accept-Language": lang,
},
});
if (!res.ok) {
throw new Error("Contacts error");
}
const data: ContactsDataType = await res.json();
return data;
};
export const postContacts = async (data: FormType) => {
const res = fetch(`${baseAPI}contact_form`, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
},
});
return (await res).status === 201;
};