feat: add in-game social test lab
This commit is contained in:
18
src/core/db/users/migrations/add-is-test-account.sql
Normal file
18
src/core/db/users/migrations/add-is-test-account.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
ALTER TABLE `users`
|
||||
ADD COLUMN IF NOT EXISTS `is_test_account` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否为开发测试实验室账号' AFTER `role`;
|
||||
|
||||
SET @test_account_index_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'users'
|
||||
AND index_name = 'idx_users_is_test_account'
|
||||
);
|
||||
SET @test_account_index_sql := IF(
|
||||
@test_account_index_exists = 0,
|
||||
'CREATE INDEX `idx_users_is_test_account` ON `users` (`is_test_account`)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE test_account_index_stmt FROM @test_account_index_sql;
|
||||
EXECUTE test_account_index_stmt;
|
||||
DEALLOCATE PREPARE test_account_index_stmt;
|
||||
@@ -36,7 +36,8 @@ import {
|
||||
IsOptional,
|
||||
Length,
|
||||
IsNotEmpty,
|
||||
IsEnum
|
||||
IsEnum,
|
||||
IsBoolean
|
||||
} from 'class-validator';
|
||||
import { UserStatus } from './user_status.enum';
|
||||
import { USER_ROLES, FIELD_LIMITS } from './users.constants';
|
||||
@@ -91,6 +92,10 @@ export class CreateUserDto {
|
||||
@Length(1, FIELD_LIMITS.USERNAME_MAX_LENGTH, { message: `用户名长度需在1-${FIELD_LIMITS.USERNAME_MAX_LENGTH}字符之间` })
|
||||
username: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
is_test_account?: boolean;
|
||||
|
||||
/**
|
||||
* 邮箱地址
|
||||
*
|
||||
@@ -272,4 +277,4 @@ export class CreateUserDto {
|
||||
@IsOptional()
|
||||
@IsEnum(UserStatus, { message: '用户状态必须是有效的枚举值' })
|
||||
status?: UserStatus = UserStatus.ACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +358,17 @@ export class Users {
|
||||
})
|
||||
role: number;
|
||||
|
||||
/**
|
||||
* 仅供开发/测试实验室创建的合成玩家使用。生产业务不得据此授予权限。
|
||||
*/
|
||||
@Column({
|
||||
type: 'boolean',
|
||||
nullable: false,
|
||||
default: false,
|
||||
comment: '是否为测试实验室账号'
|
||||
})
|
||||
is_test_account: boolean;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
|
||||
@@ -157,6 +157,7 @@ export class UsersService extends BaseUsersService {
|
||||
user.github_id = createUserDto.github_id || null;
|
||||
user.avatar_url = createUserDto.avatar_url || null;
|
||||
user.role = createUserDto.role || USER_ROLES.NORMAL_USER;
|
||||
user.is_test_account = createUserDto.is_test_account === true;
|
||||
user.email_verified = createUserDto.email_verified || false;
|
||||
user.status = createUserDto.status || UserStatus.ACTIVE;
|
||||
|
||||
@@ -711,4 +712,4 @@ export class UsersService extends BaseUsersService {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,6 +257,7 @@ export class UsersMemoryService extends BaseUsersService {
|
||||
user.github_id = createUserDto.github_id || null;
|
||||
user.avatar_url = createUserDto.avatar_url || null;
|
||||
user.role = createUserDto.role || USER_ROLES.NORMAL_USER;
|
||||
user.is_test_account = createUserDto.is_test_account === true;
|
||||
user.email_verified = createUserDto.email_verified || false;
|
||||
user.status = createUserDto.status || UserStatus.ACTIVE;
|
||||
user.created_at = new Date();
|
||||
|
||||
Reference in New Issue
Block a user