qudoco-fe/service/cms-landing.ts

271 lines
7.0 KiB
TypeScript
Raw Normal View History

2026-04-10 07:21:29 +00:00
import {
httpDeleteInterceptor,
httpGetInterceptor,
httpPostInterceptor,
httpPutInterceptor,
} from "./http-config/http-interceptor-services";
/** Axios wrapper returns `{ error, data }` where `data` is full API body `{ success, messages, data }`. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function apiPayload<T>(res: any): T | null {
if (!res || typeof res !== "object") return null;
const r = res as { error?: boolean; data?: { data?: T } | null };
if (r.error || r.data == null) return null;
return r.data.data ?? null;
}
export function apiRows<T>(res: any): T[] {
const rows = apiPayload<T[]>(res);
return Array.isArray(rows) ? rows : [];
}
/** Normalizes list endpoints that return either a single object or an array. */
export function apiDataList<T>(res: unknown): T[] {
const raw = apiPayload<T[] | T>(res);
if (Array.isArray(raw)) return raw;
if (raw != null && typeof raw === "object") return [raw as T];
return [];
}
export async function getHeroContent() {
return await httpGetInterceptor("/hero-contents");
}
export async function saveHeroContent(body: {
primary_title: string;
secondary_title?: string;
description?: string;
primary_cta?: string;
secondary_cta_text?: string;
}) {
return await httpPostInterceptor("/hero-contents", body);
}
export async function updateHeroContent(
id: string,
body: {
primary_title: string;
secondary_title?: string;
description?: string;
primary_cta?: string;
secondary_cta_text?: string;
},
) {
return await httpPutInterceptor(`/hero-contents/${id}`, body);
}
export async function getHeroImages(heroId: string) {
return await httpGetInterceptor(`/hero-content-images/${heroId}`);
}
export async function saveHeroImage(body: {
hero_content_id: string;
image_path?: string;
image_url?: string;
}) {
return await httpPostInterceptor("/hero-content-images", body);
}
export async function updateHeroImage(
id: string,
body: { image_path?: string; image_url?: string },
) {
return await httpPutInterceptor(`/hero-content-images/${id}`, body);
}
export async function getAboutContentsList() {
return await httpGetInterceptor("/about-us-contents");
}
export async function saveAboutContent(body: Record<string, string>) {
return await httpPostInterceptor("/about-us-contents", body);
}
export async function updateAboutContent(
id: number,
body: Record<string, string>,
) {
return await httpPutInterceptor(`/about-us-contents/${id}`, body);
}
export async function saveAboutUsMediaUrl(body: {
about_us_content_id: number;
media_url: string;
media_type?: string;
}) {
return await httpPostInterceptor("/about-us-content-images/url", body);
}
export async function deleteAboutUsContentImage(id: number) {
return await httpDeleteInterceptor(`/about-us-content-images/${id}`);
}
export async function getOurProductContent() {
return await httpGetInterceptor("/our-product-contents");
}
export async function saveOurProductContent(body: {
primary_title: string;
secondary_title?: string;
description?: string;
}) {
return await httpPostInterceptor("/our-product-contents", body);
}
export async function updateOurProductContent(
id: string,
body: {
primary_title: string;
secondary_title?: string;
description?: string;
},
) {
return await httpPutInterceptor(`/our-product-contents/${id}`, body);
}
export async function deleteOurProductContent(id: string) {
return await httpDeleteInterceptor(`/our-product-contents/${id}`);
}
export async function getOurProductImages(productContentId: string) {
return await httpGetInterceptor(
`/our-product-content-images/${productContentId}`,
);
}
export async function saveOurProductImage(body: {
our_product_content_id: string;
image_path?: string;
image_url?: string;
}) {
return await httpPostInterceptor("/our-product-content-images", body);
}
export async function updateOurProductImage(
id: string,
body: { image_path?: string; image_url?: string },
) {
return await httpPutInterceptor(`/our-product-content-images/${id}`, body);
}
export async function getOurServiceContent() {
return await httpGetInterceptor("/our-service-contents");
}
export async function saveOurServiceContent(body: {
primary_title: string;
secondary_title?: string;
description?: string;
}) {
return await httpPostInterceptor("/our-service-contents", body);
}
export async function updateOurServiceContent(
id: number,
body: {
primary_title: string;
secondary_title?: string;
description?: string;
},
) {
return await httpPutInterceptor(`/our-service-contents/${id}`, body);
}
export async function deleteOurServiceContent(id: number) {
return await httpDeleteInterceptor(`/our-service-contents/${id}`);
}
export async function getOurServiceImages(serviceContentId: number) {
return await httpGetInterceptor(
`/our-service-content-images/${serviceContentId}`,
);
}
export async function saveOurServiceImage(body: {
our_service_content_id: number;
image_path?: string;
image_url?: string;
}) {
return await httpPostInterceptor("/our-service-content-images", body);
}
export async function updateOurServiceImage(
id: string,
body: { image_path?: string; image_url?: string },
) {
return await httpPutInterceptor(`/our-service-content-images/${id}`, body);
}
export async function getPartnerContents() {
return await httpGetInterceptor("/partner-contents");
}
export async function savePartnerContent(body: {
primary_title: string;
image_path?: string;
image_url?: string;
}) {
return await httpPostInterceptor("/partner-contents", body);
}
export async function updatePartnerContent(
id: string,
body: {
primary_title: string;
image_path?: string;
image_url?: string;
},
) {
return await httpPutInterceptor(`/partner-contents/${id}`, body);
}
export async function deletePartnerContent(id: string) {
return await httpDeleteInterceptor(`/partner-contents/${id}`);
}
export async function getPopupNewsList(page = 1, limit = 10) {
return await httpGetInterceptor(
`/popup-news-contents?page=${page}&limit=${limit}`,
);
}
export async function getPopupNewsById(id: number) {
return await httpGetInterceptor(`/popup-news-contents/${id}`);
}
export async function savePopupNews(body: {
primary_title: string;
secondary_title?: string;
description?: string;
primary_cta?: string;
secondary_cta_text?: string;
}) {
return await httpPostInterceptor("/popup-news-contents", body);
}
export async function updatePopupNews(
id: number,
body: {
id: number;
primary_title: string;
secondary_title?: string;
description?: string;
primary_cta?: string;
secondary_cta_text?: string;
},
) {
return await httpPutInterceptor(`/popup-news-contents/${id}`, body);
}
export async function savePopupNewsImage(body: {
popup_news_content_id: number;
media_path?: string;
media_url?: string;
}) {
return await httpPostInterceptor("/popup-news-content-images", body);
}
export async function deletePopupNews(id: number) {
return await httpDeleteInterceptor(`/popup-news-contents/${id}`);
}