feat: implement create functionality for WapServers across server, sysadmin, and CLI layers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from "axios";
|
||||
import { Request, Response } from "express";
|
||||
import { WapService } from "../services/wap.service";
|
||||
import { PaginateWapServerParams, UpdateWapServerParams, WapServerByIdParams, WapServerOrganizationActionParams } from "src/models/WapServers.Model";
|
||||
import { CreateWapServerParams, PaginateWapServerParams, UpdateWapServerParams, WapServerByIdParams, WapServerOrganizationActionParams } from "src/models/WapServers.Model";
|
||||
|
||||
const wapService = new WapService();
|
||||
|
||||
@@ -58,6 +58,17 @@ export class WapController {
|
||||
}
|
||||
};
|
||||
|
||||
public createServer = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const result = await wapService.createWapServer(req.body as CreateWapServerParams);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
console.error("Error creating wap server:", error);
|
||||
const message = getErrorMessage(error);
|
||||
res.status(getErrorStatus(error)).json({ success: false, message, desc: message });
|
||||
}
|
||||
};
|
||||
|
||||
public recalculateCount = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const data: WapServerByIdParams = req.body as WapServerByIdParams;
|
||||
|
||||
@@ -33,6 +33,16 @@ export type UpdateWapServerParams = {
|
||||
active?: boolean;
|
||||
};
|
||||
|
||||
export type CreateWapServerParams = {
|
||||
name: string;
|
||||
ipv4: string;
|
||||
port: number;
|
||||
maxBots: number;
|
||||
ipv6?: string;
|
||||
description?: string;
|
||||
active?: boolean;
|
||||
};
|
||||
|
||||
export type PaginateWapServerParams = FindWapServerParams & {
|
||||
page: number;
|
||||
limit: number;
|
||||
|
||||
@@ -5,6 +5,7 @@ const router = Router();
|
||||
const wapController = new WapController();
|
||||
|
||||
router.post("/paginate", wapController.getServers);
|
||||
router.post("/create", wapController.createServer);
|
||||
router.post("/update", wapController.updateServer);
|
||||
router.post("/audit", wapController.auditServer);
|
||||
router.post("/recalculate-count", wapController.recalculateCount);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getApiHost } from "../helpers/GetApiHost";
|
||||
import axios from "axios";
|
||||
import { getPayload } from "../helpers/GetPayload";
|
||||
import {
|
||||
CreateWapServerParams,
|
||||
PaginateWapServerParams,
|
||||
PaginateWapServerResults,
|
||||
WapServerAuditResult,
|
||||
@@ -45,6 +46,18 @@ export class WapService {
|
||||
return response.data as WapServerAuditResult;
|
||||
}
|
||||
|
||||
public async createWapServer(data: CreateWapServerParams): Promise<IWapServer> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
const response = await axios.post(`${getApiHost()}/sysadmin/wapserver/create`, postData, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
return response.data as IWapServer;
|
||||
}
|
||||
|
||||
public async updateWapServer(data: UpdateWapServerParams): Promise<IWapServer> {
|
||||
const nonce = await getSysAdminNonce();
|
||||
const postData = { ...data, ...{ payload: getPayload(nonce) } };
|
||||
|
||||
Reference in New Issue
Block a user