76 lines
1.6 KiB
TypeScript
76 lines
1.6 KiB
TypeScript
import { Api } from "./api.class";
|
|
|
|
export class Command {
|
|
constructor(private api: Api) {}
|
|
|
|
async create(
|
|
projectToken: string,
|
|
source: string,
|
|
isTypescript: number = 0,
|
|
isPublic: number = 0
|
|
): Promise<any> {
|
|
const response = await this.api.createRequestWithAuthHeaders(
|
|
`${this.api.getUrl()}/command/create`,
|
|
"POST",
|
|
{
|
|
source,
|
|
isTypescript,
|
|
isPublic,
|
|
projectToken,
|
|
}
|
|
);
|
|
|
|
return response.data;
|
|
}
|
|
|
|
async update(
|
|
id: string,
|
|
updateData: Partial<{
|
|
source: string;
|
|
isTypescript?: number;
|
|
isPublic?: number;
|
|
}>
|
|
): Promise<any> {
|
|
const response = await this.api.createRequestWithAuthHeaders(
|
|
`${this.api.getUrl()}/command/update/${id}`,
|
|
"POST",
|
|
updateData
|
|
);
|
|
|
|
return response.data;
|
|
}
|
|
|
|
async run(
|
|
id: string,
|
|
query: Record<string, any>,
|
|
headers: Record<string, any> = {},
|
|
isPublic: boolean = false
|
|
): Promise<any> {
|
|
const response = await this.api.createRequestWithAuthHeaders(
|
|
`${this.api.getUrl()}/command/${isPublic ? "run-public" : "run"}/${id}`,
|
|
"POST",
|
|
query,
|
|
headers
|
|
);
|
|
|
|
return response.data;
|
|
}
|
|
|
|
runPublic(
|
|
id: string,
|
|
query: Record<string, any>,
|
|
headers: Record<string, any> = {}
|
|
): Promise<any> {
|
|
return this.run(id, query, headers, true);
|
|
}
|
|
|
|
async delete(id: string): Promise<any> {
|
|
const response = await this.api.createRequestWithAuthHeaders(
|
|
`${this.api.getUrl()}/command/delete/${id}`,
|
|
"DELETE"
|
|
);
|
|
|
|
return response.data;
|
|
}
|
|
}
|