chore:清理空的gitkeep文件和临时文件

- 删除不再需要的.gitkeep占位文件
- 清理开发过程中的临时测试文件
This commit is contained in:
moyin
2025-12-17 11:03:40 +08:00
parent 418ecaa303
commit 8591f23505
6 changed files with 110 additions and 2 deletions

View File

@@ -28,12 +28,16 @@
"@nestjs/platform-express": "^10.4.20",
"@nestjs/platform-socket.io": "^10.4.20",
"@nestjs/schedule": "^4.1.2",
"@nestjs/typeorm": "^11.0.0",
"@nestjs/websockets": "^10.4.20",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.3",
"mysql2": "^3.16.0",
"nestjs-pino": "^4.5.0",
"pino": "^10.1.0",
"reflect-metadata": "^0.1.14",
"rxjs": "^7.8.2"
"rxjs": "^7.8.2",
"typeorm": "^0.3.28"
},
"devDependencies": {
"@nestjs/cli": "^10.4.9",

View File

View File

@@ -1,8 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// 全局启用校验管道(核心配置)
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // 过滤掉 DTO 中未定义的字段(比如传了个 `age` 但 DTO 里没有,会自动忽略)
forbidNonWhitelisted: true, // 若传了未定义的字段,直接报错(防止传多余参数)
transform: true, // 自动把入参转为 DTO 对应的类型(比如前端传的字符串数字 `'1'` 转为数字 `1`
}),
);
await app.listen(3000);
console.log('Pixel Game Server is running on http://localhost:3000');
}

View File

@@ -0,0 +1,95 @@
/**
* 用户功能测试脚本
*
* 使用方法npx ts-node test-users-functionality.ts
*/
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './src/app.module';
import { UsersService } from './src/core/db/users/users.service';
import { CreateUserDto } from './src/core/db/users/users.dto';
async function testUsersFunctionality() {
console.log('🚀 启动用户功能测试...\n');
try {
// 创建NestJS应用
const app = await NestFactory.createApplicationContext(AppModule, {
logger: false, // 禁用日志以保持输出清洁
});
// 获取用户服务
const usersService = app.get(UsersService);
console.log('✅ 成功获取UsersService实例');
// 测试数据
const testUserDto: CreateUserDto = {
username: `testuser_${Date.now()}`,
email: `test_${Date.now()}@example.com`,
phone: `+86138${Date.now().toString().slice(-8)}`,
password_hash: 'hashed_password_123',
nickname: '功能测试用户',
github_id: `github_${Date.now()}`,
avatar_url: 'https://example.com/avatar.jpg',
role: 1
};
console.log('\n📝 测试创建用户...');
const createdUser = await usersService.create(testUserDto);
console.log('✅ 用户创建成功:', {
id: createdUser.id.toString(),
username: createdUser.username,
nickname: createdUser.nickname,
email: createdUser.email
});
console.log('\n🔍 测试查询用户...');
const foundUser = await usersService.findOne(createdUser.id);
console.log('✅ 用户查询成功:', foundUser.username);
console.log('\n📊 测试用户统计...');
const userCount = await usersService.count();
console.log('✅ 当前用户总数:', userCount);
console.log('\n🔍 测试根据用户名查询...');
const userByUsername = await usersService.findByUsername(createdUser.username);
console.log('✅ 根据用户名查询成功:', userByUsername?.nickname);
console.log('\n✏ 测试更新用户...');
const updatedUser = await usersService.update(createdUser.id, {
nickname: '更新后的昵称'
});
console.log('✅ 用户更新成功:', updatedUser.nickname);
console.log('\n📋 测试查询所有用户...');
const allUsers = await usersService.findAll(5); // 限制5个
console.log('✅ 查询到用户数量:', allUsers.length);
console.log('\n🔍 测试搜索功能...');
const searchResults = await usersService.search('测试');
console.log('✅ 搜索结果数量:', searchResults.length);
console.log('\n🗑 测试删除用户...');
const deleteResult = await usersService.remove(createdUser.id);
console.log('✅ 用户删除成功:', deleteResult.message);
// 验证删除
console.log('\n✅ 验证删除结果...');
try {
await usersService.findOne(createdUser.id);
console.log('❌ 删除验证失败:用户仍然存在');
} catch (error) {
console.log('✅ 删除验证成功:用户已不存在');
}
await app.close();
console.log('\n🎉 所有功能测试通过!');
} catch (error) {
console.error('❌ 测试失败:', error);
process.exit(1);
}
}
testUsersFunctionality();