126 lines
2.5 KiB
TypeScript
126 lines
2.5 KiB
TypeScript
import { UserMetaEntity } from '@freeblox/shared';
|
|
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
DeleteDateColumn,
|
|
Entity,
|
|
Index,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
} from 'typeorm';
|
|
import { Privacy } from '../../enums/privacy.enum';
|
|
import { ContentType } from '../../enums/content-type.enum';
|
|
import { Exclude, Expose } from 'class-transformer';
|
|
import { UserEntity } from 'apps/auth/src/database/entities/user.entity';
|
|
import {
|
|
IsBoolean,
|
|
IsEnum,
|
|
IsNotEmpty,
|
|
IsNumber,
|
|
IsOptional,
|
|
IsString,
|
|
MaxLength,
|
|
} from 'class-validator';
|
|
import { ContentPriceEntity } from './content-price.entity';
|
|
|
|
@Entity('content')
|
|
@Expose()
|
|
export class ContentEntity extends UserMetaEntity {
|
|
@PrimaryGeneratedColumn()
|
|
id: number;
|
|
|
|
@Column({ length: 255 })
|
|
@Index()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@MaxLength(255)
|
|
name: string;
|
|
|
|
@Column()
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@MaxLength(5000)
|
|
description: string;
|
|
|
|
@Column({ type: 'uuid', name: 'user_id' })
|
|
userId: string;
|
|
|
|
@Column({ name: 'parent_id', nullable: true })
|
|
parentId: number;
|
|
|
|
@Column({ default: false })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
restricted: boolean;
|
|
|
|
@Column({ default: false })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
onsale: boolean;
|
|
|
|
@Column({ default: false })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
published: boolean;
|
|
|
|
@Column({ default: true, name: 'comments_enabled' })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
commentsEnabled: boolean;
|
|
|
|
@Column({ default: false, name: 'open_source' })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
openSource: boolean;
|
|
|
|
@Column({ default: false })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
tradeable: boolean;
|
|
|
|
@Column({ default: false })
|
|
@IsBoolean()
|
|
@IsOptional()
|
|
marketable: boolean;
|
|
|
|
@Column({ type: 'enum', enum: Privacy, default: Privacy.PUBLIC })
|
|
@IsEnum(Privacy)
|
|
privacy: Privacy;
|
|
|
|
@Column({ type: String, enum: ContentType })
|
|
@IsEnum(ContentType)
|
|
@Index()
|
|
type: ContentType;
|
|
|
|
@Column({ unsigned: true, nullable: true })
|
|
@IsNumber()
|
|
@IsOptional()
|
|
stock: number;
|
|
|
|
@Column({ nullable: true })
|
|
@IsString()
|
|
@IsOptional()
|
|
license: string;
|
|
|
|
@ManyToOne(() => ContentEntity)
|
|
@JoinColumn({ name: 'parent_id' })
|
|
@Exclude()
|
|
parent?: ContentEntity;
|
|
|
|
@CreateDateColumn({ name: 'created_at' })
|
|
@Expose()
|
|
createdAt: Date;
|
|
|
|
@DeleteDateColumn({ name: 'deleted_at' })
|
|
@Exclude()
|
|
deletedAt?: Date;
|
|
|
|
@OneToMany(() => ContentPriceEntity, (price) => price.content)
|
|
@Expose()
|
|
prices?: ContentPriceEntity[];
|
|
|
|
user?: Partial<UserEntity>;
|
|
}
|