feat: implement core API classes for project, database, query, command, functions, and redis management
This commit is contained in:
75
src/classes/command.class.ts
Normal file
75
src/classes/command.class.ts
Normal file
@ -0,0 +1,75 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user