Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { UserRole, BookStatus } from '../../common/enums';
- import { createConnection } from 'typeorm';
- import { User, Role } from '../entities';
- import * as bcrypt from 'bcrypt';
- // tslint:disable: no-console
- const main = async () => {
- const connection = await createConnection();
- const rolesRepository = connection.getRepository(Role);
- const usersRepository = connection.getRepository(User);
- // Creating roles
- const adminRole = await rolesRepository.save({
- name: UserRole.Admin,
- });
- const basicRole = await rolesRepository.save({
- name: UserRole.Basic,
- });
- // Creating roles
- // Creating the first admin
- const firstAdmin = usersRepository.create();
- firstAdmin.username = 'scarlet';
- firstAdmin.password = await bcrypt.hash('123456789', 10);
- firstAdmin.role = adminRole;
- await usersRepository.save(firstAdmin);
- // Creating the first admin
- console.log(`Data seeded successfully`);
- };
- main().catch(console.error);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement