48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import {About_Plain} from "@/types/generated-strapi-interfaces/api/about";
|
|
import strapiClient from "@/api/strapi/strapi-client";
|
|
import qs from "qs";
|
|
import aboutQuery from "@/api/strapi/query/about.json";
|
|
import homeQuery from "@/api/strapi/query/home.json";
|
|
import servicesQuery from "@/api/strapi/query/services.json";
|
|
import {YogaBlogPost_Plain} from "@/types/generated-strapi-interfaces/api/yoga-blog-post";
|
|
import {Home_Plain} from "@/types/generated-strapi-interfaces/api/home";
|
|
import {ServicesPage_Plain} from "@/types/generated-strapi-interfaces/api/services-page";
|
|
|
|
|
|
class StrapiApi{
|
|
constructor( ) {
|
|
}
|
|
|
|
protected async getJson<T>(path: string, params?: object){
|
|
const query = params ? qs.stringify(params,{ arrayFormat: 'indices' , encode: false}) : "";
|
|
const payload = await strapiClient.httpGetJson<T>(
|
|
path+ query
|
|
);
|
|
return payload?.data;
|
|
}
|
|
|
|
public getImageUrl(imagePath: string){
|
|
return strapiClient.getImageUrl(imagePath);
|
|
}
|
|
public async getAboutPage(): Promise<About_Plain>{
|
|
return this.getJson("/api/about?",aboutQuery);
|
|
}
|
|
|
|
public getHomePage(): Promise<Home_Plain>{
|
|
return this.getJson("/api/home?",homeQuery);
|
|
}
|
|
|
|
public getServicesPage(): Promise<ServicesPage_Plain>{
|
|
return this.getJson("/api/services-page?",servicesQuery);
|
|
}
|
|
|
|
public getBlog(blogId: string): Promise<YogaBlogPost_Plain>{
|
|
return this.getJson("/api/yoga-blog-posts/"+blogId,undefined);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const api = new StrapiApi();
|
|
export default api;
|