mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 07:52:10 +01:00
feat: implement platform management system with authentication and dashboard
- Add PlatformUser model with roles (SUPER_ADMIN, ADMIN, SUPPORT) - Implement platform authentication with NextAuth - Create platform dashboard showing companies, users, and sessions - Add platform API endpoints for company management - Update landing page with SaaS design - Include test improvements and accessibility updates
This commit is contained in:
@ -9,6 +9,22 @@ datasource db {
|
||||
directUrl = env("DATABASE_URL_DIRECT")
|
||||
}
|
||||
|
||||
/// *
|
||||
/// * PLATFORM USER (super-admin for Notso AI)
|
||||
/// * Platform-level users who can manage companies and platform-wide settings
|
||||
/// * Separate from Company users for platform management isolation
|
||||
model PlatformUser {
|
||||
id String @id @default(uuid())
|
||||
email String @unique @db.VarChar(255) /// Platform user email address
|
||||
password String @db.VarChar(255) /// Hashed password for platform authentication
|
||||
role PlatformUserRole @default(ADMIN) /// Platform permission level
|
||||
name String @db.VarChar(255) /// Display name for platform user
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
||||
updatedAt DateTime @updatedAt @db.Timestamptz(6)
|
||||
|
||||
@@index([email])
|
||||
}
|
||||
|
||||
/// *
|
||||
/// * COMPANY (multi-tenant root)
|
||||
/// * Root entity for multi-tenant architecture
|
||||
@ -16,6 +32,7 @@ datasource db {
|
||||
model Company {
|
||||
id String @id @default(uuid())
|
||||
name String @db.VarChar(255) /// Company name for display and filtering
|
||||
status CompanyStatus @default(ACTIVE) /// Company status for suspension/activation
|
||||
csvUrl String @db.Text /// URL endpoint for CSV data import
|
||||
csvUsername String? @db.VarChar(255) /// Optional HTTP auth username for CSV endpoint
|
||||
csvPassword String? @db.VarChar(255) /// Optional HTTP auth password for CSV endpoint
|
||||
@ -28,6 +45,7 @@ model Company {
|
||||
users User[] @relation("CompanyUsers") /// Users belonging to this company
|
||||
|
||||
@@index([name])
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
/// *
|
||||
@ -269,6 +287,13 @@ model CompanyAIModel {
|
||||
/// * ENUMS – typed constants for better data integrity
|
||||
///
|
||||
|
||||
/// Platform-level user roles for Notso AI team
|
||||
enum PlatformUserRole {
|
||||
SUPER_ADMIN /// Full platform access, can create/suspend companies
|
||||
ADMIN /// Platform administration, company management
|
||||
SUPPORT /// Customer support access, read-only company access
|
||||
}
|
||||
|
||||
/// User permission levels within a company
|
||||
enum UserRole {
|
||||
ADMIN /// Full access to company data and settings
|
||||
@ -276,6 +301,14 @@ enum UserRole {
|
||||
AUDITOR /// Read-only access for compliance and auditing
|
||||
}
|
||||
|
||||
/// Company operational status
|
||||
enum CompanyStatus {
|
||||
ACTIVE /// Company is operational and can access all features
|
||||
SUSPENDED /// Company access is temporarily disabled
|
||||
TRIAL /// Company is in trial period with potential limitations
|
||||
ARCHIVED /// Company is archived and data is read-only
|
||||
}
|
||||
|
||||
/// AI-determined sentiment categories for sessions
|
||||
enum SentimentCategory {
|
||||
POSITIVE /// Customer expressed satisfaction or positive emotions
|
||||
|
||||
63
prisma/seed-platform.ts
Normal file
63
prisma/seed-platform.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import { PrismaClient, PlatformUserRole } from "@prisma/client";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("🚀 Seeding platform users for Notso AI...");
|
||||
|
||||
// Create initial platform admin user
|
||||
const adminPassword = await bcrypt.hash("NotsoAI2024!Admin", 12);
|
||||
|
||||
const admin = await prisma.platformUser.upsert({
|
||||
where: { email: "admin@notso.ai" },
|
||||
update: {},
|
||||
create: {
|
||||
email: "admin@notso.ai",
|
||||
password: adminPassword,
|
||||
name: "Platform Administrator",
|
||||
role: PlatformUserRole.SUPER_ADMIN,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("✅ Created platform super admin:", admin.email);
|
||||
|
||||
// Create support user
|
||||
const supportPassword = await bcrypt.hash("NotsoAI2024!Support", 12);
|
||||
|
||||
const support = await prisma.platformUser.upsert({
|
||||
where: { email: "support@notso.ai" },
|
||||
update: {},
|
||||
create: {
|
||||
email: "support@notso.ai",
|
||||
password: supportPassword,
|
||||
name: "Support Team",
|
||||
role: PlatformUserRole.SUPPORT,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("✅ Created platform support user:", support.email);
|
||||
|
||||
console.log("\n🔑 Platform Login Credentials:");
|
||||
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
console.log("Super Admin:");
|
||||
console.log(" Email: admin@notso.ai");
|
||||
console.log(" Password: NotsoAI2024!Admin");
|
||||
console.log("");
|
||||
console.log("Support:");
|
||||
console.log(" Email: support@notso.ai");
|
||||
console.log(" Password: NotsoAI2024!Support");
|
||||
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
console.log("\n🌐 Platform Access:");
|
||||
console.log(" Login: http://localhost:3000/platform/login");
|
||||
console.log(" Dashboard: http://localhost:3000/platform/dashboard");
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error("❌ Platform seeding failed:", e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user