perf: 优化类型问题

This commit is contained in:
richarjiang
2026-04-07 15:35:44 +08:00
parent 3a1b4d22bf
commit 886e70a106
18 changed files with 101 additions and 111 deletions

View File

@@ -13,7 +13,7 @@ export class CreateShareDto {
@IsString()
@IsNotEmpty({ message: '标题不能为空' })
@MaxLength(100, { message: '标题不能超过100个字符' })
title: string;
title!: string;
@ApiProperty({
description: '6个关卡ID',
@@ -23,5 +23,5 @@ export class CreateShareDto {
@ArrayMinSize(6, { message: '需要恰好6个关卡' })
@ArrayMaxSize(6, { message: '需要恰好6个关卡' })
@IsString({ each: true })
levelIds: string[];
levelIds!: string[];
}

View File

@@ -2,48 +2,48 @@ import { ApiProperty } from '@nestjs/swagger';
export class CreateShareResponseDto {
@ApiProperty({ description: '分享码' })
shareCode: string;
shareCode!: string;
@ApiProperty({ description: '分享标题' })
title: string;
title!: string;
@ApiProperty({ description: '关卡数量' })
levelCount: number;
levelCount!: number;
}
export class ShareLevelDto {
@ApiProperty()
id: string;
id!: string;
@ApiProperty()
level: number;
level!: number;
@ApiProperty()
imageUrl: string;
imageUrl!: string;
@ApiProperty()
answer: string;
answer!: string;
@ApiProperty({ nullable: true })
hint1: string | null;
hint1!: string | null;
@ApiProperty({ nullable: true })
hint2: string | null;
hint2!: string | null;
@ApiProperty({ nullable: true })
hint3: string | null;
hint3!: string | null;
@ApiProperty()
sortOrder: number;
sortOrder!: number;
}
export class JoinShareResponseDto {
@ApiProperty({ description: '分享码' })
shareCode: string;
shareCode!: string;
@ApiProperty({ description: '分享标题' })
title: string;
title!: string;
@ApiProperty({ description: '关卡列表', type: [ShareLevelDto] })
levels: ShareLevelDto[];
levels!: ShareLevelDto[];
}

View File

@@ -15,32 +15,32 @@ import { ShareParticipant } from './share-participant.entity';
@Entity('share_configs')
export class ShareConfig {
@PrimaryGeneratedColumn('uuid')
id: string;
id!: string;
@Index('idx_share_code', { unique: true })
@Column({ type: 'varchar', length: 8, name: 'share_code' })
shareCode: string;
shareCode!: string;
@Column({ type: 'varchar', length: 100 })
title: string;
title!: string;
@Column({ type: 'varchar', length: 191, name: 'sharer_id' })
sharerId: string;
sharerId!: string;
@ManyToOne(() => User)
@JoinColumn({ name: 'sharer_id' })
sharer: User;
sharer!: User;
/** 有序 JSON 数组,存储 6 个关卡 ID */
@Column({ type: 'json', name: 'level_ids' })
levelIds: string[];
levelIds!: string[];
@OneToMany(() => ShareParticipant, (p) => p.shareConfig)
participants: ShareParticipant[];
participants!: ShareParticipant[];
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
createdAt!: Date;
@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
updatedAt!: Date;
}

View File

@@ -15,23 +15,23 @@ import { ShareConfig } from './share-config.entity';
@Unique('uq_share_participant', ['shareConfigId', 'participantId'])
export class ShareParticipant {
@PrimaryGeneratedColumn('uuid')
id: string;
id!: string;
@Index('idx_share_config_id')
@Column({ type: 'varchar', length: 191, name: 'share_config_id' })
shareConfigId: string;
shareConfigId!: string;
@ManyToOne(() => ShareConfig, (sc) => sc.participants)
@JoinColumn({ name: 'share_config_id' })
shareConfig: ShareConfig;
shareConfig!: ShareConfig;
@Column({ type: 'varchar', length: 191, name: 'participant_id' })
participantId: string;
participantId!: string;
@ManyToOne(() => User)
@JoinColumn({ name: 'participant_id' })
participant: User;
participant!: User;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
createdAt!: Date;
}

View File

@@ -24,7 +24,10 @@ export class ShareController {
@Post()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: '创建分享', description: '选择6关+标题,生成分享码' })
@ApiOperation({
summary: '创建分享',
description: '选择6关+标题,生成分享码',
})
@ApiResponse({ status: 201, description: '创建成功' })
@ApiResponse({ status: 400, description: '参数错误' })
async createShare(

View File

@@ -68,10 +68,7 @@ export class ShareService {
};
}
async joinShare(
userId: string,
code: string,
): Promise<JoinShareResponseDto> {
async joinShare(userId: string, code: string): Promise<JoinShareResponseDto> {
const config = await this.shareConfigRepository.findByShareCode(code);
if (!config) {
throw new NotFoundException('分享不存在或已过期');