From 71bb2e951b722b32e4de24c2c3f1b5ffae8a211f Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev Date: Sun, 31 May 2026 21:36:19 +0500 Subject: [PATCH] Expose manager session flag --- src/schemas/user.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/schemas/user.ts b/src/schemas/user.ts index dd0c04f..3159481 100644 --- a/src/schemas/user.ts +++ b/src/schemas/user.ts @@ -23,7 +23,8 @@ export const userTypeDefs = `#graphql displayName: String phone: String avatarId: String - isAdmin: Boolean + isManager: Boolean + isAdmin: Boolean @deprecated(reason: "Use isManager") activeTeamId: String activeTeam: UserTeam teams: [UserTeam] @@ -171,7 +172,7 @@ async function getOrCreateProfileByPhone(phone: string) { }) } -async function isAdminUser(userId: number): Promise { +async function isManagerUser(userId: number): Promise { const user = await prisma.user.findUnique({ where: { id: userId } }) if (user === null) return false if (user.isStaff || user.isSuperuser) return true @@ -183,6 +184,7 @@ async function isAdminUser(userId: number): Promise { async function mapProfileUser(profile: Awaited>) { const memberships = await prisma.teamMember.findMany({ where: { userId: profile.userId }, include: { team: true } }) + const isManager = await isManagerUser(profile.userId) return { id: profile.logtoId, firstName: profile.user.firstName, @@ -190,7 +192,8 @@ async function mapProfileUser(profile: Awaited ({ id: m.team.uuid, name: m.team.name, teamType: m.team.teamType, logtoOrgId: m.team.logtoOrgId, createdAt: m.team.createdAt.toISOString() })), @@ -238,7 +241,7 @@ export const userResolvers = { managerUsers: async (_: unknown, __: unknown, ctx: AuthContext) => { if (!ctx.userId) throw new GraphQLError('Not authenticated') const profile = await getOrCreateProfile(ctx.userId) - if (!(await isAdminUser(profile.userId))) return [] + if (!(await isManagerUser(profile.userId))) return [] const members = await prisma.teamMember.findMany({ where: profile.activeTeamId === null ? {} : { teamId: profile.activeTeamId }, include: { user: { include: { profile: { include: { activeTeam: true } } } }, team: true },