mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-19 08:42:08 +03:00
867904f19d
Issue: https://github.com/StanGirard/quivr/issues/1503 Demo: https://github.com/StanGirard/quivr/assets/63923024/fc354768-e25b-4d16-8e40-bfdbf950ddcd
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { AxiosInstance } from "axios";
|
|
|
|
import { Testimonial } from "@/lib/types/testimonial";
|
|
|
|
type CmsTestimonials = {
|
|
data: {
|
|
id: number;
|
|
attributes: {
|
|
url: string;
|
|
jobTitle: string;
|
|
content: string;
|
|
name: string;
|
|
profilePicture: string | null;
|
|
socialMedia: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
publishedAt: string;
|
|
locale: string;
|
|
};
|
|
}[];
|
|
meta: {
|
|
pagination: {
|
|
page: number;
|
|
pageSize: number;
|
|
pageCount: number;
|
|
total: number;
|
|
};
|
|
};
|
|
};
|
|
|
|
const mapCmsTestimonialsToTestimonial = (
|
|
testimonials: CmsTestimonials
|
|
): Testimonial[] => {
|
|
return testimonials.data.map((item) => ({
|
|
socialMedia: item.attributes.socialMedia as "x" | "linkedin",
|
|
url: item.attributes.url,
|
|
jobTitle: item.attributes.jobTitle,
|
|
content: item.attributes.content,
|
|
name: item.attributes.name,
|
|
profilePicture: item.attributes.profilePicture ?? undefined,
|
|
}));
|
|
};
|
|
|
|
export const getTestimonials = async (
|
|
axiosInstance: AxiosInstance
|
|
): Promise<Testimonial[]> => {
|
|
const response = await axiosInstance.get<CmsTestimonials>(
|
|
"/api/testimonials"
|
|
);
|
|
|
|
return mapCmsTestimonialsToTestimonial(response.data);
|
|
};
|