From 2b378d0d6f7c3f1e2bec24501dea48c2ad4099ce Mon Sep 17 00:00:00 2001 From: tm-sanjay Date: Fri, 6 Jan 2023 14:01:49 +0530 Subject: [PATCH] responce added to apis --- src/lib/WireGuard.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 2c71af3d..704ff622 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -292,25 +292,35 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; if (config.clients[clientId]) { delete config.clients[clientId]; await this.saveConfig(); + return {status: 'Client Deleted'}; } + return {status: 'Client Not Found'}; } async enableClient({ clientId }) { const client = await this.getClient({ clientId }); - client.enabled = true; - client.updatedAt = new Date(); + if (client) { + client.enabled = true; + client.updatedAt = new Date(); - await this.saveConfig(); + await this.saveConfig(); + return {status: 'Client Enabled'}; + } + return {status: 'Client Not Found'}; } async disableClient({ clientId }) { const client = await this.getClient({ clientId }); - client.enabled = false; - client.updatedAt = new Date(); + if (client) { + client.enabled = false; + client.updatedAt = new Date(); - await this.saveConfig(); + await this.saveConfig(); + return {status: 'Client Disabled'}; + } + return {status: 'Client Not Found'}; } async updateClientName({ clientId, name }) { @@ -320,6 +330,8 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; client.updatedAt = new Date(); await this.saveConfig(); + + return {status: 'Client Name Updated'}; } async updateClientAddress({ clientId, address }) { @@ -333,6 +345,8 @@ Endpoint = ${WG_HOST}:${WG_PORT}`; client.updatedAt = new Date(); await this.saveConfig(); + + return {status: 'Client Address Updated'}; } };