feat: implement full CRUD and administrative management endpoints for WAP servers in the sysadmin API
This commit is contained in:
@@ -2,7 +2,19 @@ import { getSysAdminNonce } from "../helpers/GetSysAdminNonce";
|
||||
import { getApiHost } from "../helpers/GetApiHost";
|
||||
import axios from "axios";
|
||||
import { getPayload } from "../helpers/GetPayload";
|
||||
import { PaginateWapServerParams, PaginateWapServerResults } from "../models/WapServers.Model";
|
||||
import {
|
||||
PaginateWapServerParams,
|
||||
PaginateWapServerResults,
|
||||
WapServerAuditResult,
|
||||
WapServerByIdParams,
|
||||
WapServerDeleteResult,
|
||||
WapServerDetachResult,
|
||||
WapServerOrganizationActionParams,
|
||||
WapServerQrResult,
|
||||
WapServerRecalculateCountResult,
|
||||
UpdateWapServerParams,
|
||||
IWapServer,
|
||||
} from "../models/WapServers.Model";
|
||||
|
||||
export class WapService {
|
||||
public async getWapServers(filters: PaginateWapServerParams): Promise<PaginateWapServerResults> {
|
||||
@@ -20,4 +32,88 @@ export class WapService {
|
||||
|
||||
return resultado;
|
||||
}
|
||||
|
||||
public async auditWapServer(data: WapServerByIdParams): Promise<WapServerAuditResult> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/audit`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
return response.data as WapServerAuditResult;
|
||||
}
|
||||
|
||||
public async updateWapServer(data: UpdateWapServerParams): Promise<IWapServer> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/update`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
return response.data as IWapServer;
|
||||
}
|
||||
|
||||
public async recalculateWapServerCount(data: WapServerByIdParams): Promise<WapServerRecalculateCountResult> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/recalculate-count`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
return response.data as WapServerRecalculateCountResult;
|
||||
}
|
||||
|
||||
public async deleteWapServer(data: WapServerByIdParams): Promise<WapServerDeleteResult> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/delete`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout: 15000,
|
||||
});
|
||||
|
||||
return response.data as WapServerDeleteResult;
|
||||
}
|
||||
|
||||
private async postBotAction<T>(path: string, data: WapServerOrganizationActionParams, timeout = 10000): Promise<T> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/bot/${path}`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout,
|
||||
});
|
||||
|
||||
return response.data as T;
|
||||
}
|
||||
|
||||
public async startBot(data: WapServerOrganizationActionParams): Promise<void> {
|
||||
await this.postBotAction("start", data);
|
||||
}
|
||||
|
||||
public async stopBot(data: WapServerOrganizationActionParams): Promise<void> {
|
||||
await this.postBotAction("stop", data);
|
||||
}
|
||||
|
||||
public async restartBot(data: WapServerOrganizationActionParams): Promise<void> {
|
||||
await this.postBotAction("restart", data, 15000);
|
||||
}
|
||||
|
||||
public async getBotQr(data: WapServerOrganizationActionParams): Promise<WapServerQrResult> {
|
||||
return await this.postBotAction<WapServerQrResult>("qr", data);
|
||||
}
|
||||
|
||||
public async deleteBot(data: WapServerOrganizationActionParams): Promise<void> {
|
||||
await this.postBotAction("delete", data);
|
||||
}
|
||||
|
||||
public async detachOrganizationServer(data: WapServerOrganizationActionParams): Promise<WapServerDetachResult> {
|
||||
return await this.postBotAction<WapServerDetachResult>("detach", data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user