import { createConnection, getRepository } from 'typeorm'
import { Horario } from './entity/Horario'
import { Mesa } from './entity/Mesa'

createConnection()
  .then(async (connection) => {
    const horarioRepository = getRepository(Horario)
    const mesaRepository = getRepository(Mesa)
    const horarios = [
      '8:00-10:00',
      '10:00-12:00',
      '12:00-14:00',
      '14:00-16:00',
      '16:00-18:00',
      '18:00-20:00'
    ]
    for (let index = 0; index < horarios.length; index++) {
      const horario = new Horario()
      horario.hora = horarios[index]
      console.log(horario)
      await horarioRepository.save(horario)
    }
    for (let i = 1; i < 30; i++) {
      const mesa = new Mesa()
      mesa.nombre = String(i)
      await mesaRepository.save(mesa)
    }

    process.exit()
  })
  .catch((error) => console.log('TypeORM connection error: ', error))
