Skip to content

Commit

Permalink
network description
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Sep 2, 2024
1 parent 480cc46 commit 8954aad
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/pages/api/v1/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,41 @@ const GET_userNetworks = SecuredPrivateApiRoute(
},
async (_req, res, { ctx, userId }) => {
try {
const networks = await prisma.user.findFirst({
const userWithNetworks = await prisma.user.findUnique({
where: {
id: userId,
},
select: {
network: true,
network: {
select: {
nwid: true,
description: true,
authorId: true,
},
},
},
});
const arr = [];
// biome-ignore lint/correctness/noUnsafeOptionalChaining: <explanation>
for (const network of networks?.network) {
const ztControllerResponse = await ztController.local_network_detail(
//@ts-expect-error
ctx,
network.nwid,
false,
);
arr.push(ztControllerResponse.network);

if (!userWithNetworks || !userWithNetworks.network) {
return res.status(404).json({ error: "User or networks not found" });
}

return res.status(200).json(arr);
const networksWithDetails = await Promise.all(
userWithNetworks.network.map(async (network) => {
const ztControllerResponse = await ztController.local_network_detail(
//@ts-expect-error
ctx,
network.nwid,
false,
);
return {
...network,
...ztControllerResponse.network,
};
}),
);

return res.status(200).json(networksWithDetails);
} catch (cause) {
return handleApiErrors(cause, res);
}
Expand Down

0 comments on commit 8954aad

Please sign in to comment.