API/src/entity/category.entity.ts

40 lines
1.0 KiB
TypeScript

import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToMany } from 'typeorm';
import { ApiProperty } from '@midwayjs/swagger';
import { Product } from './product.entity';
import { CategoryAttribute } from './category_attribute.entity';
@Entity('category')
export class Category {
@ApiProperty({ description: 'ID' })
@PrimaryGeneratedColumn()
id: number;
@ApiProperty({ description: '分类显示名称' })
@Column()
title: string;
@ApiProperty({ description: '分类中文名称' })
@Column({ nullable: true })
titleCN: string;
@ApiProperty({ description: '分类唯一标识' })
@Column({ unique: true })
name: string;
@ApiProperty({ description: '排序' })
@Column({ default: 0 })
sort: number;
@OneToMany(() => Product, product => product.category)
products: Product[];
@OneToMany(() => CategoryAttribute, categoryAttribute => categoryAttribute.category)
attributes: CategoryAttribute[];
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
}