update models

This commit is contained in:
Lacey Pevey
2023-05-14 15:26:05 -05:00
parent 5873b08f12
commit e498701703
3 changed files with 74 additions and 34 deletions
+16 -2
View File
@@ -1,14 +1,28 @@
import { Product, Customer } from "@medusajs/medusa"
import { BaseEntity, generateEntityId } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm"
import { BeforeInsert, Column, Entity, Index, OneToMany } from "typeorm"
import { BlogPost } from "./blog-post"
@Entity()
export class BlogCategory extends BaseEntity {
@Index({ unique: true })
@Column({ type: "varchar", nullable: true })
handle: string | null
@Column({ type: "varchar", nullable: false })
title: string
@Column({ type: "text", nullable: true })
description: string | null
@Column({ type: "text", nullable: true, array: true })
keywords: string | null
@Column({ type: "jsonb", nullable: true })
metadata: Record<string, any> | null
@OneToMany(() => BlogPost, post => post.category)
posts: BlogPost[]
@BeforeInsert()
private beforeInsert(): void {
+55 -26
View File
@@ -1,6 +1,6 @@
import { Product, Customer } from "@medusajs/medusa"
import { Product, ProductCollection } from "@medusajs/medusa"
import { BaseEntity, generateEntityId } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm"
import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, ManyToMany, JoinTable } from "typeorm"
import { BlogCategory } from "./blog-category"
import { BlogTag } from "./blog-tag"
@@ -8,49 +8,78 @@ import { BlogTag } from "./blog-tag"
export class BlogPost extends BaseEntity {
@Index({ unique: true })
@Column({ type: "text", nullable: true })
@Column({ type: "varchar", nullable: true })
handle: string | null
@Column()
@Column({ type: "varchar", nullable: false })
title: string
@Column({ type: "varchar", nullable: true })
author: string | null
@Column({ type: "boolean", nullable: false })
published: boolean
@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
@Column({ type: "varchar", nullable: false })
category_id: string
@ManyToOne(() => BlogCategory)
@JoinColumn({ name: "category_id" })
category: BlogCategory
@ManyToMany(() => BlogTag)
@JoinTable({
name: "blog_tags",
joinColumn: {
name: "post_id",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "tag_id",
referencedColumnName: "id",
},
})
tags: BlogTag[]
@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
@ManyToMany(() => Product)
@JoinTable({
name: "blog_product_tags",
joinColumn: {
name: "post_id",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "product_id",
referencedColumnName: "id",
},
})
products: Product[]
@ManyToMany(() => ProductCollection)
@JoinTable({
name: "blog_collection_tags",
joinColumn: {
name: "post_id",
referencedColumnName: "id",
},
inverseJoinColumn: {
name: "collection_id",
referencedColumnName: "id",
},
})
collections: ProductCollection[]
@Column({ type: "jsonb", nullable: true })
metadata: Record<string, any> | null
@BeforeInsert()
private beforeInsert(): void {
+3 -6
View File
@@ -1,14 +1,11 @@
import { Product, Customer } from "@medusajs/medusa"
import { BaseEntity, generateEntityId } from "@medusajs/utils"
import { BeforeInsert, Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from "typeorm"
import { BeforeInsert, Column, Entity } from "typeorm"
@Entity()
export class BlogTag extends BaseEntity {
@Column({ type: "varchar", nullable: false })
title: string
@BeforeInsert()
private beforeInsert(): void {