make handles not nullable and unique

This commit is contained in:
Lacey Pevey
2023-05-16 07:51:52 -05:00
parent 38ec057ce3
commit 2da076c102
7 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# Change Log
## 0.10.0
## 0.0.1
### Patch Changes
+2
View File
@@ -1 +1,3 @@
# medusa-plugin-blog
Working on it
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "medusa-plugin-blog",
"version": ".1.0",
"description": "Markdown-based blog for Medusa",
"version": "0.0.1",
"description": "Basic blog for Medusa",
"repository": {
"type": "git",
"url": "https://github.com/pevey/medusa-plugin-blog"
+2 -2
View File
@@ -5,7 +5,7 @@ export class Blog1684173263726 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "blog_category" ("id" character varying NOT NULL,
"handle" character varying,
"handle" character varying UNIQUE NOT NULL,
"title" character varying NOT NULL,
"description" character varying,
"keywords" varchar array,
@@ -17,7 +17,7 @@ export class Blog1684173263726 implements MigrationInterface {
await queryRunner.query(
`CREATE TABLE IF NOT EXISTS "blog_post" ("id" character varying NOT NULL,
"handle" character varying,
"handle" character varying UNIQUE NOT NULL,
"title" character varying NOT NULL,
"author" character varying,
"published" boolean NOT NULL DEFAULT false,
+1 -1
View File
@@ -6,7 +6,7 @@ import { BlogPost } from "./blog-post"
export class BlogCategory extends BaseEntity {
@Index({ unique: true })
@Column({ type: "varchar", nullable: true })
@Column({ type: "varchar", nullable: false })
handle: string | null
@Column({ type: "varchar", nullable: false })
+1 -1
View File
@@ -8,7 +8,7 @@ import { BlogTag } from "./blog-tag"
export class BlogPost extends BaseEntity {
@Index({ unique: true })
@Column({ type: "varchar", nullable: true })
@Column({ type: "varchar", nullable: false })
handle: string | null
@Column({ type: "varchar", nullable: false })
+4 -4
View File
@@ -46,7 +46,7 @@ export default class BlogService extends TransactionBaseService {
async addBlogCategory (category) {
const { handle, title, description, keywords, metadata } = category
if (!title) throw new Error("Adding a blog category requires a title")
if (!handle || !title) throw new Error("Adding a blog category requires a unique handle and a title")
/* @ts-ignore */
const blogCategoryRepository = this.activeManager_.withRepository(this.blogCategoryRepository_)
const createdCategory = blogCategoryRepository.create({
@@ -62,7 +62,7 @@ export default class BlogService extends TransactionBaseService {
async updateBlogCategory (id, category) {
const { handle, title, description, keywords, metadata } = category
if (!id || !title) throw new Error("Updating a blog category requires an id and a title")
if (!id || !title || !title) throw new Error("Updating a blog category requires an id, a unique handle, and a title")
/* @ts-ignore */
const blogCategoryRepository = this.activeManager_.withRepository(this.blogCategoryRepository_)
const blogCategory = blogCategoryRepository.update(id, {
@@ -205,7 +205,7 @@ export default class BlogService extends TransactionBaseService {
async addBlogPost(post) {
const { handle, title, author, published, content, description, keywords, category_id, tag_ids, product_ids, collection_ids, metadata } = post
if (!title) throw new Error("Adding a blog post requires a title")
if (!handle || !title) throw new Error("Adding a blog post requires a unique handle and a title")
let tags = []
if (tag_ids) {
/* @ts-ignore */
@@ -261,7 +261,7 @@ export default class BlogService extends TransactionBaseService {
async updateBlogPost(id, post) {
const { handle, title, author, published, content, description, keywords, category_id, tag_ids, product_ids, collection_ids, metadata } = post
if (!id || !title) throw new Error("Updating a blog post requires an id and a title")
if (!id || !handle || !title) throw new Error("Updating a blog post requires an id, a unique handle, and a title")
let tags = []
if (tag_ids) {
/* @ts-ignore */