91 lines
2.0 KiB
TypeScript
91 lines
2.0 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { TeamRole } from 'src/team-roles/entities/team-roles.entity';
|
|
import { TeamRolesEnum } from 'src/team-roles/team-roles.enum';
|
|
import { Repository } from 'typeorm';
|
|
|
|
@Injectable()
|
|
export class TeamRoleSeedService {
|
|
constructor(
|
|
@InjectRepository(TeamRole)
|
|
private repository: Repository<TeamRole>,
|
|
) {}
|
|
|
|
async run() {
|
|
const countPlayer = await this.repository.count({
|
|
where: {
|
|
id: TeamRolesEnum.player,
|
|
},
|
|
});
|
|
|
|
if (countPlayer === 0) {
|
|
await this.repository.save(
|
|
this.repository.create({
|
|
id: TeamRolesEnum.player,
|
|
name: 'player',
|
|
}),
|
|
);
|
|
}
|
|
|
|
const countScndTr = await this.repository.count({
|
|
where: {
|
|
id: TeamRolesEnum.scnd_treasurer,
|
|
},
|
|
});
|
|
|
|
if (countScndTr === 0) {
|
|
await this.repository.save(
|
|
this.repository.create({
|
|
id: TeamRolesEnum.scnd_treasurer,
|
|
name: 'scnd_treasurer',
|
|
}),
|
|
);
|
|
}
|
|
|
|
const countCaptain = await this.repository.count({
|
|
where: {
|
|
id: TeamRolesEnum.captain,
|
|
},
|
|
});
|
|
|
|
if (countCaptain === 0) {
|
|
await this.repository.save(
|
|
this.repository.create({
|
|
id: TeamRolesEnum.captain,
|
|
name: 'captain',
|
|
}),
|
|
);
|
|
}
|
|
|
|
const countTreasurer = await this.repository.count({
|
|
where: {
|
|
id: TeamRolesEnum.treasurer,
|
|
},
|
|
});
|
|
|
|
if (countTreasurer === 0) {
|
|
await this.repository.save(
|
|
this.repository.create({
|
|
id: TeamRolesEnum.treasurer,
|
|
name: 'treasurer',
|
|
}),
|
|
);
|
|
}
|
|
|
|
const countCoach = await this.repository.count({
|
|
where: {
|
|
id: TeamRolesEnum.coach,
|
|
},
|
|
});
|
|
|
|
if (countCoach === 0) {
|
|
await this.repository.save(
|
|
this.repository.create({
|
|
id: TeamRolesEnum.coach,
|
|
name: 'coach',
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
}
|