I have an entity Audit Like below in Nestjs app with typeorm for mongodb:
@Entity()
export class Audit {
@Column()
createdBy: string;
@BeforeInsert()
setAudit() {
this.createdBy = ???
}
}
@Entity()
export class Post extends Audit {
@Column()
title: string;
...
}
My other entities extend Audit and in my application i'm using jwt to authenticate users.
The problem is that when i want to save an entity i don't know how to set createdBy with @BeforeInsert hook...
I know we have user in request but i don't know what is the correct way of bringing user into setAudit method?