|
| 1 | +import { Faker } from '@faker-js/faker'; |
| 2 | +import { Prisma, Team_Type } from '@prisma/client'; |
| 3 | +import type { FullUser } from '../context.js'; |
| 4 | + |
| 5 | +const SLACK_ID_RANDOM_LENGTH = 4; |
| 6 | + |
| 7 | +export type SeedTeamConfig = { |
| 8 | + teamName: string; |
| 9 | + description: string; |
| 10 | + teamTypeName: string; |
| 11 | + financeTeam?: boolean; |
| 12 | +}; |
| 13 | + |
| 14 | +export const seedTeamConfigs: SeedTeamConfig[] = [ |
| 15 | + { |
| 16 | + teamName: 'Mechanical', |
| 17 | + description: 'Designs and manufactures mechanical systems for the car.', |
| 18 | + teamTypeName: 'Mechanical' |
| 19 | + }, |
| 20 | + { |
| 21 | + teamName: 'Powertrain', |
| 22 | + description: 'Develops drivetrain and high-voltage powertrain systems.', |
| 23 | + teamTypeName: 'Electrical' |
| 24 | + }, |
| 25 | + { |
| 26 | + teamName: 'Electrical', |
| 27 | + description: 'Builds and maintains the car electrical architecture.', |
| 28 | + teamTypeName: 'Electrical' |
| 29 | + }, |
| 30 | + { |
| 31 | + teamName: 'Software', |
| 32 | + description: 'Develops FinishLine, telemetry, and vehicle software.', |
| 33 | + teamTypeName: 'Software' |
| 34 | + }, |
| 35 | + { |
| 36 | + teamName: 'Embedded Systems', |
| 37 | + description: 'Works on firmware and embedded controls.', |
| 38 | + teamTypeName: 'Software' |
| 39 | + }, |
| 40 | + { |
| 41 | + teamName: 'Controls', |
| 42 | + description: 'Develops vehicle control systems and performance tools.', |
| 43 | + teamTypeName: 'Software' |
| 44 | + }, |
| 45 | + { |
| 46 | + teamName: 'Battery', |
| 47 | + description: 'Designs and validates the battery pack and accumulator systems.', |
| 48 | + teamTypeName: 'Electrical' |
| 49 | + }, |
| 50 | + { |
| 51 | + teamName: 'Aerodynamics', |
| 52 | + description: 'Designs aero components and validates vehicle airflow.', |
| 53 | + teamTypeName: 'Mechanical' |
| 54 | + }, |
| 55 | + { |
| 56 | + teamName: 'Chassis', |
| 57 | + description: 'Develops the frame and structural systems.', |
| 58 | + teamTypeName: 'Mechanical' |
| 59 | + }, |
| 60 | + { |
| 61 | + teamName: 'Suspension', |
| 62 | + description: 'Designs suspension geometry and handling systems.', |
| 63 | + teamTypeName: 'Mechanical' |
| 64 | + }, |
| 65 | + { |
| 66 | + teamName: 'Brakes', |
| 67 | + description: 'Develops braking systems and pedal box components.', |
| 68 | + teamTypeName: 'Mechanical' |
| 69 | + }, |
| 70 | + { |
| 71 | + teamName: 'Composites', |
| 72 | + description: 'Manufactures composite bodywork and structural parts.', |
| 73 | + teamTypeName: 'Mechanical' |
| 74 | + }, |
| 75 | + { |
| 76 | + teamName: 'Manufacturing', |
| 77 | + description: 'Coordinates machining, fabrication, and shop work.', |
| 78 | + teamTypeName: 'Mechanical' |
| 79 | + }, |
| 80 | + { |
| 81 | + teamName: 'Operations', |
| 82 | + description: 'Coordinates logistics, planning, and internal processes.', |
| 83 | + teamTypeName: 'Business' |
| 84 | + }, |
| 85 | + { |
| 86 | + teamName: 'Finance', |
| 87 | + description: 'Manages purchasing, reimbursements, budgeting, and sponsor funds.', |
| 88 | + teamTypeName: 'Business', |
| 89 | + financeTeam: true |
| 90 | + }, |
| 91 | + { |
| 92 | + teamName: 'Sponsorship', |
| 93 | + description: 'Manages sponsor outreach and sponsor relationships.', |
| 94 | + teamTypeName: 'Business' |
| 95 | + }, |
| 96 | + { |
| 97 | + teamName: 'Marketing', |
| 98 | + description: 'Creates team media, branding, and public-facing content.', |
| 99 | + teamTypeName: 'Business' |
| 100 | + }, |
| 101 | + { |
| 102 | + teamName: 'Recruitment', |
| 103 | + description: 'Supports recruiting, onboarding, and member engagement.', |
| 104 | + teamTypeName: 'Business' |
| 105 | + }, |
| 106 | + { |
| 107 | + teamName: 'Data Acquisition', |
| 108 | + description: 'Builds telemetry, sensors, and data analysis tools.', |
| 109 | + teamTypeName: 'Electrical' |
| 110 | + }, |
| 111 | + { |
| 112 | + teamName: 'Driver Interface', |
| 113 | + description: 'Develops cockpit, dashboard, and driver-facing controls.', |
| 114 | + teamTypeName: 'Electrical' |
| 115 | + } |
| 116 | +]; |
| 117 | + |
| 118 | +const connectUsers = (users: FullUser[]) => users.map((user) => ({ userId: user.userId })); |
| 119 | + |
| 120 | +const slackIdForTeam = (faker: Faker, teamName: string): string => { |
| 121 | + const slug = teamName.toLowerCase().replaceAll(' ', '-').replaceAll('/', '-'); |
| 122 | + |
| 123 | + return `seed-${slug}-${faker.string.alphanumeric(SLACK_ID_RANDOM_LENGTH).toLowerCase()}`; |
| 124 | +}; |
| 125 | + |
| 126 | +const findTeamType = (teamTypesByName: Record<string, Team_Type>, teamTypeName: string): Team_Type => { |
| 127 | + const teamType = teamTypesByName[teamTypeName]; |
| 128 | + |
| 129 | + if (!teamType) { |
| 130 | + throw new Error(`Missing team type: ${teamTypeName}`); |
| 131 | + } |
| 132 | + |
| 133 | + return teamType; |
| 134 | +}; |
| 135 | + |
| 136 | +export const teamCreateInput = ( |
| 137 | + faker: Faker, |
| 138 | + organizationId: string, |
| 139 | + head: FullUser, |
| 140 | + leads: FullUser[], |
| 141 | + members: FullUser[], |
| 142 | + teamTypesByName: Record<string, Team_Type>, |
| 143 | + config: SeedTeamConfig, |
| 144 | + overrides: Partial<Prisma.TeamCreateInput> = {} |
| 145 | +): Prisma.TeamCreateInput => { |
| 146 | + const teamType = findTeamType(teamTypesByName, config.teamTypeName); |
| 147 | + |
| 148 | + return { |
| 149 | + teamName: config.teamName, |
| 150 | + slackId: slackIdForTeam(faker, config.teamName), |
| 151 | + description: config.description, |
| 152 | + financeTeam: config.financeTeam ?? false, |
| 153 | + head: { |
| 154 | + connect: { userId: head.userId } |
| 155 | + }, |
| 156 | + leads: { |
| 157 | + connect: connectUsers(leads) |
| 158 | + }, |
| 159 | + members: { |
| 160 | + connect: connectUsers(members) |
| 161 | + }, |
| 162 | + teamType: { |
| 163 | + connect: { teamTypeId: teamType.teamTypeId } |
| 164 | + }, |
| 165 | + organization: { |
| 166 | + connect: { organizationId } |
| 167 | + }, |
| 168 | + ...overrides |
| 169 | + }; |
| 170 | +}; |
0 commit comments