Configuring access rights in the CRM Super Admin

This commit is contained in:
2026-09-20 11:24:14 +03:30
parent 04d37a9d12
commit 4a9fe0b07c
29 changed files with 1235 additions and 35 deletions
+38 -4
View File
@@ -44,9 +44,19 @@ async function seedPlatformAdmin() {
return;
}
const passwordHash = await bcrypt.hash(password, 10);
const existingByMobile = await prisma.platformAdmin.findUnique({ where: { mobile } });
if (existingByMobile) {
console.log('Platform admin exists:', mobile);
await prisma.platformAdmin.update({
where: { id: existingByMobile.id },
data: {
passwordHash,
fullName: envName,
isActive: true,
...(email ? { email } : {}),
},
});
console.log('Platform admin password refreshed:', mobile);
return;
}
if (email) {
@@ -54,14 +64,38 @@ async function seedPlatformAdmin() {
if (existingByEmail) {
await prisma.platformAdmin.update({
where: { id: existingByEmail.id },
data: { mobile, ...(envName ? { fullName: envName } : {}) },
data: {
mobile,
passwordHash,
fullName: envName,
isActive: true,
},
});
console.log('Platform admin linked mobile:', mobile, '→', email);
console.log('Platform admin linked mobile + password refreshed:', mobile, '→', email);
return;
}
}
const passwordHash = await bcrypt.hash(password, 10);
const orphans = await prisma.platformAdmin.findMany({
where: { mobile: null },
take: 2,
});
if (orphans.length === 1) {
const orphan = orphans[0]!;
await prisma.platformAdmin.update({
where: { id: orphan.id },
data: {
mobile,
passwordHash,
fullName: envName,
isActive: true,
...(email ? { email } : {}),
},
});
console.log('Platform admin orphan linked mobile:', mobile);
return;
}
await prisma.platformAdmin.create({
data: {
mobile,