gemercheung 7 ヶ月 前
コミット
f9923d907d

+ 2 - 1
packages/backend/package.json

@@ -38,7 +38,8 @@
     "reflect-metadata": "^0.1.13",
     "rxjs": "^7.8.1",
     "svg-captcha": "^1.4.0",
-    "typeorm": "^0.3.17"
+    "typeorm": "^0.3.17",
+    "typeorm-i18n": "0.2.0-rc.1"
   },
   "devDependencies": {
     "@nestjs/cli": "^10.0.0",

+ 23 - 15
packages/backend/src/modules/article/article.entity.ts

@@ -13,12 +13,17 @@ import {
 } from 'typeorm';
 import { Category } from '../category/category.entity';
 import { User } from '../user/user.entity';
+import { I18nColumn } from 'typeorm-i18n';
 
 @Entity()
 export class Article {
   @PrimaryGeneratedColumn()
   id: number;
 
+  @I18nColumn({
+    default_language: 'cn',
+    languages: ['cn', 'en'],
+  })
   @Column({ unique: false, default: '', length: 200 })
   title: string;
 
@@ -60,23 +65,26 @@ export class Article {
   @UpdateDateColumn()
   updateTime: Date;
 
-  @OneToMany(() => ArticleContent, (articleContent) => articleContent.content)
-  public contents: ArticleContent[];
+  // @OneToMany(() => ArticleContent, (articleContent) => articleContent.content)
+  // public contents: ArticleContent[];
 }
 
-@Entity()
-export class ArticleContent {
-  @PrimaryGeneratedColumn()
-  id: number;
+// @Entity()
+// export class ArticleContent {
+//   @PrimaryGeneratedColumn()
+//   id: number;
 
-  @ManyToOne(() => Article, (article) => article.contents, {
-    createForeignKeyConstraints: false,
-  })
-  article: Article;
+//   @ManyToOne(() => Article, (article) => article.contents, {
+//     createForeignKeyConstraints: false,
+//   })
+//   article: Article;
 
-  @Column({ unique: false, default: '', length: 200 })
-  lang: string;
+//   @Column({ default: '', length: 200 })
+//   title: string;
 
-  @Column({ type: 'longtext', nullable: true })
-  content: string;
-}
+//   @Column({ unique: false, default: '', length: 200 })
+//   lang: string;
+
+//   @Column({ type: 'longtext', nullable: true })
+//   content: string;
+// }

+ 2 - 2
packages/backend/src/modules/article/article.module.ts

@@ -1,10 +1,10 @@
 import { Module } from '@nestjs/common';
 import { ArticleService } from './article.service';
 import { ArticleController } from './article.controller';
-import { Article, ArticleContent } from './article.entity';
+import { Article } from './article.entity';
 import { TypeOrmModule } from '@nestjs/typeorm';
 @Module({
-  imports: [TypeOrmModule.forFeature([Article, ArticleContent])],
+  imports: [TypeOrmModule.forFeature([Article])],
   providers: [ArticleService],
   controllers: [ArticleController],
 })

+ 20 - 1
packages/backend/src/modules/article/dto.ts

@@ -43,6 +43,25 @@ export class CreateArticleDto {
   enable?: boolean;
 }
 
+export class ArticleContentDto {
+  @ApiProperty()
+  @IsString()
+  @IsNotEmpty({ message: '标题不能为空' })
+  @Length(1, 200, {
+    message: `用户名长度必须大于$constraint1到$constraint2之间,当前传递的值是$value`,
+  })
+  title: string;
+
+  @ApiProperty({ required: true })
+  @IsString()
+  content: string;
+
+  @ApiProperty({ required: false })
+  @IsNumber()
+  @IsOptional()
+  articleId?: number;
+}
+
 export class GetArticleDto {
   @ApiProperty({ required: false })
   @Allow()
@@ -61,7 +80,7 @@ export class GetArticleDto {
   enable?: boolean;
 }
 
-export class QueryArticleDto extends GetArticleDto {}
+export class QueryArticleDto extends GetArticleDto { }
 
 export class UpdateArticleDto {
   @ApiProperty()

+ 153 - 0
pnpm-lock.yaml

@@ -82,6 +82,9 @@ importers:
       typeorm:
         specifier: ^0.3.17
         version: 0.3.20(mysql2@3.12.0)(redis@4.7.0)(ts-node@10.9.2(@types/node@20.17.11)(typescript@5.7.2))
+      typeorm-i18n:
+        specifier: 0.2.0-rc.1
+        version: 0.2.0-rc.1(mysql2@3.12.0)(redis@4.7.0)
     devDependencies:
       '@nestjs/cli':
         specifier: ^10.0.0
@@ -2396,6 +2399,9 @@ packages:
   '@types/yargs@17.0.33':
     resolution: {integrity: sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA==}
 
+  '@types/zen-observable@0.8.3':
+    resolution: {integrity: sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw==}
+
   '@typescript-eslint/eslint-plugin@6.21.0':
     resolution: {integrity: sha512-oy9+hTPCUFpngkEZUSzbf9MxI65wbKFoQYsgPdILTfbUldp5ovUuphZVe4i30emU9M/kP+T64Di0mxl7dSw3MA==}
     engines: {node: ^16.0.0 || >=18.0.0}
@@ -3760,6 +3766,10 @@ packages:
     resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==}
     engines: {node: '>=12'}
 
+  dotenv@8.6.0:
+    resolution: {integrity: sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==}
+    engines: {node: '>=10'}
+
   dunder-proto@1.0.1:
     resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
     engines: {node: '>= 0.4'}
@@ -6200,6 +6210,9 @@ packages:
     engines: {node: '>=14.0.0'}
     hasBin: true
 
+  sax@1.4.1:
+    resolution: {integrity: sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==}
+
   saxes@5.0.1:
     resolution: {integrity: sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==}
     engines: {node: '>=10'}
@@ -6754,6 +6767,60 @@ packages:
   typedarray@0.0.6:
     resolution: {integrity: sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==}
 
+  typeorm-i18n@0.2.0-rc.1:
+    resolution: {integrity: sha512-JkbRpOPBDZZjWDahYRGWoVtW1LVW9mR6x8Ycalokz5mweMVw2jcFEhkhhYSwhi1A/zb+/APRQFcTkc60XPvA5g==}
+
+  typeorm@0.2.45:
+    resolution: {integrity: sha512-c0rCO8VMJ3ER7JQ73xfk0zDnVv0WDjpsP6Q1m6CVKul7DB9iVdWLRjPzc8v2eaeBuomsbZ2+gTaYr8k1gm3bYA==}
+    hasBin: true
+    peerDependencies:
+      '@sap/hana-client': ^2.11.14
+      better-sqlite3: ^7.1.2
+      hdb-pool: ^0.1.6
+      ioredis: ^4.28.3
+      mongodb: ^3.6.0
+      mssql: ^6.3.1
+      mysql2: ^2.2.5
+      oracledb: ^5.1.0
+      pg: ^8.5.1
+      pg-native: ^3.0.0
+      pg-query-stream: ^4.0.0
+      redis: ^3.1.1
+      sql.js: ^1.4.0
+      sqlite3: ^5.0.2
+      typeorm-aurora-data-api-driver: ^2.0.0
+    peerDependenciesMeta:
+      '@sap/hana-client':
+        optional: true
+      better-sqlite3:
+        optional: true
+      hdb-pool:
+        optional: true
+      ioredis:
+        optional: true
+      mongodb:
+        optional: true
+      mssql:
+        optional: true
+      mysql2:
+        optional: true
+      oracledb:
+        optional: true
+      pg:
+        optional: true
+      pg-native:
+        optional: true
+      pg-query-stream:
+        optional: true
+      redis:
+        optional: true
+      sql.js:
+        optional: true
+      sqlite3:
+        optional: true
+      typeorm-aurora-data-api-driver:
+        optional: true
+
   typeorm@0.3.20:
     resolution: {integrity: sha512-sJ0T08dV5eoZroaq9uPKBoNcGslHBR4E4y+EBHs//SiGbblGe7IeduP/IH4ddCcj0qp3PHwDwGnuvqEAnKlq/Q==}
     engines: {node: '>=16.13.0'}
@@ -6949,6 +7016,10 @@ packages:
     resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==}
     engines: {node: '>= 0.4.0'}
 
+  uuid@8.3.2:
+    resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
+    hasBin: true
+
   uuid@9.0.1:
     resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
     hasBin: true
@@ -7328,6 +7399,14 @@ packages:
     resolution: {integrity: sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==}
     engines: {node: '>=12'}
 
+  xml2js@0.4.23:
+    resolution: {integrity: sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==}
+    engines: {node: '>=4.0.0'}
+
+  xmlbuilder@11.0.1:
+    resolution: {integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==}
+    engines: {node: '>=4.0'}
+
   xmlchars@2.2.0:
     resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==}
 
@@ -7411,6 +7490,12 @@ packages:
     resolution: {integrity: sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==}
     engines: {node: '>=18'}
 
+  zen-observable-ts@1.1.0:
+    resolution: {integrity: sha512-1h4zlLSqI2cRLPJUHJFL8bCWHhkpuXkF+dbGkRaWjgDIG26DmzyshUMrdV/rL3UnR+mhaX4fRq8LPouq0MYYIA==}
+
+  zen-observable@0.8.15:
+    resolution: {integrity: sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==}
+
   zrender@5.6.1:
     resolution: {integrity: sha512-OFXkDJKcrlx5su2XbzJvj/34Q3m6PvyCZkVPHGYpcCJ52ek4U/ymZyfuV1nKE23AyBJ51E/6Yr0mhZ7xGTO4ag==}
 
@@ -9273,6 +9358,8 @@ snapshots:
     dependencies:
       '@types/yargs-parser': 21.0.3
 
+  '@types/zen-observable@0.8.3': {}
+
   '@typescript-eslint/eslint-plugin@6.21.0(@typescript-eslint/parser@6.21.0(eslint@8.57.1)(typescript@5.7.2))(eslint@8.57.1)(typescript@5.7.2)':
     dependencies:
       '@eslint-community/regexpp': 4.12.1
@@ -10922,6 +11009,8 @@ snapshots:
 
   dotenv@16.4.7: {}
 
+  dotenv@8.6.0: {}
+
   dunder-proto@1.0.1:
     dependencies:
       call-bind-apply-helpers: 1.0.1
@@ -14052,6 +14141,8 @@ snapshots:
     optionalDependencies:
       '@parcel/watcher': 2.5.0
 
+  sax@1.4.1: {}
+
   saxes@5.0.1:
     dependencies:
       xmlchars: 2.2.0
@@ -14625,6 +14716,52 @@ snapshots:
 
   typedarray@0.0.6: {}
 
+  typeorm-i18n@0.2.0-rc.1(mysql2@3.12.0)(redis@4.7.0):
+    dependencies:
+      typeorm: 0.2.45(mysql2@3.12.0)(redis@4.7.0)
+    transitivePeerDependencies:
+      - '@sap/hana-client'
+      - better-sqlite3
+      - hdb-pool
+      - ioredis
+      - mongodb
+      - mssql
+      - mysql2
+      - oracledb
+      - pg
+      - pg-native
+      - pg-query-stream
+      - redis
+      - sql.js
+      - sqlite3
+      - supports-color
+      - typeorm-aurora-data-api-driver
+
+  typeorm@0.2.45(mysql2@3.12.0)(redis@4.7.0):
+    dependencies:
+      '@sqltools/formatter': 1.2.5
+      app-root-path: 3.1.0
+      buffer: 6.0.3
+      chalk: 4.1.2
+      cli-highlight: 2.1.11
+      debug: 4.4.0
+      dotenv: 8.6.0
+      glob: 7.2.3
+      js-yaml: 4.1.0
+      mkdirp: 1.0.4
+      reflect-metadata: 0.1.14
+      sha.js: 2.4.11
+      tslib: 2.8.1
+      uuid: 8.3.2
+      xml2js: 0.4.23
+      yargs: 17.7.2
+      zen-observable-ts: 1.1.0
+    optionalDependencies:
+      mysql2: 3.12.0
+      redis: 4.7.0
+    transitivePeerDependencies:
+      - supports-color
+
   typeorm@0.3.20(mysql2@3.12.0)(redis@4.7.0)(ts-node@10.9.2(@types/node@20.17.11)(typescript@5.7.2)):
     dependencies:
       '@sqltools/formatter': 1.2.5
@@ -14836,6 +14973,8 @@ snapshots:
 
   utils-merge@1.0.1: {}
 
+  uuid@8.3.2: {}
+
   uuid@9.0.1: {}
 
   v8-compile-cache-lib@3.0.1: {}
@@ -15221,6 +15360,13 @@ snapshots:
 
   xml-name-validator@4.0.0: {}
 
+  xml2js@0.4.23:
+    dependencies:
+      sax: 1.4.1
+      xmlbuilder: 11.0.1
+
+  xmlbuilder@11.0.1: {}
+
   xmlchars@2.2.0: {}
 
   xtend@4.0.2: {}
@@ -15291,6 +15437,13 @@ snapshots:
 
   yoctocolors@2.1.1: {}
 
+  zen-observable-ts@1.1.0:
+    dependencies:
+      '@types/zen-observable': 0.8.3
+      zen-observable: 0.8.15
+
+  zen-observable@0.8.15: {}
+
   zrender@5.6.1:
     dependencies:
       tslib: 2.3.0