This commit is contained in:
+24
-19
@@ -1,7 +1,7 @@
|
||||
import { GraphQLError } from 'graphql'
|
||||
import { randomUUID, createHash } from 'crypto'
|
||||
import { prisma } from '../db.js'
|
||||
import { requireScopes, type AuthContext } from '../auth.js'
|
||||
import { startAddressWorkflow, startInviteWorkflow } from '../services/temporal.js'
|
||||
|
||||
export const teamTypeDefs = `#graphql
|
||||
type TeamUser {
|
||||
@@ -204,13 +204,26 @@ export const teamResolvers = {
|
||||
inviteMember: async (_: unknown, args: { input: { email: string; role?: string } }, ctx: AuthContext) => {
|
||||
requireScopes(ctx, 'teams:member')
|
||||
if (!ctx.teamUuid || !ctx.userId) throw new GraphQLError('Not authenticated')
|
||||
try {
|
||||
await startInviteWorkflow(ctx.teamUuid, args.input.email, args.input.role || 'MEMBER', ctx.userId)
|
||||
return { success: true, message: 'Invitation workflow started' }
|
||||
} catch (e) {
|
||||
console.error('Failed to start invite workflow:', e)
|
||||
return { success: false, message: String(e) }
|
||||
}
|
||||
const team = await prisma.team.findUnique({ where: { uuid: ctx.teamUuid } })
|
||||
if (!team) throw new GraphQLError('Team not found')
|
||||
const invitation = await prisma.teamInvitation.create({
|
||||
data: {
|
||||
teamId: team.id,
|
||||
email: args.input.email,
|
||||
role: args.input.role || 'MEMBER',
|
||||
invitedBy: ctx.userId,
|
||||
status: 'PENDING',
|
||||
},
|
||||
})
|
||||
const token = randomUUID()
|
||||
await prisma.teamInvitationToken.create({
|
||||
data: {
|
||||
invitationId: invitation.id,
|
||||
tokenHash: createHash('sha256').update(token).digest('hex'),
|
||||
workflowStatus: 'active',
|
||||
},
|
||||
})
|
||||
return { success: true, message: 'Invitation created' }
|
||||
},
|
||||
|
||||
createTeamAddress: async (_: unknown, args: { input: { name: string; address: string; latitude?: number; longitude?: number; countryCode?: string; isDefault?: boolean } }, ctx: AuthContext) => {
|
||||
@@ -223,19 +236,11 @@ export const teamResolvers = {
|
||||
teamId: team.id, name: args.input.name, address: args.input.address,
|
||||
latitude: args.input.latitude, longitude: args.input.longitude,
|
||||
countryCode: args.input.countryCode || '', isDefault: args.input.isDefault || false,
|
||||
status: 'active',
|
||||
processedAt: new Date(),
|
||||
},
|
||||
})
|
||||
try {
|
||||
const wfId = await startAddressWorkflow(
|
||||
ctx.teamUuid, addr.uuid, addr.name, addr.address,
|
||||
addr.latitude ?? undefined, addr.longitude ?? undefined,
|
||||
addr.countryCode || undefined, addr.isDefault,
|
||||
)
|
||||
return { success: true, message: 'Address created', workflowId: wfId }
|
||||
} catch (e) {
|
||||
console.error('Failed to start address workflow:', e)
|
||||
return { success: true, message: 'Address created but workflow failed', workflowId: null }
|
||||
}
|
||||
return { success: true, message: 'Address created', workflowId: null }
|
||||
},
|
||||
|
||||
updateTeamAddress: async (_: unknown, args: { input: { uuid: string; name?: string; address?: string; latitude?: number; longitude?: number; countryCode?: string; isDefault?: boolean } }, ctx: AuthContext) => {
|
||||
|
||||
Reference in New Issue
Block a user