31 lines
1.6 KiB
TypeScript
31 lines
1.6 KiB
TypeScript
import { AxiosResponse } from "axios";
|
|
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
|
import { BaseClient } from "../../clients/clientBase";
|
|
import { Article } from "../../viewmodels/webpage/collection";
|
|
|
|
interface IArticleRequests {
|
|
getArticles: RequestDefinition<void, void, Article[]>;
|
|
getArticleById: RequestDefinition<{ id: string }, void, Article>;
|
|
createArticle: RequestDefinition<void, Partial<Article>, string>;
|
|
updateArticle: RequestDefinition<{ id: string }, Partial<Article>, void>;
|
|
deleteArticle: RequestDefinition<{ id: string }, void, void>;
|
|
}
|
|
|
|
@ImplementsRequestInterface<IArticleRequests>()
|
|
export default abstract class ArticleRequests {
|
|
static async getArticles({ http }: BaseClient): Promise<AxiosResponse<Article[], any>> {
|
|
return await http.get("/articles");
|
|
}
|
|
static async getArticleById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Article, any>> {
|
|
return await http.get(`/articles/${p.params.id}`);
|
|
}
|
|
static async createArticle({ http }: BaseClient, p: RequestData<void, Partial<Article>>): Promise<AxiosResponse<string, any>> {
|
|
return await http.post("/articles", p.body);
|
|
}
|
|
static async updateArticle({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Article>>): Promise<AxiosResponse<void, any>> {
|
|
return await http.post(`/articles/${p.params.id}`, p.body);
|
|
}
|
|
static async deleteArticle({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
|
return await http.post(`/articles/${p.params.id}`);
|
|
}
|
|
}
|