Multi-environment and multi-user construction
This commit is contained in:
@@ -139,6 +139,27 @@ async function main() {
|
||||
console.log('Seeded admin user:', adminEmail, '/ demo1234');
|
||||
}
|
||||
|
||||
async function ensureMembership(
|
||||
userId: string,
|
||||
organizationId: string,
|
||||
role: 'owner' | 'admin' | 'sales' | 'support',
|
||||
) {
|
||||
await prisma.membership.upsert({
|
||||
where: { userId_organizationId: { userId, organizationId } },
|
||||
create: { userId, organizationId, role },
|
||||
update: { role },
|
||||
});
|
||||
}
|
||||
|
||||
const ownerRow = await prisma.user.findFirst({
|
||||
where: { email, organizationId: org.id },
|
||||
});
|
||||
if (ownerRow) await ensureMembership(ownerRow.id, org.id, 'owner');
|
||||
const salesRow = await prisma.user.findFirst({ where: { email: salesEmail } });
|
||||
if (salesRow) await ensureMembership(salesRow.id, org.id, 'sales');
|
||||
const adminRow = await prisma.user.findFirst({ where: { email: adminEmail } });
|
||||
if (adminRow) await ensureMembership(adminRow.id, org.id, 'admin');
|
||||
|
||||
let peopleCount = await prisma.person.count({
|
||||
where: { organizationId: org.id },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user