2025-02-05 14:29:09 +01:00
|
|
|
import { AxiosResponse } from "axios";
|
|
|
|
import { RequestDefinition, RequestData, ImplementsRequestInterface } from "../requestBase";
|
|
|
|
import { CreateQueryViewModel, QueryExecuteResult, QueryViewModel, UpdateQueryViewModel } from "../../viewmodels/admin/query.models";
|
|
|
|
import { DynamicQueryStructure } from "../../types/admin/dynamicQueries";
|
|
|
|
import { BaseClient } from "../../clients/clientBase";
|
|
|
|
|
2025-03-26 11:50:54 +01:00
|
|
|
interface GetQueryParams {
|
|
|
|
offset?: number;
|
|
|
|
count?: number;
|
|
|
|
noLimit?: boolean;
|
|
|
|
}
|
|
|
|
|
2025-02-05 14:29:09 +01:00
|
|
|
interface IQueryRequests {
|
|
|
|
getQueries: RequestDefinition<void, void, QueryViewModel[]>;
|
2025-04-14 09:33:30 +02:00
|
|
|
getQueryById: RequestDefinition<{ id: string }, void, QueryViewModel>;
|
|
|
|
createQuery: RequestDefinition<void, CreateQueryViewModel, string>;
|
|
|
|
updateQuery: RequestDefinition<{ id: string }, UpdateQueryViewModel, void>;
|
|
|
|
deleteQuery: RequestDefinition<{ id: string }, void, void>;
|
2025-02-05 14:29:09 +01:00
|
|
|
|
2025-03-26 11:50:54 +01:00
|
|
|
executeQuery: RequestDefinition<GetQueryParams, DynamicQueryStructure | string, QueryExecuteResult>;
|
2025-04-14 09:33:30 +02:00
|
|
|
executeQueryByQueryStoreId: RequestDefinition<GetQueryParams & { storeId: string }, void, QueryExecuteResult>;
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ImplementsRequestInterface<IQueryRequests>()
|
|
|
|
export default abstract class QueryDataRequests {
|
|
|
|
static async getQueries({ http }: BaseClient): Promise<AxiosResponse<QueryViewModel[], any>> {
|
2025-04-14 09:33:30 +02:00
|
|
|
return await http.get("/admin/querystore");
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
2025-04-14 09:33:30 +02:00
|
|
|
static async getQueryById({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<QueryViewModel, any>> {
|
|
|
|
return await http.get(`/admin/querystore/${p.params.id}`);
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
2025-04-14 09:33:30 +02:00
|
|
|
static async createQuery({ http }: BaseClient, p: RequestData<void, CreateQueryViewModel>): Promise<AxiosResponse<string, any>> {
|
|
|
|
return await http.post("/admin/querystore", p.body);
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
2025-04-14 09:33:30 +02:00
|
|
|
static async updateQuery({ http }: BaseClient, p: RequestData<{ id: string }, UpdateQueryViewModel>): Promise<AxiosResponse<void, any>> {
|
|
|
|
return await http.post(`/admin/querystore/${p.params.id}`, p.body);
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
2025-04-14 09:33:30 +02:00
|
|
|
static async deleteQuery({ http }: BaseClient, p: RequestData<{ id: string }, void>): Promise<AxiosResponse<void, any>> {
|
|
|
|
return await http.post(`/admin/querystore/${p.params.id}`);
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static async executeQuery(
|
|
|
|
{ http }: BaseClient,
|
2025-03-26 11:50:54 +01:00
|
|
|
p: RequestData<GetQueryParams, DynamicQueryStructure | string | "member" | "memberByRunningMembership">
|
2025-02-05 14:29:09 +01:00
|
|
|
): Promise<AxiosResponse<QueryExecuteResult, any>> {
|
2025-03-26 11:50:54 +01:00
|
|
|
const queryParams = new URLSearchParams(Object.fromEntries(Object.entries(p.params).filter(([_, v]) => v !== undefined))).toString();
|
|
|
|
return await http.post(`/admin/query?${queryParams}`, p.body);
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|
2025-04-14 09:33:30 +02:00
|
|
|
static async executeQueryByQueryStoreId(
|
|
|
|
{ http }: BaseClient,
|
|
|
|
p: RequestData<GetQueryParams & { storeId: string }, void>
|
|
|
|
): Promise<AxiosResponse<QueryExecuteResult, any>> {
|
|
|
|
const queryParams = new URLSearchParams(
|
|
|
|
Object.fromEntries(Object.entries(p.params).filter(([k, v]) => v !== undefined && k != "storeId"))
|
|
|
|
).toString();
|
|
|
|
return await http.post(`/admin/query/${p.params.storeId}?${queryParams}`);
|
|
|
|
}
|
2025-02-05 14:29:09 +01:00
|
|
|
}
|