|
|
@@ -1,6 +1,7 @@
|
|
|
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
|
|
|
import { z } from '@hono/zod-openapi';
|
|
|
import { UserEntity } from '../users/user.entity';
|
|
|
+import { SilverKnowledgeCategory } from './silver-knowledge-category.entity';
|
|
|
|
|
|
@Entity('silver_knowledges')
|
|
|
export class SilverKnowledge {
|
|
|
@@ -13,8 +14,12 @@ export class SilverKnowledge {
|
|
|
@Column({ name: 'content', type: 'text' })
|
|
|
content!: string;
|
|
|
|
|
|
- @Column({ name: 'category', type: 'varchar', length: 50 })
|
|
|
- category!: string;
|
|
|
+ @Column({ name: 'category_id', type: 'int', unsigned: true })
|
|
|
+ categoryId!: number;
|
|
|
+
|
|
|
+ @ManyToOne(() => SilverKnowledgeCategory)
|
|
|
+ @JoinColumn({ name: 'category_id' })
|
|
|
+ category!: SilverKnowledgeCategory;
|
|
|
|
|
|
@Column({ name: 'tags', type: 'text', nullable: true })
|
|
|
tags!: string | null;
|
|
|
@@ -50,7 +55,8 @@ export const SilverKnowledgeSchema = z.object({
|
|
|
id: z.number().int().positive().openapi({ description: '知识ID' }),
|
|
|
title: z.string().max(255).openapi({ description: '知识标题', example: '健康生活小贴士' }),
|
|
|
content: z.string().openapi({ description: '知识内容', example: '今日分享几个健康生活的小技巧...' }),
|
|
|
- category: z.string().max(50).openapi({ description: '知识分类', example: '健康养生' }),
|
|
|
+ categoryId: z.number().int().positive().openapi({ description: '分类ID', example: 1 }),
|
|
|
+ category: z.any().optional().openapi({ description: '知识分类信息' }),
|
|
|
tags: z.string().nullable().openapi({ description: '标签,逗号分隔', example: '健康,养生,老年人' }),
|
|
|
author: z.string().max(100).openapi({ description: '作者', example: '张医生' }),
|
|
|
status: z.number().int().min(0).max(1).openapi({ description: '状态(0-草稿,1-发布)', example: 1 }),
|
|
|
@@ -64,7 +70,7 @@ export const SilverKnowledgeSchema = z.object({
|
|
|
export const CreateSilverKnowledgeDto = z.object({
|
|
|
title: z.string().max(255).openapi({ description: '知识标题', example: '健康生活小贴士' }),
|
|
|
content: z.string().openapi({ description: '知识内容', example: '今日分享几个健康生活的小技巧...' }),
|
|
|
- category: z.string().max(50).openapi({ description: '知识分类', example: '健康养生' }),
|
|
|
+ categoryId: z.coerce.number().int().positive().openapi({ description: '分类ID', example: 1 }),
|
|
|
tags: z.string().nullable().optional().openapi({ description: '标签,逗号分隔', example: '健康,养生,老年人' }),
|
|
|
author: z.string().max(100).openapi({ description: '作者', example: '张医生' }),
|
|
|
status: z.coerce.number().int().min(0).max(1).default(1).openapi({ description: '状态(0-草稿,1-发布)', example: 1 })
|
|
|
@@ -73,7 +79,7 @@ export const CreateSilverKnowledgeDto = z.object({
|
|
|
export const UpdateSilverKnowledgeDto = z.object({
|
|
|
title: z.string().max(255).optional().openapi({ description: '知识标题', example: '健康生活小贴士' }),
|
|
|
content: z.string().optional().openapi({ description: '知识内容', example: '今日分享几个健康生活的小技巧...' }),
|
|
|
- category: z.string().max(50).optional().openapi({ description: '知识分类', example: '健康养生' }),
|
|
|
+ categoryId: z.coerce.number().int().positive().optional().openapi({ description: '分类ID', example: 1 }),
|
|
|
tags: z.string().nullable().optional().openapi({ description: '标签,逗号分隔', example: '健康,养生,老年人' }),
|
|
|
author: z.string().max(100).optional().openapi({ description: '作者', example: '张医生' }),
|
|
|
status: z.coerce.number().int().min(0).max(1).optional().openapi({ description: '状态(0-草稿,1-发布)', example: 1 })
|