SoftwareBrothers / adminjs-typeorm

TypeORM adapter for AdminJS
MIT License
24 stars 32 forks source link

Mariadb type 'time' showing NaN #27

Open show981111 opened 3 years ago

show981111 commented 3 years ago

I had columns that have a type 'time' in Mariadb. For those columns, admin-bro shows NaN, which seems it tries to convert to the Date type but fail. I am using "@admin-bro/typeorm": "^1.4.0",

스크린샷 2021-08-06 오후 11 24 22

This is my entity.

@Entity('TEACHER')
export class Teacher extends BaseEntity {
    @PrimaryGeneratedColumn('increment')
    @ApiProperty()
    id: number;

    @Column({ name: 'FK_TEACHER_teacherID' })
    @RelationId((teacher: Teacher) => teacher.teacher)
    @ApiProperty()
    teacherID: string;

    @ManyToOne((type) => TeacherID, (TeacherID) => TeacherID.teacherID, {
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    })
    @JoinColumn({ name: 'FK_TEACHER_teacherID' })
    teacher: TeacherID;

    @ManyToOne((type) => Branch, (Branch) => Branch.branchName, {
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    })
    @JoinColumn({ name: 'FK_TEACHER_branch' })
    branch: Branch;

    @Column({ name: 'FK_TEACHER_branch' })
    @ApiProperty()
    branchName: string;

    @Column({ type: 'tinyint', nullable: false })
    @ApiProperty()
    workDow: number;

    @Column({ type: 'time', nullable: false })
    @ApiProperty()
    startTime: Date;

    @Column({ type: 'time', nullable: false })
    @ApiProperty()
    endTime: Date;

    setTeacher(createTeacherDto: CreateTeacherDto): void {
        let br = new Branch(createTeacherDto.teacherBranch);
        let tr = new TeacherID(createTeacherDto.teacherID);
        this.teacher = tr;
        this.branch = br;
        this.workDow = createTeacherDto.workDow;
        this.startTime = createTeacherDto.startTime;
        this.endTime = createTeacherDto.endTime;
    }
}

I checked it at the "adminjs-typeorm/src/Property.js" and it clearly shows that 'time' column is converted to Date. Thus, I added if(this.column.type === 'time') type = 'string'; at the adminjs-typeorm/src/Property.js and it shows the time correctly.

As a result, I think the type 'time' should not be converted to 'Date'.