currently i got a bit of a janky work around but i wanted to do things proper and use BeforeInsert
i think its best here to just post the account.entity and let it speak for its self
@Entity()
export class Account {
@PrimaryGeneratedColumn()
id: number
@Column({ type: 'enum', enum: Status, default: Status.ACTIVATED })
status: Status
@ManyToMany((type) => Role, (role) => role.users, {
cascade: true,
})
@JoinTable()
roles: Role[]
// inject a default into the account
@BeforeInsert()
async setDefaultRole() {
/* TODO: create the default role (if not exist already)
add the "default" role too the account*/
}
// other unrelated columns
}
as you see in the BeforeInsert i'm trying to make sure the "default" role is created and the role is given before the account is created
the documentation isn't really the most helpful as it doesn't document what can and cant be done inside the BeforeInsert