because I got bored of customising my CV for every job
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(seed): add organization seeding

- Create 20 organizations with random names and descriptions
- Assign all users to 1-2 random organizations
- Ensure test user is created with static credentials
- Update seed service to handle organization relationships

+91 -8
+91 -8
apps/server/src/modules/seed/seed.service.ts
··· 11 11 async seed(): Promise<void> { 12 12 this.logger.log("🌱 Starting database seeding..."); 13 13 14 - // Find the existing test user 15 - const testUser = await this.prisma.user.findUnique({ 14 + // Find or create the test user 15 + let testUser = await this.prisma.user.findUnique({ 16 16 where: { email: "test@test.test" }, 17 17 }); 18 18 19 19 if (!testUser) { 20 - this.logger.error( 21 - "❌ User test@test.test not found. Please create the user first.", 22 - ); 23 - return; 20 + this.logger.log("👤 Creating test user..."); 21 + testUser = await this.prisma.user.create({ 22 + data: { 23 + email: "test@test.test", 24 + name: "Test User", 25 + password: "$2b$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", // password 26 + }, 27 + }); 28 + this.logger.log(`✅ Created test user: ${testUser.name} (${testUser.email})`); 29 + } else { 30 + this.logger.log(`✅ Found existing user: ${testUser.name} (${testUser.email})`); 24 31 } 25 - 26 - this.logger.log(`✅ Found user: ${testUser.name} (${testUser.email})`); 27 32 28 33 // Clear existing job experiences for this user only 29 34 this.logger.log("🧹 Clearing existing job experiences for test user..."); ··· 284 289 }); 285 290 } 286 291 292 + // Create organizations 293 + this.logger.log("🏢 Creating organizations..."); 294 + const organizationNames = [ 295 + "TechCorp Solutions", 296 + "Innovation Labs", 297 + "Digital Dynamics", 298 + "Future Systems", 299 + "CodeCrafters Inc", 300 + "DataFlow Technologies", 301 + "CloudScale Systems", 302 + "AgileWorks", 303 + "DevOps Masters", 304 + "AI Innovations", 305 + "Blockchain Builders", 306 + "Mobile First Co", 307 + "Web3 Pioneers", 308 + "Startup Accelerator", 309 + "Enterprise Solutions", 310 + "Open Source Foundation", 311 + "Developer Community", 312 + "Tech Mentorship Program", 313 + "Women in Tech", 314 + "Diversity in Tech", 315 + ]; 316 + 317 + const createdOrganizations = []; 318 + for (const orgName of organizationNames) { 319 + const existingOrg = await this.prisma.organization.findFirst({ 320 + where: { name: orgName }, 321 + }); 322 + 323 + if (!existingOrg) { 324 + const organization = await this.prisma.organization.create({ 325 + data: { 326 + name: orgName, 327 + description: faker.company.catchPhrase(), 328 + }, 329 + }); 330 + createdOrganizations.push(organization); 331 + } else { 332 + createdOrganizations.push(existingOrg); 333 + } 334 + } 335 + 336 + // Get all users to assign to organizations 337 + this.logger.log("👥 Assigning users to organizations..."); 338 + const allUsers = await this.prisma.user.findMany(); 339 + 340 + for (const user of allUsers) { 341 + // Each user should have 1-2 organizations, usually at least one 342 + const numOrganizations = faker.number.int({ min: 1, max: 2 }); 343 + const selectedOrganizations = faker.helpers.arrayElements(createdOrganizations, { 344 + min: 1, 345 + max: numOrganizations, 346 + }); 347 + 348 + for (const org of selectedOrganizations) { 349 + // Check if user is already in this organization 350 + const existingMembership = await this.prisma.userOrganization.findFirst({ 351 + where: { 352 + userId: user.id, 353 + organizationId: org.id, 354 + }, 355 + }); 356 + 357 + if (!existingMembership) { 358 + await this.prisma.userOrganization.create({ 359 + data: { 360 + userId: user.id, 361 + organizationId: org.id, 362 + }, 363 + }); 364 + } 365 + } 366 + } 367 + 287 368 this.logger.log("✅ Database seeding completed!"); 288 369 this.logger.log(`📊 Created job experiences for: ${testUser.name}`); 289 370 this.logger.log(` - ${createdSkills.length} skills available`); ··· 291 372 this.logger.log(` - ${createdRoles.length} roles available`); 292 373 this.logger.log(` - ${createdLevels.length} levels available`); 293 374 this.logger.log(` - ${numExperiences} job experiences created`); 375 + this.logger.log(` - ${createdOrganizations.length} organizations created`); 376 + this.logger.log(` - ${allUsers.length} users assigned to organizations`); 294 377 } 295 378 }