69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { PrismaClient, Roles } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
// base sans underscore, en string
|
|
const BASE_PHONE = "1100000000";
|
|
|
|
function emailFor(i: number) {
|
|
return `user${i + 1}@example.test`;
|
|
}
|
|
|
|
async function main() {
|
|
const usersData: {
|
|
first_name: string;
|
|
last_name: string;
|
|
email: string;
|
|
phone_number: string;
|
|
residence?: string | null;
|
|
role: Roles;
|
|
}[] = [];
|
|
|
|
const firstNames = ['Alex','Sam','Chris','Jordan','Taylor','Morgan','Jamie','Robin','Avery','Casey'];
|
|
const lastNames = ['Smith','Johnson','Williams','Brown','Jones','Miller','Davis','Wilson','Taylor','Clark'];
|
|
|
|
const pick = <T>(arr: T[]) => arr[Math.floor(Math.random() * arr.length)];
|
|
|
|
const rolesForEmployees: Roles[] = [
|
|
Roles.ADMIN,
|
|
...Array(4).fill(Roles.SUPERVISOR),
|
|
Roles.HR,
|
|
Roles.ACCOUNTING,
|
|
...Array(33).fill(Roles.EMPLOYEE),
|
|
];
|
|
|
|
// 40 employees
|
|
for (let i = 0; i < 40; i++) {
|
|
const fn = pick(firstNames);
|
|
const ln = pick(lastNames);
|
|
usersData.push({
|
|
first_name: fn,
|
|
last_name: ln,
|
|
email: emailFor(i),
|
|
// on concatène proprement en string
|
|
phone_number: BASE_PHONE + i.toString(),
|
|
residence: Math.random() < 0.5 ? 'QC' : 'ON',
|
|
role: rolesForEmployees[i],
|
|
});
|
|
}
|
|
|
|
// 10 customers
|
|
for (let i = 40; i < 50; i++) {
|
|
const fn = pick(firstNames);
|
|
const ln = pick(lastNames);
|
|
usersData.push({
|
|
first_name: fn,
|
|
last_name: ln,
|
|
email: emailFor(i),
|
|
phone_number: BASE_PHONE + i.toString(),
|
|
residence: Math.random() < 0.5 ? 'QC' : 'ON',
|
|
role: Roles.CUSTOMER,
|
|
});
|
|
}
|
|
|
|
await prisma.users.createMany({ data: usersData, skipDuplicates: true });
|
|
console.log('✓ Users: 50 rows (40 employees, 10 customers)');
|
|
}
|
|
|
|
main().finally(() => prisma.$disconnect());
|