Add manager GraphQL endpoint
This commit is contained in:
@@ -43,16 +43,6 @@ export const userTypeDefs = `#graphql
|
||||
user: User!
|
||||
}
|
||||
|
||||
type ManagerUser {
|
||||
id: ID!
|
||||
accountId: String
|
||||
displayName: String
|
||||
phone: String!
|
||||
companyName: String
|
||||
telegramGroupTitle: String
|
||||
telegramNotificationsEnabled: Boolean!
|
||||
}
|
||||
|
||||
input RequestLoginOtpInput {
|
||||
phone: String!
|
||||
}
|
||||
@@ -62,11 +52,6 @@ export const userTypeDefs = `#graphql
|
||||
code: String!
|
||||
}
|
||||
|
||||
input ManagerTotpLoginInput {
|
||||
phone: String!
|
||||
code: String!
|
||||
}
|
||||
|
||||
type TeamMemberInfo {
|
||||
uuid: String!
|
||||
role: String!
|
||||
@@ -118,14 +103,12 @@ export const userTypeDefs = `#graphql
|
||||
|
||||
type Query {
|
||||
me: User
|
||||
managerUsers: [ManagerUser!]!
|
||||
getTeam(teamId: String!): TeamWithMembers
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
requestLoginOtp(input: RequestLoginOtpInput!): AuthChallenge!
|
||||
verifyLoginOtp(input: VerifyLoginOtpInput!): AuthPayload!
|
||||
managerTotpLogin(input: ManagerTotpLoginInput!): AuthPayload!
|
||||
logout: Boolean!
|
||||
createTeam(input: CreateTeamInput!): CreateTeamResult
|
||||
updateUser(userId: String!, input: UpdateUserInput!): UpdateUserResult
|
||||
@@ -236,31 +219,6 @@ export const userResolvers = {
|
||||
return mapProfileUser(profile)
|
||||
},
|
||||
|
||||
managerUsers: async (_: unknown, __: unknown, ctx: AuthContext) => {
|
||||
if (!ctx.userId) throw new GraphQLError('Not authenticated')
|
||||
const profile = await getOrCreateProfile(ctx.userId)
|
||||
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 },
|
||||
orderBy: { joinedAt: 'desc' },
|
||||
})
|
||||
return members.filter(member => member.user !== null).map(member => {
|
||||
const user = member.user!
|
||||
const memberProfile = user.profile
|
||||
const phone = memberProfile?.phone ?? ''
|
||||
return {
|
||||
id: member.uuid,
|
||||
accountId: memberProfile?.logtoId ?? user.username,
|
||||
displayName: displayName(user.firstName, user.lastName, phone),
|
||||
phone,
|
||||
companyName: member.team.name,
|
||||
telegramGroupTitle: null,
|
||||
telegramNotificationsEnabled: false,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getTeam: async (_: unknown, args: { teamId: string }, ctx: AuthContext) => {
|
||||
if (!ctx.userId) throw new GraphQLError('Not authenticated')
|
||||
const team = await prisma.team.findUnique({
|
||||
@@ -302,10 +260,6 @@ export const userResolvers = {
|
||||
return verifyPhoneLogin(args.input.phone, args.input.code)
|
||||
},
|
||||
|
||||
managerTotpLogin: async (_: unknown, args: { input: { phone: string; code: string } }) => {
|
||||
return verifyPhoneLogin(args.input.phone, args.input.code)
|
||||
},
|
||||
|
||||
logout: async (_: unknown, __: unknown, ctx: AuthContext) => {
|
||||
if (ctx.sessionToken !== undefined) {
|
||||
await prisma.authSession.updateMany({ where: { token: ctx.sessionToken, revokedAt: null }, data: { revokedAt: new Date() } })
|
||||
|
||||
Reference in New Issue
Block a user