feat: 完善管理员系统和用户管理模块
- 更新管理员控制器和数据库管理功能 - 完善管理员操作日志系统 - 添加全面的属性测试覆盖 - 优化用户管理和用户档案服务 - 更新代码检查规范文档 功能改进: - 增强管理员权限验证 - 完善操作日志记录 - 优化数据库管理接口 - 提升系统安全性和可维护性
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
* @lastModified 2026-01-08
|
||||
*/
|
||||
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { UserStatus } from '../user_mgmt/user_status.enum';
|
||||
|
||||
@@ -52,26 +51,21 @@ export const DEFAULT_PROPERTY_CONFIG: PropertyTestConfig = {
|
||||
* 属性测试生成器
|
||||
*/
|
||||
export class PropertyTestGenerators {
|
||||
private static setupFaker(seed?: number) {
|
||||
if (seed) {
|
||||
faker.seed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机用户数据
|
||||
*/
|
||||
static generateUser(seed?: number) {
|
||||
this.setupFaker(seed);
|
||||
const random = seed ? Math.sin(seed) * 10000 - Math.floor(Math.sin(seed) * 10000) : Math.random();
|
||||
const id = Math.floor(random * 1000000);
|
||||
return {
|
||||
username: faker.internet.username(),
|
||||
nickname: faker.person.fullName(),
|
||||
email: faker.internet.email(),
|
||||
phone: faker.phone.number(),
|
||||
role: faker.number.int({ min: 0, max: 9 }),
|
||||
status: faker.helpers.enumValue(UserStatus),
|
||||
avatar_url: faker.image.avatar(),
|
||||
github_id: faker.string.alphanumeric(10)
|
||||
username: `testuser${id}`,
|
||||
nickname: `Test User ${id}`,
|
||||
email: `test${id}@example.com`,
|
||||
phone: `138${String(id).padStart(8, '0').substring(0, 8)}`,
|
||||
role: Math.floor(random * 10),
|
||||
status: ['ACTIVE', 'INACTIVE', 'SUSPENDED'][Math.floor(random * 3)] as any,
|
||||
avatar_url: `https://example.com/avatar${id}.jpg`,
|
||||
github_id: `github${id}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,21 +73,22 @@ export class PropertyTestGenerators {
|
||||
* 生成随机用户档案数据
|
||||
*/
|
||||
static generateUserProfile(seed?: number) {
|
||||
this.setupFaker(seed);
|
||||
const random = seed ? Math.sin(seed) * 10000 - Math.floor(Math.sin(seed) * 10000) : Math.random();
|
||||
const id = Math.floor(random * 1000000);
|
||||
return {
|
||||
user_id: faker.string.numeric(10),
|
||||
bio: faker.lorem.paragraph(),
|
||||
resume_content: faker.lorem.paragraphs(3),
|
||||
tags: JSON.stringify(faker.helpers.arrayElements(['developer', 'designer', 'manager'], { min: 1, max: 3 })),
|
||||
user_id: String(id),
|
||||
bio: `This is a test bio for user ${id}`,
|
||||
resume_content: `Test resume content for user ${id}. This is a sample resume.`,
|
||||
tags: JSON.stringify(['developer', 'tester']),
|
||||
social_links: JSON.stringify({
|
||||
github: faker.internet.url(),
|
||||
linkedin: faker.internet.url()
|
||||
github: `https://github.com/user${id}`,
|
||||
linkedin: `https://linkedin.com/in/user${id}`
|
||||
}),
|
||||
skin_id: faker.string.alphanumeric(8),
|
||||
current_map: faker.helpers.arrayElement(['plaza', 'forest', 'beach', 'mountain']),
|
||||
pos_x: faker.number.float({ min: 0, max: 1000 }),
|
||||
pos_y: faker.number.float({ min: 0, max: 1000 }),
|
||||
status: faker.number.int({ min: 0, max: 2 })
|
||||
skin_id: `skin${id}`,
|
||||
current_map: ['plaza', 'forest', 'beach', 'mountain'][Math.floor(random * 4)],
|
||||
pos_x: random * 1000,
|
||||
pos_y: random * 1000,
|
||||
status: Math.floor(random * 3)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,14 +96,16 @@ export class PropertyTestGenerators {
|
||||
* 生成随机Zulip账号数据
|
||||
*/
|
||||
static generateZulipAccount(seed?: number) {
|
||||
this.setupFaker(seed);
|
||||
const random = seed ? Math.sin(seed) * 10000 - Math.floor(Math.sin(seed) * 10000) : Math.random();
|
||||
const id = Math.floor(random * 1000000);
|
||||
const statuses = ['active', 'inactive', 'suspended', 'error'] as const;
|
||||
return {
|
||||
gameUserId: faker.string.numeric(10),
|
||||
zulipUserId: faker.number.int({ min: 1, max: 999999 }),
|
||||
zulipEmail: faker.internet.email(),
|
||||
zulipFullName: faker.person.fullName(),
|
||||
zulipApiKeyEncrypted: faker.string.alphanumeric(32),
|
||||
status: faker.helpers.arrayElement(['active', 'inactive', 'suspended', 'error'] as const)
|
||||
gameUserId: String(id),
|
||||
zulipUserId: Math.floor(random * 999999) + 1,
|
||||
zulipEmail: `zulip${id}@example.com`,
|
||||
zulipFullName: `Zulip User ${id}`,
|
||||
zulipApiKeyEncrypted: `encrypted_key_${id}`,
|
||||
status: statuses[Math.floor(random * 4)]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,10 +113,10 @@ export class PropertyTestGenerators {
|
||||
* 生成随机分页参数
|
||||
*/
|
||||
static generatePaginationParams(seed?: number) {
|
||||
this.setupFaker(seed);
|
||||
const random = seed ? Math.sin(seed) * 10000 - Math.floor(Math.sin(seed) * 10000) : Math.random();
|
||||
return {
|
||||
limit: faker.number.int({ min: 1, max: 100 }),
|
||||
offset: faker.number.int({ min: 0, max: 1000 })
|
||||
limit: Math.floor(random * 100) + 1,
|
||||
offset: Math.floor(random * 1000)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user