Просмотр исходного кода

♻️ refactor(contacts): 修改联系人表clientId类型为数字

- 将clientId字段从varchar类型改为int类型
- 添加unsigned约束确保数值为正数
- 更新Zod验证规则为number().int().positive()
- 调整示例值从字符串格式改为数字格式

♻️ refactor(contracts): 修改合同表clientId类型为数字

- 将clientId字段从varchar类型改为int类型
- 添加unsigned约束确保数值为正数
- 添加外键约束关联Client实体
- 更新Zod验证规则为number().int().positive()
- 调整示例值从字符串格式改为数字格式

♻️ refactor(expenses): 修改费用表clientId类型为数字

- 将clientId字段从varchar类型改为int类型
- 添加unsigned约束确保数值为正数
- 更新Zod验证规则为number().int().positive()
- 调整示例值从字符串格式改为数字格式
yourname 8 месяцев назад
Родитель
Сommit
9925132dee

+ 8 - 8
src/server/modules/contacts/linkman.entity.ts

@@ -7,9 +7,9 @@ export class Linkman {
   @PrimaryColumn({ name: 'id', type: 'varchar', length: 50 })
   id!: string;
 
-  @Column({ name: 'client_id', type: 'varchar', length: 50 })
+  @Column({ name: 'client_id', type: 'int', unsigned: true })
   @ForeignKey(() => Client)
-  clientId!: string;
+  clientId!: number;
 
   @Column({ name: 'name', type: 'varchar', length: 100 })
   name!: string;
@@ -67,9 +67,9 @@ export const LinkmanSchema = z.object({
     description: '联系人ID',
     example: 'LM20230001' 
   }),
-  clientId: z.string().max(50).openapi({ 
+  clientId: z.number().int().positive().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   name: z.string().max(100).openapi({ 
     description: '姓名',
@@ -138,9 +138,9 @@ export const CreateLinkmanDto = z.object({
     description: '联系人ID',
     example: 'LM20230001' 
   }),
-  clientId: z.string().max(50).openapi({ 
+  clientId: z.coerce.number().int().positive().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   name: z.string().max(100).openapi({ 
     description: '姓名',
@@ -197,9 +197,9 @@ export const CreateLinkmanDto = z.object({
 });
 
 export const UpdateLinkmanDto = z.object({
-  clientId: z.string().max(50).optional().openapi({ 
+  clientId: z.coerce.number().int().positive().optional().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   name: z.string().max(100).optional().openapi({ 
     description: '姓名',

+ 11 - 9
src/server/modules/contracts/hetong.entity.ts

@@ -1,4 +1,5 @@
-import { Entity, PrimaryColumn, Column, Index } from 'typeorm';
+import { Entity, PrimaryColumn, Column, Index, ForeignKey } from 'typeorm';
+import { Client } from '../clients/client.entity';
 import { z } from '@hono/zod-openapi';
 
 @Entity('hetong')
@@ -12,8 +13,9 @@ export class Hetong {
   @Column({ name: 'user_id', type: 'varchar', length: 50 })
   userId!: string;
 
-  @Column({ name: 'client_id', type: 'varchar', length: 50 })
-  clientId!: string;
+  @Column({ name: 'client_id', type: 'int', unsigned: true })
+  @ForeignKey(() => Client)
+  clientId!: number;
 
   @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })
   projectId?: string;
@@ -76,9 +78,9 @@ export const HetongSchema = z.object({
     description: '关联用户ID',
     example: 'U1001' 
   }),
-  clientId: z.string().max(50).openapi({ 
+  clientId: z.number().int().positive().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().openapi({ 
     description: '项目ID',
@@ -151,9 +153,9 @@ export const CreateHetongDto = z.object({
     description: '关联用户ID',
     example: 'U1001' 
   }),
-  clientId: z.string().max(50).openapi({ 
+  clientId: z.coerce.number().int().positive().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().optional().openapi({ 
     description: '项目ID',
@@ -214,9 +216,9 @@ export const UpdateHetongDto = z.object({
     description: '关联用户ID',
     example: 'U1001' 
   }),
-  clientId: z.string().max(50).optional().openapi({ 
+  clientId: z.coerce.number().int().positive().optional().openapi({
     description: '客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().optional().openapi({ 
     description: '项目ID',

+ 8 - 8
src/server/modules/expenses/expense.entity.ts

@@ -18,8 +18,8 @@ export class Expense {
   @Column({ name: 'amount', type: 'decimal', precision: 10, scale: 2 })
   amount!: number;
 
-  @Column({ name: 'client_id', type: 'varchar', length: 50, nullable: true })
-  clientId?: string;
+  @Column({ name: 'client_id', type: 'int', unsigned: true, nullable: true })
+  clientId?: number;
 
   @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })
   projectId?: string;
@@ -90,9 +90,9 @@ export const ExpenseSchema = z.object({
     description: '费用金额',
     example: 1500.50 
   }),
-  clientId: z.string().max(50).nullable().openapi({ 
+  clientId: z.number().int().positive().nullable().openapi({
     description: '关联客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().openapi({ 
     description: '关联项目ID',
@@ -173,9 +173,9 @@ export const CreateExpenseDto = z.object({
     description: '费用金额',
     example: 1500.50 
   }),
-  clientId: z.string().max(50).nullable().optional().openapi({ 
+  clientId: z.coerce.number().int().positive().nullable().optional().openapi({
     description: '关联客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().optional().openapi({ 
     description: '关联项目ID',
@@ -244,9 +244,9 @@ export const UpdateExpenseDto = z.object({
     description: '费用金额',
     example: 1500.50 
   }),
-  clientId: z.string().max(50).nullable().optional().openapi({ 
+  clientId: z.coerce.number().int().positive().nullable().optional().openapi({
     description: '关联客户ID',
-    example: 'C2001' 
+    example: 2001
   }),
   projectId: z.string().max(50).nullable().optional().openapi({ 
     description: '关联项目ID',