-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpage.entity.ts
43 lines (36 loc) · 1.34 KB
/
page.entity.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 { BlockDataInterface, RootBlock, RootBlockEntity } from "@comet/blocks-api";
import { DocumentInterface, RootBlockDataScalar, RootBlockType } from "@comet/cms-api";
import { BaseEntity, Entity, OptionalProps, PrimaryKey, Property } from "@mikro-orm/core";
import { Field, ID, ObjectType } from "@nestjs/graphql";
import { v4 as uuid } from "uuid";
import { PageContentBlock } from "../blocks/PageContentBlock";
import { SeoBlock } from "../blocks/seo.block";
@Entity()
@ObjectType({
implements: () => [DocumentInterface],
})
@RootBlockEntity()
export class Page extends BaseEntity<Page, "id"> implements DocumentInterface {
[OptionalProps]?: "createdAt" | "updatedAt";
@PrimaryKey({ columnType: "uuid" })
@Field(() => ID)
id: string = uuid();
@RootBlock(PageContentBlock)
@Property({ customType: new RootBlockType(PageContentBlock) })
@Field(() => RootBlockDataScalar(PageContentBlock))
content: BlockDataInterface;
@Property({ customType: new RootBlockType(SeoBlock) })
@Field(() => RootBlockDataScalar(SeoBlock))
seo: BlockDataInterface;
@Property({
columnType: "timestamp with time zone",
})
@Field()
createdAt: Date = new Date();
@Property({
columnType: "timestamp with time zone",
onUpdate: () => new Date(),
})
@Field()
updatedAt: Date = new Date();
}