diff --git a/package.json b/package.json index 6496a4d..23f767e 100644 --- a/package.json +++ b/package.json @@ -18,16 +18,15 @@ ], "devDependencies": { "@medusajs/medusa": "^1.10.1", + "@medusajs/types": "^1.8.5", "@medusajs/utils": "^1.8.4", "body-parser": "^1.19.0", + "cors": "^2.8.5", "cross-env": "^5.2.1", "express": "^4.17.2", - "jest": "^25.5.4", - "medusa-core-utils": "^1.2.0", "medusa-interfaces": "^1.3.7", - "medusa-test-utils": "^1.1.40", - "typescript": "^4.9.5", - "typeorm": "^0.3.16" + "typeorm": "^0.3.16", + "typescript": "^4.9.5" }, "scripts": { "prepare": "cross-env NODE_ENV=production yarn run build", diff --git a/src/models/blog-category.ts b/src/models/blog-category.ts new file mode 100644 index 0000000..03fb2e3 --- /dev/null +++ b/src/models/blog-category.ts @@ -0,0 +1,17 @@ +import { Product, Customer } from "@medusajs/medusa" +import { BaseEntity, generateEntityId } from "@medusajs/utils" +import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm" + +@Entity() +export class BlogCategory extends BaseEntity { + + + + + + + @BeforeInsert() + private beforeInsert(): void { + this.id = generateEntityId(this.id, "post") + } +} \ No newline at end of file diff --git a/src/models/blog-post.ts b/src/models/blog-post.ts new file mode 100644 index 0000000..74714c1 --- /dev/null +++ b/src/models/blog-post.ts @@ -0,0 +1,59 @@ +import { Product, Customer } from "@medusajs/medusa" +import { BaseEntity, generateEntityId } from "@medusajs/utils" +import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm" +import { BlogCategory } from "./blog-category" +import { BlogTag } from "./blog-tag" + +@Entity() +export class BlogPost extends BaseEntity { + + @Index({ unique: true }) + @Column({ type: "text", nullable: true }) + handle: string | null + + @Column() + title: string + + @Column({ type: "text", nullable: true }) + content: string | null + + @Column({ type: "text", nullable: true }) + author: string | null + + @Column({ type: "text", nullable: true }) + description: string | null + + @Column({ type: "text", nullable: true, array: true }) + keywords: string | null + + @Column({ type: "jsonb", nullable: true }) + tags: string | null + + @ManyToOne(() => BlogCategory) + @JoinColumn({ name: "category_id" }) + category: BlogCategory + + @Column({ type: "boolean", nullable: false }) + published: boolean + + + + @ManyToOne(() => BlogCategory) + @JoinColumn({ name: "product_id" }) + product: Product + + @Column({ type: "varchar", nullable: false }) + customer_id: string + + @ManyToOne(() => Product) + @JoinColumn({ name: "customer_id" }) + customer: Customer + + + + + @BeforeInsert() + private beforeInsert(): void { + this.id = generateEntityId(this.id, "post") + } +} \ No newline at end of file diff --git a/src/models/blog-tag.ts b/src/models/blog-tag.ts new file mode 100644 index 0000000..39d3f7f --- /dev/null +++ b/src/models/blog-tag.ts @@ -0,0 +1,17 @@ +import { Product, Customer } from "@medusajs/medusa" +import { BaseEntity, generateEntityId } from "@medusajs/utils" +import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm" + +@Entity() +export class BlogTag extends BaseEntity { + + + + + + + @BeforeInsert() + private beforeInsert(): void { + this.id = generateEntityId(this.id, "post") + } +} \ No newline at end of file