Skip to content

Commit

Permalink
Merge pull request #491 from sinamics/org-member-api
Browse files Browse the repository at this point in the history
Added missing values from organization - members api
  • Loading branch information
sinamics authored Aug 13, 2024
2 parents 30048ed + 3b35e68 commit 61fe2b7
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 17 deletions.
41 changes: 40 additions & 1 deletion docs/docs/Rest Api/_example/NetworkMemberExample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ NetworkMemberExample:
vMinor: 12
vProto: 12
vRev: 2
physicalAddress: null
peers:
address: "abcdef01234"
isBonded: false
latency: -1
paths: []
role: "LEAF"
tunneled: false
version: "1.12.2"
versionMajor: 1
versionMinor: 12
versionRev: 2
conStatus: 1

NetworkArrayMemberExample:
- nodeid: 1
Expand Down Expand Up @@ -63,6 +76,19 @@ NetworkArrayMemberExample:
vMinor: 12
vProto: 12
vRev: 2
physicalAddress: null
peers:
address: "abcdef01234"
isBonded: false
latency: -1
paths: []
role: "LEAF"
tunneled: false
version: "1.12.2"
versionMajor: 1
versionMinor: 12
versionRev: 2
conStatus: 1
- nodeid: 2
id: "abcdef01235"
nwid: "8056c2e21c000001"
Expand Down Expand Up @@ -93,4 +119,17 @@ NetworkArrayMemberExample:
vMajor: 1
vMinor: 12
vProto: 12
vRev: 2
vRev: 2
physicalAddress: null
peers:
address: "abcdef01234"
isBonded: false
latency: -1
paths: []
role: "LEAF"
tunneled: false
version: "1.12.2"
versionMajor: 1
versionMinor: 12
versionRev: 2
conStatus: 1
54 changes: 54 additions & 0 deletions docs/docs/Rest Api/_schema/NetworkMemberSchema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,57 @@ NetworkMemberResponse:
vRev:
type: integer
description: Revision version number
physicalAddress:
type: string
description: External ip address of the user
peers:
type: array
items:
type: object
properties:
address:
type: string
description: Address of the peer
isBonded:
type: boolean
description: Bonded status
latency:
type: integer
description: Latency
paths:
type: array
items:
type: string
description: List of paths
role:
type: string
description: Role of the peer
tunneled:
type: boolean
description: Tunneled status
version:
type: string
description: Version of the peer
versionMajor:
type: integer
description: Major version of the peer
versionMinor:
type: integer
description: Minor version of the peer
versionRev:
type: integer
description: Revision version of the peer
description: List of peers
conStatus:
type: integer
description: |
Connection status
Possible values:
* 0 - Offline: The connection is not established
* 1 - Relayed or DirectLAN: The connection is either relayed or direct within a LAN
* 2 - DirectWAN: The connection is direct over WAN
enum:
- 0
- 1
- 2

17 changes: 3 additions & 14 deletions src/pages/api/v1/org/[orgid]/network/[nwid]/member/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { decryptAndVerifyToken } from "~/utils/encryption";
import { handleApiErrors } from "~/utils/errors";
import rateLimit from "~/utils/rateLimit";
import { checkUserOrganizationRole } from "~/utils/role";
import * as ztController from "~/utils/ztApi";

// Number of allowed requests per minute
const limiter = rateLimit({
Expand Down Expand Up @@ -91,23 +90,13 @@ export const GET_orgNetworkMembers = async (

// @ts-expect-error
const caller = appRouter.createCaller(ctx);
const network = await caller.network
.getNetworkById({ nwid: networkId })
.then(async (res) => {
return res.network || null;
});
const response = await caller.network.getNetworkById({ nwid: networkId });

if (!network) {
if (!response?.network) {
return res.status(401).json({ error: "Network not found or access denied." });
}

const ztControllerResponse = await ztController.local_network_detail(
//@ts-expect-error
ctx,
networkId,
false,
);
return res.status(200).json(ztControllerResponse?.members);
return res.status(200).json(response?.members);
} catch (cause) {
return handleApiErrors(cause, res);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/api/routers/memberRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const networkMemberRouter = createTRPCRouter({
where: {
id_nwid: {
id: input.id,
nwid: input.nwid, // this should be the value of `nwid` you are looking for
nwid: input.nwid,
},
},
});
Expand All @@ -114,7 +114,7 @@ export const networkMemberRouter = createTRPCRouter({
where: {
id_nwid: {
id: input.id,
nwid: input.nwid, // this should be the value of `nwid` you are looking for
nwid: input.nwid,
},
},
data: {
Expand Down

0 comments on commit 61fe2b7

Please sign in to comment.