@natrave/shared-entities 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.changeset/README.md +9 -0
  2. package/.changeset/config.json +11 -0
  3. package/.github/workflows/release.yml +80 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.husky/pre-push +4 -0
  6. package/.lintstagedrc.json +5 -0
  7. package/.prettierignore +2 -0
  8. package/.prettierrc.json +12 -0
  9. package/CHANGELOG.md +13 -0
  10. package/eslint.config.js +84 -0
  11. package/package.json +52 -0
  12. package/src/app-auth/index.ts +5 -0
  13. package/src/app-auth/password-resets/index.ts +1 -0
  14. package/src/app-auth/password-resets/password-reset.entity.ts +52 -0
  15. package/src/app-auth/refresh-tokens/index.ts +1 -0
  16. package/src/app-auth/refresh-tokens/refresh-token.entity.ts +52 -0
  17. package/src/app-auth/user-auth-providers/enums/auth-provider.enum.ts +24 -0
  18. package/src/app-auth/user-auth-providers/index.ts +3 -0
  19. package/src/app-auth/user-auth-providers/user-auth-provider.entity.ts +58 -0
  20. package/src/app-auth/user-verifications/enums/verification-type.enum.ts +19 -0
  21. package/src/app-auth/user-verifications/index.ts +3 -0
  22. package/src/app-auth/user-verifications/user-verification.entity.ts +62 -0
  23. package/src/app-auth/users/index.ts +1 -0
  24. package/src/app-auth/users/user.entity.ts +149 -0
  25. package/src/app-auth/users/utils/format-data.utils.ts +38 -0
  26. package/src/common/utils/decimal-transformer.utils.ts +13 -0
  27. package/src/facilities/addresses/address.entity.ts +82 -0
  28. package/src/facilities/addresses/index.ts +1 -0
  29. package/src/facilities/facilities/enums/facility-status.enum.ts +25 -0
  30. package/src/facilities/facilities/facility.entity.ts +137 -0
  31. package/src/facilities/facilities/index.ts +3 -0
  32. package/src/facilities/facilities/utils/sanititze.utils.ts +19 -0
  33. package/src/facilities/facility-images/facility-image.entity.ts +64 -0
  34. package/src/facilities/facility-images/index.ts +1 -0
  35. package/src/facilities/facility-owners/facility-owner.entity.ts +74 -0
  36. package/src/facilities/facility-owners/index.ts +1 -0
  37. package/src/facilities/facility-owners/utils/sanitize.utils.ts +16 -0
  38. package/src/facilities/fields/enums/surface-type.enum.ts +35 -0
  39. package/src/facilities/fields/field.entity.ts +74 -0
  40. package/src/facilities/fields/index.ts +3 -0
  41. package/src/facilities/index.ts +5 -0
  42. package/src/index.ts +7 -0
  43. package/src/payments/index.ts +5 -0
  44. package/src/payments/payment-providers/enums/payment-provider-name.enum.ts +15 -0
  45. package/src/payments/payment-providers/index.ts +3 -0
  46. package/src/payments/payment-providers/payment-provider.entity.ts +61 -0
  47. package/src/payments/payments/enums/payment-method.enum.ts +20 -0
  48. package/src/payments/payments/enums/payment-status.enum.ts +45 -0
  49. package/src/payments/payments/index.ts +5 -0
  50. package/src/payments/payments/payment.entity.ts +84 -0
  51. package/src/payments/user-payment-providers/index.ts +1 -0
  52. package/src/payments/user-payment-providers/user-payment-provider.entity.ts +73 -0
  53. package/src/tournaments/index.ts +12 -0
  54. package/src/tournaments/tournament-facilities/index.ts +1 -0
  55. package/src/tournaments/tournament-facilities/tournament-facility.entity.ts +67 -0
  56. package/src/tournaments/tournament-format-configs/index.ts +1 -0
  57. package/src/tournaments/tournament-format-configs/tournament-format-config.entity.ts +69 -0
  58. package/src/tournaments/tournament-match-cards/index.ts +1 -0
  59. package/src/tournaments/tournament-match-cards/tournament-match-card.entity.ts +86 -0
  60. package/src/tournaments/tournament-match-goals/index.ts +1 -0
  61. package/src/tournaments/tournament-match-goals/tournament-match-goal.entity.ts +88 -0
  62. package/src/tournaments/tournament-match-schemas/index.ts +1 -0
  63. package/src/tournaments/tournament-match-schemas/tournament-match-schema.entity.ts +51 -0
  64. package/src/tournaments/tournament-matches/index.ts +1 -0
  65. package/src/tournaments/tournament-matches/tournament-match.entity.ts +101 -0
  66. package/src/tournaments/tournament-payments/index.ts +1 -0
  67. package/src/tournaments/tournament-payments/tournament-payment.entity.ts +67 -0
  68. package/src/tournaments/tournament-players/index.ts +1 -0
  69. package/src/tournaments/tournament-players/tournament-player.entity.ts +96 -0
  70. package/src/tournaments/tournament-prize-rules/index.ts +1 -0
  71. package/src/tournaments/tournament-prize-rules/tournament-prize-rule.entity.ts +65 -0
  72. package/src/tournaments/tournament-rules/index.ts +1 -0
  73. package/src/tournaments/tournament-rules/tournament-rule.entity.ts +81 -0
  74. package/src/tournaments/tournament-teams/index.ts +1 -0
  75. package/src/tournaments/tournament-teams/tournament-team.entity.ts +111 -0
  76. package/src/tournaments/tournament-teams/utils/invite-code-generator.ts +12 -0
  77. package/src/tournaments/tournaments/index.ts +1 -0
  78. package/src/tournaments/tournaments/tournament.entity.ts +153 -0
  79. package/tsconfig.json +29 -0
@@ -0,0 +1,88 @@
1
+ import { ITournamentMatchGoal, MatchPeriod } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ Index,
9
+ ManyToOne,
10
+ JoinColumn,
11
+ } from 'typeorm';
12
+
13
+ import { TournamentMatch } from 'tournaments/tournament-matches';
14
+ import { TournamentPlayer } from 'tournaments/tournament-players';
15
+ import { TournamentTeam } from 'tournaments/tournament-teams';
16
+
17
+ /**
18
+ * Entidade que representa um gol marcado em uma partida do campeonato.
19
+ *
20
+ * @remarks
21
+ * Esta entidade armazena os dados de um gol, incluindo o identificador do time que marcou,
22
+ * o identificador da partida, o minuto (opcional), o período da partida (opcional),
23
+ * os identificadores do jogador que marcou e do jogador que fez a assistência (opcionais),
24
+ * além das datas de criação e atualização do registro.
25
+ *
26
+ * @public
27
+ */
28
+ @Entity('tournament_match_goals')
29
+ @Index(['teamId'])
30
+ @Index(['matchId'])
31
+ export class TournamentMatchGoal implements ITournamentMatchGoal {
32
+ @PrimaryGeneratedColumn()
33
+ id: number;
34
+
35
+ @Column({ name: 'team_id', type: 'int' })
36
+ teamId: number;
37
+
38
+ @Column({ name: 'match_id', type: 'int' })
39
+ matchId: number;
40
+
41
+ @Column({ type: 'int', nullable: true })
42
+ minute?: number;
43
+
44
+ @Column({ type: 'enum', enum: MatchPeriod, nullable: true })
45
+ period?: MatchPeriod;
46
+
47
+ @Column({ name: 'scorer_id', type: 'int', nullable: true })
48
+ scorerId?: number;
49
+
50
+ @Column({ name: 'assist_id', type: 'int', nullable: true })
51
+ assistId?: number;
52
+
53
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
54
+ createdAt: Date;
55
+
56
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
57
+ updatedAt: Date;
58
+
59
+ /** RELAÇÕES */
60
+
61
+ /**
62
+ * Relação com o time associado ao gol.
63
+ */
64
+ @ManyToOne(() => TournamentTeam, (team) => team.goals, { onDelete: 'CASCADE' })
65
+ @JoinColumn({ name: 'team_id' })
66
+ team?: TournamentTeam;
67
+
68
+ /**
69
+ * Relação com a partida associada ao gol.
70
+ */
71
+ @ManyToOne(() => TournamentMatch, (match) => match.goals, { onDelete: 'CASCADE' })
72
+ @JoinColumn({ name: 'team_id' })
73
+ match?: TournamentMatch;
74
+
75
+ /**
76
+ * Relação com o jogador autor do gol associado ao evento de gol.
77
+ */
78
+ @ManyToOne(() => TournamentPlayer, (team) => team.goals, { onDelete: 'CASCADE' })
79
+ @JoinColumn({ name: 'scorer_id' })
80
+ scorer?: TournamentPlayer;
81
+
82
+ /**
83
+ * Relação com o jogador autor da assistencia associado ao evento de gol.
84
+ */
85
+ @ManyToOne(() => TournamentPlayer, (team) => team.assists, { onDelete: 'CASCADE' })
86
+ @JoinColumn({ name: 'assist_id' })
87
+ assist?: TournamentPlayer;
88
+ }
@@ -0,0 +1 @@
1
+ export { TournamentMatchSchema } from './tournament-match-schema.entity';
@@ -0,0 +1,51 @@
1
+ import { ITournamentMatchSchema } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ Index,
9
+ OneToMany,
10
+ } from 'typeorm';
11
+
12
+ import { Tournament } from 'tournaments/tournaments';
13
+
14
+ /**
15
+ * Entidade que representa um esquema de partidas de torneio.
16
+ *
17
+ * @remarks
18
+ * Esta entidade armazena os dados referentes a um esquema de partidas, como o nome, descrição
19
+ * e quantidade de jogadores por equipe, além das datas de criação e atualização do registro.
20
+ *
21
+ * @public
22
+ */
23
+ @Entity('tournament_match_schemas')
24
+ @Index(['name'])
25
+ export class TournamentMatchSchema implements ITournamentMatchSchema {
26
+ @PrimaryGeneratedColumn()
27
+ id: number;
28
+
29
+ @Column({ type: 'varchar', length: 100 })
30
+ name: string;
31
+
32
+ @Column({ type: 'varchar', length: 255, nullable: true })
33
+ description?: string;
34
+
35
+ @Column({ type: 'int', name: 'players_per_team' })
36
+ playersPerTeam: number;
37
+
38
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
39
+ createdAt: Date;
40
+
41
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
42
+ updatedAt: Date;
43
+
44
+ /** RELAÇÕES */
45
+
46
+ /**
47
+ * Relação com os campeonatos associadas ao esquema de partidas.
48
+ */
49
+ @OneToMany(() => Tournament, (tournament) => tournament.matchSchema)
50
+ tournaments: Tournament[];
51
+ }
@@ -0,0 +1 @@
1
+ export { TournamentMatch } from './tournament-match.entity';
@@ -0,0 +1,101 @@
1
+ import { ITournamentMatch } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ ManyToOne,
9
+ JoinColumn,
10
+ OneToMany,
11
+ } from 'typeorm';
12
+
13
+ import { Field } from 'facilities';
14
+ import { TournamentMatchCard } from 'tournaments/tournament-match-cards';
15
+ import { TournamentMatchGoal } from 'tournaments/tournament-match-goals';
16
+ import { TournamentTeam } from 'tournaments/tournament-teams';
17
+ import { Tournament } from 'tournaments/tournaments';
18
+
19
+ /**
20
+ * Entidade que representa uma partida de torneio.
21
+ *
22
+ * @remarks
23
+ * Esta entidade armazena os dados de uma partida de torneio, incluindo os identificadores dos times (casa e visitante),
24
+ * o identificador do campo (opcional), a data do jogo e as datas de criação e atualização do registro.
25
+ *
26
+ * @public
27
+ */
28
+ @Entity('tournament_matches')
29
+ export class TournamentMatch implements ITournamentMatch {
30
+ @PrimaryGeneratedColumn()
31
+ id: number;
32
+
33
+ @Column({ name: 'tournament_id', type: 'int' })
34
+ tournamentId: number;
35
+
36
+ @Column({ name: 'home_team_id', type: 'int' })
37
+ homeTeamId: number;
38
+
39
+ @Column({ name: 'away_team_id', type: 'int' })
40
+ awayTeamId: number;
41
+
42
+ @Column({ name: 'field_id', type: 'int', nullable: true })
43
+ fieldId?: number;
44
+
45
+ @Column({ name: 'match_date', type: 'timestamptz' })
46
+ matchDate: Date;
47
+
48
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
49
+ createdAt: Date;
50
+
51
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
52
+ updatedAt: Date;
53
+
54
+ /** RELAÇÕES */
55
+
56
+ /**
57
+ * Relação com o campo ao qual a partida esta associada.
58
+ */
59
+ @ManyToOne(() => Field, (field) => field.tournamentMatches, { onDelete: 'SET NULL' })
60
+ @JoinColumn({ name: 'field_id' })
61
+ field?: Field;
62
+
63
+ /**
64
+ * Relação com o campeonato ao qual a partida esta associada.
65
+ */
66
+ @ManyToOne(() => Tournament, (tournament) => tournament.matches, {
67
+ onDelete: 'CASCADE',
68
+ })
69
+ @JoinColumn({ name: 'tournament_id' })
70
+ tournament: Tournament;
71
+
72
+ /**
73
+ * Relação com o time da casa ao qual a partida esta associada.
74
+ */
75
+ @ManyToOne(() => TournamentTeam, (team) => team.homeMatches, {
76
+ onDelete: 'CASCADE',
77
+ })
78
+ @JoinColumn({ name: 'home_team_id' })
79
+ homeTeam: TournamentTeam;
80
+
81
+ /**
82
+ * Relação com o time visitante ao qual a partida esta associada.
83
+ */
84
+ @ManyToOne(() => TournamentTeam, (team) => team.awayMatches, {
85
+ onDelete: 'CASCADE',
86
+ })
87
+ @JoinColumn({ name: 'away_team_id' })
88
+ awayTeam: TournamentTeam;
89
+
90
+ /**
91
+ * Relação com os gols associados a partida.
92
+ */
93
+ @OneToMany(() => TournamentMatchGoal, (goal) => goal.match)
94
+ goals: TournamentMatchGoal[];
95
+
96
+ /**
97
+ * Relação com os cartões associados a partida.
98
+ */
99
+ @OneToMany(() => TournamentMatchCard, (card) => card.match)
100
+ cards: TournamentMatchCard[];
101
+ }
@@ -0,0 +1 @@
1
+ export { TournamentPayment } from './tournament-payment.entity';
@@ -0,0 +1,67 @@
1
+ import { ITournamentPayment } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ ManyToOne,
9
+ JoinColumn,
10
+ } from 'typeorm';
11
+
12
+ import { User } from 'app-auth';
13
+ import { Payment } from 'payments';
14
+ import { Tournament } from 'tournaments/tournaments';
15
+
16
+ /**
17
+ * Entidade que representa um pagamento realizado para um torneio.
18
+ *
19
+ * @remarks
20
+ * Esta entidade armazena os dados do pagamento associado a um torneio,
21
+ * vinculando o pagamento a um usuário e ao torneio correspondente.
22
+ *
23
+ * @public
24
+ */
25
+ @Entity('tournament_payments')
26
+ export class TournamentPayment implements ITournamentPayment {
27
+ @PrimaryGeneratedColumn('uuid')
28
+ id: string;
29
+
30
+ @Column({ name: 'payment_id', type: 'int' })
31
+ paymentId: number;
32
+
33
+ @Column({ name: 'tournament_id', type: 'int' })
34
+ tournamentId: number;
35
+
36
+ @Column({ name: 'user_id', type: 'uuid' })
37
+ userId: string;
38
+
39
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
40
+ createdAt: Date;
41
+
42
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
43
+ updatedAt: Date;
44
+
45
+ /** RELAÇÕES */
46
+
47
+ /**
48
+ * Relação com o usuário ao qual o pagamento esta associado.
49
+ */
50
+ @ManyToOne(() => User, { onDelete: 'CASCADE' })
51
+ @JoinColumn({ name: 'user_id' })
52
+ user: User;
53
+
54
+ /**
55
+ * Relação com o pagamento ao qual o pagamento do torneio esta associado.
56
+ */
57
+ @ManyToOne(() => Payment, { onDelete: 'CASCADE', eager: true })
58
+ @JoinColumn({ name: 'payment_id' })
59
+ payment: Payment;
60
+
61
+ /**
62
+ * Relação com o torneio ao qual o pagamento do torneio esta associado.
63
+ */
64
+ @ManyToOne(() => Tournament, { onDelete: 'CASCADE' })
65
+ @JoinColumn({ name: 'tournament_id' })
66
+ tournament: Tournament;
67
+ }
@@ -0,0 +1 @@
1
+ export { TournamentPlayer } from './tournament-player.entity';
@@ -0,0 +1,96 @@
1
+ import { ITournamentPlayer } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ ManyToOne,
9
+ JoinColumn,
10
+ Unique,
11
+ Index,
12
+ OneToMany,
13
+ } from 'typeorm';
14
+
15
+ import { User } from 'app-auth';
16
+ import { TournamentMatchCard } from 'tournaments/tournament-match-cards';
17
+ import { TournamentMatchGoal } from 'tournaments/tournament-match-goals';
18
+ import { TournamentTeam } from 'tournaments/tournament-teams';
19
+
20
+ /**
21
+ * Entidade que representa um jogador de torneio.
22
+ *
23
+ * @remarks
24
+ * Esta entidade associa um usuário a um time em um torneio e indica se o usuário é o dono do time.
25
+ *
26
+ * São utilizados:
27
+ * - Uma restrição única para garantir que um usuário não seja associado a mais de um time no mesmo torneio.
28
+ * - Índices em "userId" e "teamId" para otimizar consultas.
29
+ *
30
+ * @public
31
+ */
32
+ @Entity('tournament_players')
33
+ @Unique(['userId', 'teamId'])
34
+ @Index('IDX_user_id', ['userId'])
35
+ @Index('IDX_team_id', ['teamId'])
36
+ export class TournamentPlayer implements ITournamentPlayer {
37
+ @PrimaryGeneratedColumn()
38
+ id: number;
39
+
40
+ @Column({ name: 'user_id', type: 'uuid' })
41
+ userId: string;
42
+
43
+ @Column({ name: 'team_id', type: 'int' })
44
+ teamId: number;
45
+
46
+ @Column({ name: 'is_owner', type: 'boolean', default: false })
47
+ isOwner: boolean;
48
+
49
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
50
+ createdAt: Date;
51
+
52
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
53
+ updatedAt: Date;
54
+
55
+ /** RELAÇÕES */
56
+
57
+ /**
58
+ * Relação com o time ao qual o jogador esta associado.
59
+ */
60
+
61
+ @ManyToOne(() => TournamentTeam, (team) => team.players, {
62
+ onDelete: 'CASCADE',
63
+ eager: true,
64
+ })
65
+ @JoinColumn({ name: 'team_id' })
66
+ team: TournamentTeam;
67
+
68
+ /**
69
+ * Relação com o usuário ao qual os jogador esta associado.
70
+ */
71
+
72
+ @ManyToOne(() => User, (user) => user.tournamentPlayers, {
73
+ onDelete: 'CASCADE',
74
+ eager: true,
75
+ })
76
+ @JoinColumn({ name: 'user_id' })
77
+ user: User;
78
+
79
+ /**
80
+ * Relação com os gols associados ao jogador.
81
+ */
82
+ @OneToMany(() => TournamentMatchGoal, (goal) => goal.scorer)
83
+ goals: TournamentMatchGoal[];
84
+
85
+ /**
86
+ * Relação com as assistências associados ao jogador.
87
+ */
88
+ @OneToMany(() => TournamentMatchGoal, (goal) => goal.assist)
89
+ assists: TournamentMatchGoal[];
90
+
91
+ /**
92
+ * Relação com os cartões associados ao jogador.
93
+ */
94
+ @OneToMany(() => TournamentMatchCard, (card) => card.player)
95
+ cards: TournamentMatchCard[];
96
+ }
@@ -0,0 +1 @@
1
+ export { TournamentPrizeRule } from './tournament-prize-rule.entity';
@@ -0,0 +1,65 @@
1
+ import { ITournamentPrizeRule } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ Index,
9
+ Check,
10
+ ManyToOne,
11
+ JoinColumn,
12
+ } from 'typeorm';
13
+
14
+ import { Tournament } from 'tournaments/tournaments';
15
+
16
+ /**
17
+ * Entidade que representa as regras de premiação para torneios.
18
+ *
19
+ * @remarks
20
+ * Esta entidade armazena o valor do prêmio, a classificação associada e, opcionalmente, uma descrição,
21
+ * garantindo que o valor do prêmio e a classificação sejam não-negativos.
22
+ *
23
+ * São utilizados:
24
+ * - Um índice composto em [tournamentId, rank] para otimizar consultas por torneio e posição.
25
+ * - Check constraints para assegurar que "amount" e "rank" sejam maiores ou iguais a zero.
26
+ *
27
+ * @public
28
+ */
29
+ @Entity('tournament_prize_rules')
30
+ @Index(['tournamentId', 'rank'])
31
+ @Check('CHK_TOURNAMENT_PRIZE_RULES_NON_NEGATIVE', 'amount >= 0 AND rank >= 0')
32
+ export class TournamentPrizeRule implements ITournamentPrizeRule {
33
+ @PrimaryGeneratedColumn()
34
+ id: number;
35
+
36
+ @Column({ name: 'tournament_id', type: 'int' })
37
+ tournamentId: number;
38
+
39
+ @Column({ type: 'int' })
40
+ amount: number;
41
+
42
+ @Column({ type: 'int' })
43
+ rank: number;
44
+
45
+ @Column({ type: 'varchar', length: 255, nullable: true })
46
+ description?: string;
47
+
48
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
49
+ createdAt: Date;
50
+
51
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
52
+ updatedAt: Date;
53
+
54
+ /** RELAÇÕES */
55
+
56
+ /**
57
+ * Relação com o torneio ao qual as regras estão associadas.
58
+ */
59
+
60
+ @ManyToOne(() => Tournament, (tournament) => tournament.prizeRules, {
61
+ onDelete: 'CASCADE',
62
+ })
63
+ @JoinColumn({ name: 'tournament_id' })
64
+ tournament: Tournament;
65
+ }
@@ -0,0 +1 @@
1
+ export { TournamentRule } from './tournament-rule.entity';
@@ -0,0 +1,81 @@
1
+ import { ITournamentRule } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ JoinColumn,
9
+ Check,
10
+ OneToOne,
11
+ } from 'typeorm';
12
+
13
+ import { Tournament } from 'tournaments/tournaments';
14
+
15
+ /**
16
+ * Entidade que representa as regras de um torneio.
17
+ *
18
+ * @remarks
19
+ * Esta entidade armazena os limites de jogadores por time, faixas etárias, número mínimo e máximo de times,
20
+ * além de informações adicionais, como observações e URL do regulamento em PDF.
21
+ *
22
+ * @public
23
+ */
24
+ @Entity('tournament_rules')
25
+ @Check('CHK_TEAMS', '"max_teams" >= "min_teams"')
26
+ @Check('CHK_PLAYERS_PER_TEAM', '"max_player_per_team" >= "min_player_per_team"')
27
+ @Check('CHK_MIN_AGE', '"min_age" >= 0')
28
+ @Check('CHK_MAX_AGE', '"max_age" IS NULL OR "max_age" > "min_age"')
29
+ export class TournamentRule implements ITournamentRule {
30
+ @PrimaryGeneratedColumn()
31
+ id: number;
32
+
33
+ @Column({ name: 'tournament_id', type: 'int', unique: true })
34
+ tournamentId: number;
35
+
36
+ @Column({ name: 'max_player_per_team', type: 'int' })
37
+ maxPlayerPerTeam: number;
38
+
39
+ @Column({ name: 'min_player_per_team', type: 'int' })
40
+ minPlayerPerTeam: number;
41
+
42
+ @Column({ name: 'min_age', type: 'int' })
43
+ minAge: number;
44
+
45
+ @Column({ name: 'max_age', type: 'int', nullable: true })
46
+ maxAge?: number;
47
+
48
+ @Column({ name: 'min_teams', type: 'int' })
49
+ minTeams: number;
50
+
51
+ @Column({ name: 'max_teams', type: 'int' })
52
+ maxTeams: number;
53
+
54
+ @Column({ type: 'varchar', length: 255, nullable: true })
55
+ notes?: string;
56
+
57
+ @Column({
58
+ name: 'regulation_pdf_url',
59
+ type: 'varchar',
60
+ length: 500,
61
+ nullable: true,
62
+ })
63
+ regulationPdfUrl?: string;
64
+
65
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
66
+ createdAt: Date;
67
+
68
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
69
+ updatedAt: Date;
70
+
71
+ /** RELAÇÕES */
72
+
73
+ /**
74
+ * Relação com o torneio ao qual as regras estão associadas.
75
+ */
76
+ @OneToOne(() => Tournament, (tournament) => tournament.rule, {
77
+ cascade: true,
78
+ })
79
+ @JoinColumn({ name: 'tournament_id' })
80
+ tournament: Tournament;
81
+ }
@@ -0,0 +1 @@
1
+ export { TournamentTeam } from './tournament-team.entity';
@@ -0,0 +1,111 @@
1
+ import { ITournamentTeam } from '@natrave/tournaments-service-types';
2
+ import {
3
+ Entity,
4
+ Column,
5
+ PrimaryGeneratedColumn,
6
+ CreateDateColumn,
7
+ UpdateDateColumn,
8
+ ManyToOne,
9
+ JoinColumn,
10
+ Unique,
11
+ Index,
12
+ BeforeInsert,
13
+ OneToMany,
14
+ } from 'typeorm';
15
+
16
+ import { TournamentMatchCard } from 'tournaments/tournament-match-cards';
17
+ import { TournamentMatchGoal } from 'tournaments/tournament-match-goals';
18
+ import { TournamentMatch } from 'tournaments/tournament-matches';
19
+ import { TournamentPlayer } from 'tournaments/tournament-players';
20
+ import { Tournament } from 'tournaments/tournaments';
21
+
22
+ import { generateRandomInviteCode } from './utils/invite-code-generator';
23
+
24
+ /**
25
+ * Entidade que representa um time de torneio.
26
+ *
27
+ * @remarks
28
+ * Esta entidade armazena informações básicas sobre o time de um torneio, como o nome, logo, descrição e código de convite único.
29
+ * Além disso, mantém a referência ao torneio ao qual o time está associado e registra as datas de criação e atualização.
30
+ *
31
+ * @public
32
+ */
33
+ @Entity('tournament_teams')
34
+ @Unique(['tournamentId', 'name'])
35
+ @Unique(['inviteCode'])
36
+ @Index('IDX_tournament_team_tournament_id', ['tournamentId'])
37
+ @Index('IDX_tournament_team_invite_code', ['inviteCode'])
38
+ export class TournamentTeam implements ITournamentTeam {
39
+ @PrimaryGeneratedColumn()
40
+ id: number;
41
+
42
+ @Column({ name: 'tournament_id', type: 'int' })
43
+ tournamentId: number;
44
+
45
+ @Column({ type: 'varchar', length: 100 })
46
+ name: string;
47
+
48
+ @Column({ name: 'team_logo_url', type: 'text', nullable: true })
49
+ teamLogoUrl?: string;
50
+
51
+ @Column({ type: 'varchar', length: 255, nullable: true })
52
+ description?: string;
53
+
54
+ @Column({ name: 'invite_code', type: 'varchar', length: 5, unique: true })
55
+ inviteCode: string;
56
+
57
+ @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
58
+ createdAt: Date;
59
+
60
+ @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
61
+ updatedAt: Date;
62
+
63
+ /** RELAÇÕES */
64
+
65
+ /**
66
+ * Relação com o torneio ao qual o time está associado.
67
+ */
68
+ @ManyToOne(() => Tournament, (tournament) => tournament.teams, {
69
+ onDelete: 'CASCADE',
70
+ })
71
+ @JoinColumn({ name: 'tournament_id' })
72
+ tournament: Tournament;
73
+
74
+ /**
75
+ * Relação com os jogadores associados ao time.
76
+ */
77
+ @OneToMany(() => TournamentPlayer, (player) => player.team)
78
+ players: TournamentPlayer[];
79
+
80
+ /**
81
+ * Relação com as partidas em casa associadas ao time.
82
+ */
83
+ @OneToMany(() => TournamentMatch, (match) => match.homeTeam)
84
+ homeMatches: TournamentMatch[];
85
+
86
+ /**
87
+ * Relação com as partidas fora de casa associadas ao time.
88
+ */
89
+ @OneToMany(() => TournamentMatch, (match) => match.awayTeam)
90
+ awayMatches: TournamentMatch[];
91
+
92
+ /**
93
+ * Relação com os gols associados ao time.
94
+ */
95
+ @OneToMany(() => TournamentMatchGoal, (goal) => goal.team)
96
+ goals: TournamentMatchGoal[];
97
+
98
+ /**
99
+ * Relação com os cartões associados ao time.
100
+ */
101
+ @OneToMany(() => TournamentMatchCard, (card) => card.team)
102
+ cards: TournamentMatchCard[];
103
+
104
+ /**
105
+ * Gera o código de convite antes de inserir o registro.
106
+ */
107
+ @BeforeInsert()
108
+ generateInviteCode(): void {
109
+ this.inviteCode = generateRandomInviteCode();
110
+ }
111
+ }