|
| 1 | +import { faker } from 'https://esm.sh/@faker-js/faker' |
| 2 | +import User from '../User' |
| 3 | +import Curriculum from '../Curriculum' |
| 4 | + |
| 5 | +// Generate seed data for users |
| 6 | +const generateUsers = async (numUsers) => { |
| 7 | + try { |
| 8 | + for (let i = 0; i < numUsers; i++) { |
| 9 | + const hashedPassword = await hashPassword(faker.internet.password()) |
| 10 | + const user = new User({ |
| 11 | + name: faker.name.findName(), |
| 12 | + email: faker.internet.email(), |
| 13 | + password: hashedPassword, |
| 14 | + }) |
| 15 | + await user.save() |
| 16 | + } |
| 17 | + console.log(`${numUsers} users seeded successfully.`) |
| 18 | + } catch (error) { |
| 19 | + console.error('Error seeding users:', error) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// Generate seed data for curricula |
| 24 | +// const generateCurricula = async (numCurricula) => { |
| 25 | +// try { |
| 26 | +// for (let i = 0; i < numCurricula; i++) { |
| 27 | +// const curriculum = new Curriculum({ |
| 28 | +// title: faker.lorem.words(3), |
| 29 | +// description: faker.lorem.sentence(), |
| 30 | +// // Add any other curriculum properties you need |
| 31 | +// }) |
| 32 | +// await curriculum.save() |
| 33 | +// } |
| 34 | +// console.log(`${numCurricula} curricula seeded successfully.`) |
| 35 | +// } catch (error) { |
| 36 | +// console.error('Error seeding curricula:', error) |
| 37 | +// } |
| 38 | +// } |
| 39 | + |
| 40 | +// Call the functions to generate seed data |
| 41 | +const numUsers = 10 // Number of users to generate |
| 42 | +// const numCurricula = 5 // Number of curricula to generate |
| 43 | + |
| 44 | +generateUsers(numUsers) |
| 45 | +// generateCurricula(numCurricula) |
0 commit comments