start models

This commit is contained in:
Lacey Pevey
2023-05-14 13:10:05 -05:00
parent ada2b4d991
commit 5873b08f12
4 changed files with 97 additions and 5 deletions
+4 -5
View File
@@ -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",
+17
View File
@@ -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")
}
}
+59
View File
@@ -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")
}
}
+17
View File
@@ -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")
}
}