diff --git a/CHANGELOG.md b/CHANGELOG.md index baf4bcb..c81a925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## 0.10.0 +## 0.0.1 ### Patch Changes diff --git a/README.md b/README.md index d3f0809..1048831 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # medusa-plugin-blog + +Working on it diff --git a/package.json b/package.json index 2216a9d..4789ce9 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/migrations/1684173263726-Blog.ts b/src/migrations/1684173263726-Blog.ts index 0e2d649..16eb89c 100644 --- a/src/migrations/1684173263726-Blog.ts +++ b/src/migrations/1684173263726-Blog.ts @@ -5,7 +5,7 @@ export class Blog1684173263726 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { 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, diff --git a/src/models/blog-category.ts b/src/models/blog-category.ts index 2ee9d23..d71dfce 100644 --- a/src/models/blog-category.ts +++ b/src/models/blog-category.ts @@ -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 }) diff --git a/src/models/blog-post.ts b/src/models/blog-post.ts index f5a0e6c..84ea3a9 100644 --- a/src/models/blog-post.ts +++ b/src/models/blog-post.ts @@ -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 }) diff --git a/src/services/blog.ts b/src/services/blog.ts index 400a109..c2f0580 100644 --- a/src/services/blog.ts +++ b/src/services/blog.ts @@ -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 */