Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mariadb type 'time' showing NaN #27

Open
show981111 opened this issue Aug 6, 2021 · 0 comments
Open

Mariadb type 'time' showing NaN #27

show981111 opened this issue Aug 6, 2021 · 0 comments

Comments

@show981111
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant