import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Team } from 'src/teams/entities/team.entity';
import { Repository } from 'typeorm';

@Injectable()
export class TeamsSeedService {
  constructor(
    @InjectRepository(Team)
    private repository: Repository<Team>,
  ) {}

  async run() {
    const countTeams = await this.repository.count({
      where: {
        id: 1,
      },
    });

    if (countTeams === 0) {
      await this.repository.save(
        this.repository.create({
          id: 1,
          name: 'Development Team',
          alias: '9999',
        }),
      );
    }
  }
}
