@smallprod/models
Version:
74 lines (62 loc) • 1.51 kB
text/typescript
import {
AutoIncrement,
BigInt,
Check,
Date,
Default,
Entity,
EntityContext,
FieldName,
Id,
Int,
ManyToMany,
ManyToOne,
PrimaryKey,
Table,
Varchar,
} from '../../..';
import CategoryEntity from './category.entity';
import UserEntity from './user.entity';
export default class ArticleEntity extends Entity {
private id = 0;
private title: string;
private publishedAt: Date;
private nbPages: number;
private authors: UserEntity[] = [];
private category: CategoryEntity | null = null;
public constructor(
title: string,
publishedAt: Date,
nbPages: number,
category: CategoryEntity,
authors: UserEntity[] = [],
) {
super();
this.title = title;
this.publishedAt = publishedAt;
this.nbPages = nbPages;
this.category = category;
this.authors = authors;
}
public getId = () => this.id;
public getCategory = () => this.category;
public getAuthors = () => this.authors;
public setCategory = (category: CategoryEntity) => (this.category = category);
public setAuthors = (authors: UserEntity[]) => (this.authors = authors);
public fetchAuthors = (context: EntityContext, dbName: string) =>
this.fetch('authors', context, dbName);
}