-
-
Notifications
You must be signed in to change notification settings - Fork 495
/
Publisher.ts
43 lines (32 loc) · 932 Bytes
/
Publisher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { ObjectId } from 'mongodb';
import { Collection, Entity, ManyToMany, MongoEntity, OneToMany, PrimaryKey, Property, BeforeCreate } from '../../lib';
import { Book } from './Book';
import { Test } from './test.model';
import { SerializedPrimaryKey } from '../../lib/decorators';
@Entity()
export class Publisher implements MongoEntity<Publisher> {
@PrimaryKey()
_id!: ObjectId;
@SerializedPrimaryKey()
id!: string;
@Property()
name: string;
@OneToMany({ mappedBy: 'publisher' })
books = new Collection<Book>(this);
@ManyToMany({ eager: true })
tests = new Collection<Test>(this);
@Property()
type: PublisherType = PublisherType.LOCAL;
constructor(name: string = 'asd', type: PublisherType = PublisherType.LOCAL) {
this.name = name;
this.type = type;
}
@BeforeCreate()
beforeCreate() {
// do sth
}
}
export enum PublisherType {
LOCAL = 'local',
GLOBAL = 'global',
}