Skip to content

Mariadb type 'time' showing NaN #27

@show981111

Description

@show981111

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions