Advertisement
nikolayneykov

Untitled

Oct 3rd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { UserRole, BookStatus } from '../../common/enums';
  2. import { createConnection } from 'typeorm';
  3. import { User, Role } from '../entities';
  4. import * as bcrypt from 'bcrypt';
  5.  
  6. // tslint:disable: no-console
  7. const main = async () => {
  8.   const connection = await createConnection();
  9.   const rolesRepository = connection.getRepository(Role);
  10.   const usersRepository = connection.getRepository(User);
  11.  
  12.   // Creating roles
  13.  
  14.   const adminRole = await rolesRepository.save({
  15.     name: UserRole.Admin,
  16.   });
  17.  
  18.   const basicRole = await rolesRepository.save({
  19.     name: UserRole.Basic,
  20.   });
  21.  
  22.   // Creating roles
  23.  
  24.  
  25.   // Creating the first admin
  26.   const firstAdmin = usersRepository.create();
  27.  
  28.   firstAdmin.username = 'scarlet';
  29.   firstAdmin.password = await bcrypt.hash('123456789', 10);
  30.   firstAdmin.role = adminRole;
  31.  
  32.   await usersRepository.save(firstAdmin);
  33.   // Creating the first admin
  34.  
  35.   console.log(`Data seeded successfully`);
  36. };
  37.  
  38. main().catch(console.error);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement