import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import dayjs from "dayjs";
export abstract class BaseEntity {
  @PrimaryGeneratedColumn({ type: "int", name: "id" })
  id: number;
  @Column({
    type: "datetime",
    comment: "创建时间",
    default: () => "CURRENT_TIMESTAMP",
    transformer: {
      to(value: Date) {
        return value;
      },
      from(value) {
        return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
      },
    },
  })
  createDate: Date;
  @Column({
    type: "datetime",
    comment: "更新时间",
    default: () => "CURRENT_TIMESTAMP",
    transformer: {
      to(value: Date) {
        return value;
      },
      from(value) {
        return dayjs(new Date(value)).format("YYYY-MM-DD HH:mm:ss");
      },
    },
  })
  updateDate: Date;
}
