fix(admin-service): relax changelog and minOsVersion validation

- Changelog: allow empty value, return default "No changelog provided"
- MinOsVersion: allow empty value and single number format (e.g., "24" -> "24.0")

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-09 07:09:03 -08:00
parent 58a359d9b3
commit eceb927d54
2 changed files with 9 additions and 6 deletions

View File

@ -15,16 +15,13 @@ export class Changelog {
}
static create(value: string): Changelog {
// 允许空值,返回默认 changelog
if (!value || value.trim() === '') {
throw new DomainException('Changelog cannot be empty');
return Changelog.empty();
}
const trimmed = value.trim();
if (trimmed.length < 10) {
throw new DomainException('Changelog must be at least 10 characters');
}
if (trimmed.length > 5000) {
throw new DomainException('Changelog cannot exceed 5000 characters');
}

View File

@ -15,12 +15,18 @@ export class MinOsVersion {
}
static create(value: string): MinOsVersion {
// 允许空值,返回默认版本
if (!value || value.trim() === '') {
throw new DomainException('MinOsVersion cannot be empty');
return MinOsVersion.none();
}
const trimmed = value.trim();
// 支持纯数字格式 (e.g., "24") 自动转换为 "24.0"
if (/^\d+$/.test(trimmed)) {
return new MinOsVersion(`${trimmed}.0`);
}
// 验证格式: 数字.数字 或 数字.数字.数字 (e.g., "11.0", "14.0", "5.1.1")
if (!/^\d+(\.\d+){1,2}$/.test(trimmed)) {
throw new DomainException('MinOsVersion must be in format like "11.0" or "5.1.1"');