mirror of
https://github.com/Such-Software/medusa-plugin-blog.git
synced 2026-10-17 05:32:06 +02:00
update models
This commit is contained in:
@@ -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
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user