Skip to content

Commit

Permalink
check db then controller for node name
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Dec 16, 2024
1 parent 11ba4a3 commit 12d8079
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions src/server/api/services/memberService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,37 +121,55 @@ const findExistingMemberName = async (
organizationId?: string,
) => {
try {
if (isOrganization && organizationId) {
// For organization networks, search in database
const existingMember = await prisma.network_members.findFirst({
where: {
id: memberId,
name: { not: null },
deleted: false,
nwid: { not: currentNwid },
nwid_ref: {
organizationId: organizationId,
},
},
select: { name: true },
orderBy: {
creationTime: "desc",
},
});
return existingMember?.name || null;
// First check database for existing name
const whereClause =
isOrganization && organizationId
? {
id: memberId,
name: { not: null },
deleted: false,
nwid: { not: currentNwid },
nwid_ref: {
organizationId: organizationId,
},
}
: {
id: memberId,
name: { not: null },
deleted: false,
nwid: { not: currentNwid },
nwid_ref: {
authorId: ctx.session.user.id,
organizationId: null,
},
};

const existingMember = await prisma.network_members.findFirst({
where: whereClause,
select: { name: true },
orderBy: {
creationTime: "desc",
},
});

if (existingMember?.name) {
return existingMember.name;
}
// For private networks, use controller API

// If no name found in database, check controller
const networks = await ztController.get_controller_networks(ctx, false);

const relevantNetworks = await prisma.network.findMany({
where: {
AND: [
{ nwid: { in: networks as string[] } },
{ nwid: { not: currentNwid } },
{
authorId: ctx.session.user.id,
organizationId: null,
},
isOrganization && organizationId
? { organizationId: organizationId }
: {
authorId: ctx.session.user.id,
organizationId: null,
},
],
},
select: { nwid: true },
Expand Down

0 comments on commit 12d8079

Please sign in to comment.