feat: Introduce agent types module, replacing categories and verification modules, and updating agent-related DTOs, services, and Prisma schema.

This commit is contained in:
pradeepkumar
2026-01-20 12:16:01 +05:30
parent c04ca2bcef
commit 3df8ea067a
30 changed files with 345 additions and 1559 deletions

View File

@@ -33,18 +33,6 @@ enum AuthProvider {
TWITTER
}
enum VerificationStatus {
PENDING
APPROVED
REJECTED
}
enum VerificationDocType {
LICENSE
ID_CARD
CERTIFICATE
OTHER
}
// ===========================================
// USER - Authentication Only
@@ -120,6 +108,7 @@ model AgentProfile {
id String @id @default(uuid())
userId String @unique
slug String @unique
agentTypeId String?
// Basic Info
firstName String?
@@ -170,10 +159,10 @@ model AgentProfile {
// Relations
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
specializations AgentSpecialization[]
verificationRequests VerificationRequest[]
agentType AgentType? @relation(fields: [agentTypeId], references: [id])
@@index([userId])
@@index([agentTypeId])
@@index([slug])
@@index([city, state])
@@index([isVerified])
@@ -183,111 +172,26 @@ model AgentProfile {
}
// ===========================================
// CATEGORY - Main categories for agents
// AGENT TYPE - Dynamic agent types (Professional, Lender, etc.)
// ===========================================
model Category {
id String @id @default(uuid())
name String @unique
slug String @unique
description String?
icon String?
image String?
isActive Boolean @default(true)
sortOrder Int @default(0)
model AgentType {
id String @id @default(uuid())
name String @unique
description String?
icon String?
isActive Boolean @default(true)
sortOrder Int @default(0)
// Timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
specializations Specialization[]
agents AgentProfile[]
@@index([slug])
@@index([isActive])
@@map("categories")
}
// ===========================================
// SPECIALIZATION - Sub-categories under Category
// ===========================================
model Specialization {
id String @id @default(uuid())
categoryId String
name String
slug String @unique
description String?
isActive Boolean @default(true)
sortOrder Int @default(0)
// Timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
agents AgentSpecialization[]
@@unique([categoryId, name])
@@index([categoryId])
@@index([slug])
@@map("specializations")
}
// ===========================================
// AGENT SPECIALIZATION - Many-to-Many pivot
// ===========================================
model AgentSpecialization {
id String @id @default(uuid())
agentProfileId String
specializationId String
// Timestamps
createdAt DateTime @default(now())
// Relations
agentProfile AgentProfile @relation(fields: [agentProfileId], references: [id], onDelete: Cascade)
specialization Specialization @relation(fields: [specializationId], references: [id], onDelete: Cascade)
@@unique([agentProfileId, specializationId])
@@index([agentProfileId])
@@index([specializationId])
@@map("agent_specializations")
}
// ===========================================
// VERIFICATION REQUEST - Agent verification
// ===========================================
model VerificationRequest {
id String @id @default(uuid())
agentProfileId String
// Document Info
documentType VerificationDocType
documentUrl String
documentName String?
notes String? @db.Text
// Status
status VerificationStatus @default(PENDING)
reviewedAt DateTime?
reviewedBy String? // Admin user ID
adminNotes String? @db.Text
rejectionReason String?
// Timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relations
agentProfile AgentProfile @relation(fields: [agentProfileId], references: [id], onDelete: Cascade)
@@index([agentProfileId])
@@index([status])
@@map("verification_requests")
@@map("agent_types")
}
// ===========================================

View File

@@ -12,7 +12,48 @@ async function main() {
console.log('🌱 Starting database seeding...\n');
// Admin credentials
// =============================================
// Seed Agent Types
// =============================================
console.log('📋 Seeding Agent Types...');
const agentTypes = [
{
name: 'Professional',
description: 'Licensed real estate professionals',
icon: 'briefcase',
sortOrder: 1,
},
{
name: 'Lender',
description: 'Mortgage and loan specialists',
icon: 'bank',
sortOrder: 2,
},
];
for (const agentType of agentTypes) {
const existing = await prisma.agentType.findUnique({
where: { name: agentType.name },
});
if (existing) {
console.log(` ⚠️ Agent type "${agentType.name}" already exists`);
} else {
await prisma.agentType.create({
data: agentType,
});
console.log(` ✅ Created agent type: ${agentType.name}`);
}
}
console.log('');
// =============================================
// Seed Admin User
// =============================================
console.log('👤 Seeding Admin User...');
const adminEmail = process.env.ADMIN_EMAIL || 'admin@realestate.com';
const adminPassword = process.env.ADMIN_PASSWORD || 'Admin@123456';
@@ -25,7 +66,7 @@ async function main() {
});
if (existingAdmin) {
console.log(`⚠️ Admin user already exists: ${adminEmail}`);
console.log(` ⚠️ Admin user already exists: ${adminEmail}`);
} else {
// Create admin user
const admin = await prisma.user.create({
@@ -40,7 +81,7 @@ async function main() {
},
});
console.log('✅ Admin user created successfully!');
console.log(' ✅ Admin user created successfully!');
console.log(' ───────────────────────────────');
console.log(` 📧 Email: ${adminEmail}`);
console.log(` 🔑 Password: ${adminPassword}`);
@@ -49,13 +90,17 @@ async function main() {
console.log(' ───────────────────────────────\n');
}
// =============================================
// Summary
// =============================================
const userCount = await prisma.user.count();
const adminCount = await prisma.user.count({ where: { role: UserRole.ADMIN } });
const agentTypeCount = await prisma.agentType.count();
console.log('📊 Database Summary:');
console.log(` Total Users: ${userCount}`);
console.log(` Admins: ${adminCount}`);
console.log(` Total Users: ${userCount}`);
console.log(` Admins: ${adminCount}`);
console.log(` Agent Types: ${agentTypeCount}`);
console.log('\n🌱 Seeding completed!\n');
await prisma.$disconnect();