fix: support soft-delete user uniqueness in tools
This commit is contained in:
@@ -25,29 +25,35 @@ async function ensureSmokeData() {
|
||||
create: { code: tenantCode, name: 'Smoke Test Enterprise', status: 'active' },
|
||||
});
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { username },
|
||||
update: {
|
||||
tenantId: tenant.id,
|
||||
email,
|
||||
phone,
|
||||
displayName: 'Smoke Client Admin',
|
||||
passwordHash: hashPassword(password),
|
||||
status: 'active',
|
||||
failedLoginCount: 0,
|
||||
lockedUntil: null,
|
||||
deletedAt: null,
|
||||
},
|
||||
create: {
|
||||
tenantId: tenant.id,
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
displayName: 'Smoke Client Admin',
|
||||
passwordHash: hashPassword(password),
|
||||
status: 'active',
|
||||
},
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: { username, deletedAt: null },
|
||||
});
|
||||
const user = existingUser
|
||||
? await prisma.user.update({
|
||||
where: { id: existingUser.id },
|
||||
data: {
|
||||
tenantId: tenant.id,
|
||||
email,
|
||||
phone,
|
||||
displayName: 'Smoke Client Admin',
|
||||
passwordHash: hashPassword(password),
|
||||
status: 'active',
|
||||
failedLoginCount: 0,
|
||||
lockedUntil: null,
|
||||
deletedAt: null,
|
||||
},
|
||||
})
|
||||
: await prisma.user.create({
|
||||
data: {
|
||||
tenantId: tenant.id,
|
||||
username,
|
||||
email,
|
||||
phone,
|
||||
displayName: 'Smoke Client Admin',
|
||||
passwordHash: hashPassword(password),
|
||||
status: 'active',
|
||||
},
|
||||
});
|
||||
|
||||
const enterpriseAdminRole = await prisma.role.upsert({
|
||||
where: { code: 'enterprise_admin' },
|
||||
|
||||
Reference in New Issue
Block a user