Skip to content

Commit

Permalink
controller precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Sep 5, 2024
1 parent 433df5c commit bf237f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const POST_orgUpdateNetworkMember = SecuredOrganizationApiRoute(
where: {
id_nwid: {
id: memberId,
nwid: networkId, // this should be the value of `nwid` you are looking for
nwid: networkId,
},
},
data: {
Expand Down Expand Up @@ -225,14 +225,24 @@ export const GET_orgNetworkMemberById = SecuredOrganizationApiRoute(
const validatedContext = HandlerContextSchema.parse(context);
const { networkId, memberId, ctx } = validatedContext;

const controllerMember = await ztController.local_network_detail(
// @ts-expect-error: fake request object
ctx,
networkId,
false,
);

const findControllermemberById = controllerMember.members.find(
(member) => member.id === memberId,
);
// @ts-expect-error
const caller = appRouter.createCaller(ctx);
const networkAndMembers = await caller.networkMember.getMemberById({
nwid: networkId,
id: memberId,
});

return res.status(200).json(networkAndMembers);
return res.status(200).json({ ...networkAndMembers, ...findControllermemberById });
} catch (cause) {
return handleApiErrors(cause, res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test("updateDatabaseOnly test", async () => {
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
2 changes: 1 addition & 1 deletion src/server/api/routers/memberRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const networkMemberRouter = createTRPCRouter({
const dbMember = await ctx.prisma.network_members.findFirst({
where: {
id: input.id,
nwid: input.nwid, // this should be the value of `nwid` you are looking for
nwid: input.nwid,
},
});
return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ztApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ export const member_details = async (

return await getData<MemberEntity>(addr, headers);
} catch (error) {
const message = `${error} (member_details)`;
const message = "Member not found!";
throw new APIError(message, error as AxiosError);
}
};
Expand Down

0 comments on commit bf237f3

Please sign in to comment.