fix: support soft-delete user uniqueness in tools

This commit is contained in:
hectorzhao
2026-07-26 13:14:46 +08:00
parent 2ce682c3fc
commit 059b38e8fe
3 changed files with 56 additions and 43 deletions
+28 -22
View File
@@ -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' },