-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeder.ts
51 lines (47 loc) · 1.37 KB
/
seeder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { NestFactory } from '@nestjs/core';
import * as faker from 'faker';
import { AppModule } from './src/app.module';
import { UsersService } from './src/users/users.service';
import { UserRole } from './src/users/user.entity';
import { BikesService } from './src/bikes/bikes.service';
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule);
const usersService = app.get(UsersService);
const usersPromises = [];
for (let i = 0; i < 20; i++) {
usersPromises.push(
usersService.create({
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: faker.internet.email(),
password: 'P@s5word',
roles: [
faker.random.number(1) === 1 ? UserRole.MANAGER : UserRole.CLIENT,
],
isActive: true,
}),
);
}
await Promise.all(usersPromises);
const bikesService = app.get(BikesService);
const bikesPromises = [];
for (let i = 0; i < 20; i++) {
bikesPromises.push(
bikesService.create({
model: faker.company.companyName(),
color: faker.commerce.color(),
location: faker.address.city(),
}),
);
}
await Promise.all(bikesPromises);
await app.close();
}
bootstrap()
.then(() => {
console.log('seeder bootstrapped');
})
.catch((error) => {
console.log({ error });
process.exit(1);
});