Files
negareh-api/src/modules/form-builder/entities/field.entity.ts
T
2026-02-05 10:08:37 +03:30

37 lines
1.0 KiB
TypeScript

import { Collection, Entity, Enum, ManyToOne, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
import { FieldOption } from './field-option.entity';
import { EntityType, FieldType } from '../interface/print';
import { BaseEntity } from 'src/common/entities/base.entity';
@Entity({ tableName: 'field' })
export class Field extends BaseEntity {
[OptionalProps]?: 'createdAt' | 'deletedAt'
@OneToMany(() => FieldOption, (attrValue) => attrValue.field)
options = new Collection<FieldOption>(this)
// Discriminator column
@Enum(() => EntityType) // Product , Print
entityType: EntityType;
// Foreign key based on entityType
@Property({ type: 'string',columnType:'char(26)' })
entityId: string;
@Property()
name: string;
@Enum(() => FieldType)
type: FieldType;
@Property({ type: 'boolean', default: false })
isRequired: boolean = false;
@Property({ type: 'boolean', default: false })
multiple: boolean = false;
@Property({ type: 'int', nullable: true })
order?: number;
}