first commit
This commit is contained in:
66
myteamwallet_backend/src/players/entities/player.entity.ts
Normal file
66
myteamwallet_backend/src/players/entities/player.entity.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
AfterLoad,
|
||||
BeforeInsert,
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { EntityHelper } from 'src/utils/entity-helper';
|
||||
import { TeamRole } from 'src/team-roles/entities/team-roles.entity';
|
||||
import { Team } from 'src/teams/entities/team.entity';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { Transaction } from 'src/transactions/entitites/transaction.entity';
|
||||
|
||||
@Entity()
|
||||
export class Player extends EntityHelper {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
firstName: string;
|
||||
|
||||
@Column()
|
||||
lastName: string;
|
||||
|
||||
@ManyToOne(() => TeamRole, {
|
||||
eager: true,
|
||||
})
|
||||
teamRole?: TeamRole | null;
|
||||
|
||||
@ManyToOne(() => Team, {
|
||||
eager: true,
|
||||
})
|
||||
team: Team;
|
||||
|
||||
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0 })
|
||||
balance: number;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.players, {
|
||||
eager: true,
|
||||
})
|
||||
user?: User | null;
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.player)
|
||||
transactions: Transaction[];
|
||||
|
||||
@AfterLoad()
|
||||
updateValue() {
|
||||
this.balance = Number(this.balance);
|
||||
}
|
||||
|
||||
@Column({ default: true })
|
||||
active: boolean;
|
||||
|
||||
@BeforeInsert()
|
||||
prepareData() {
|
||||
if (this.balance == null) {
|
||||
this.balance = 0;
|
||||
}
|
||||
|
||||
if (this.transactions == null) {
|
||||
this.transactions = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user