import {
    PrimaryKey,
    Property,
    BaseEntity as MikroOrmBaseEntity,
    BeforeCreate,
    BeforeUpdate,
} from '@mikro-orm/core';

export abstract class BaseEntity extends MikroOrmBaseEntity {
    @PrimaryKey()
    id!: number;

    @Property({ hidden: true })
    createdAt: Date = new Date();

    @Property({ hidden: true })
    updatedAt: Date = new Date();

    @BeforeCreate()
    setCreationDate() {
        this.createdAt = new Date();
    }

    @BeforeUpdate()
    setUpdateDate() {
        this.updatedAt = new Date();
    }
}
