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 { Operation } from "../../viewmodels/webpage/collection";
|
|
|
|
interface IOperationRequests {
|
|
getOperations: RequestDefinition<void, void, Operation[]>;
|
|
getOperationById: RequestDefinition<{ id: string }, void, Operation>;
|
|
createOperation: RequestDefinition<void, Partial<Operation>, string>;
|
|
updateOperation: RequestDefinition<{ id: string }, Partial<Operation>, void>;
|
|
deleteOperation: RequestDefinition<{ id: string }, void, void>;
|
|
}
|
|
|
|
@ImplementsRequestInterface<IOperationRequests>()
|
|
export default abstract class OperationRequests {
|
|
static async getOperations({ http }: BaseClient): Promise<AxiosResponse<Operation[], any>> {
|
|
return await http.get("/operations");
|
|
}
|
|
static async getOperationById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<Operation, any>> {
|
|
return await http.get(`/operations/${p.params.id}`);
|
|
}
|
|
static async createOperation({ http }: BaseClient, p: RequestData<void, Partial<Operation>>): Promise<AxiosResponse<string, any>> {
|
|
return await http.post("/operations", p.body);
|
|
}
|
|
static async updateOperation({ http }: BaseClient, p: RequestData<{ id: string }, Partial<Operation>>): Promise<AxiosResponse<void, any>> {
|
|
return await http.post(`/operations/${p.params.id}`, p.body);
|
|
}
|
|
static async deleteOperation({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
|
return await http.post(`/operations/${p.params.id}`);
|
|
}
|
|
}
|