mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 14:12:10 +01:00
fix: resolve user invitation unique constraint error and add integration tests
- Fix platform user invitation to handle global email uniqueness properly - Replace findFirst with findUnique for email validation - Add clear error messages for email conflicts across companies - Create comprehensive CSV import workflow integration tests - Create comprehensive session processing pipeline integration tests - Cover end-to-end flows from import to AI analysis completion
This commit is contained in:
@ -51,19 +51,36 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
|
||||
// Check if user already exists in this company
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
// Check if user already exists (emails must be globally unique)
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: {
|
||||
email,
|
||||
companyId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
companyId: true,
|
||||
company: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
return NextResponse.json(
|
||||
{ error: "User already exists in this company" },
|
||||
{ status: 400 }
|
||||
);
|
||||
if (existingUser.companyId === companyId) {
|
||||
return NextResponse.json(
|
||||
{ error: "User already exists in this company" },
|
||||
{ status: 400 }
|
||||
);
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: `Email already in use by a user in company: ${existingUser.company.name}. Each email address can only be used once across all companies.`
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a temporary password (in a real app, you'd send an invitation email)
|
||||
|
||||
Reference in New Issue
Block a user