feat(v2.4): 切换根数据领域主写

This commit is contained in:
2026-07-08 12:07:35 +08:00
parent d82e8729af
commit 142800f75b
21 changed files with 977 additions and 73 deletions

View File

@@ -0,0 +1,8 @@
ALTER TABLE "versions" ADD COLUMN "status" TEXT NOT NULL DEFAULT 'planned';
ALTER TABLE "versions" ADD COLUMN "current_stage" TEXT;
ALTER TABLE "versions" ADD COLUMN "start_date" TIMESTAMP(3);
ALTER TABLE "versions" ADD COLUMN "expected_release_date" TIMESTAMP(3);
ALTER TABLE "versions" ADD COLUMN "members" JSONB NOT NULL DEFAULT '[]';
ALTER TABLE "versions" ADD COLUMN "progress" JSONB NOT NULL DEFAULT '[]';
ALTER TABLE "versions" ADD COLUMN "priority" INTEGER;
ALTER TABLE "versions" ADD COLUMN "links" JSONB NOT NULL DEFAULT '{}';

View File

@@ -76,7 +76,15 @@ model Version {
projectId String? @map("project_id")
name String
description String @default("")
status String @default("planned")
currentStage String? @map("current_stage")
startDate DateTime? @map("start_date")
expectedReleaseDate DateTime? @map("expected_release_date")
releaseDate DateTime? @map("release_date")
members Json @default("[]")
progress Json @default("[]")
priority Int?
links Json @default("{}")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

View File

@@ -3,7 +3,9 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
import { ApiTimingInterceptor } from './common/interceptors/api-timing.interceptor';
import { PrismaModule } from './prisma/prisma.module';
import { ProductModule } from './modules/product/product.module';
import { ProjectModule } from './modules/project/project.module';
import { RequirementModule } from './modules/requirement/requirement.module';
import { VersionModule } from './modules/version/version.module';
import { AiModule } from './modules/ai/ai.module';
import { ConfigModule } from './modules/config/config.module';
import { DataModule } from './modules/data/data.module';
@@ -12,7 +14,19 @@ import { V22QueryModule } from './modules/v22-query/v22-query.module';
import { HealthModule } from './modules/health/health.module';
@Module({
imports: [PrismaModule, ProductModule, RequirementModule, ConfigModule, DataModule, MigrationModule, V22QueryModule, HealthModule, AiModule],
imports: [
PrismaModule,
ProductModule,
ProjectModule,
VersionModule,
RequirementModule,
ConfigModule,
DataModule,
MigrationModule,
V22QueryModule,
HealthModule,
AiModule,
],
controllers: [],
providers: [
{

View File

@@ -29,7 +29,15 @@ interface VersionRow {
projectId?: string;
name: string;
description: string;
status: string;
currentStage?: string;
startDate?: string;
expectedReleaseDate?: string;
releaseDate?: string;
members: unknown[];
progress: unknown[];
priority?: number;
links: unknown;
createdAt?: string;
updatedAt?: string;
}
@@ -348,7 +356,15 @@ export function mapAppDataToV22Rows(appData: Record<string, unknown>): V22Mapped
projectId,
name: stringField(version, 'name') ?? versionId,
description: stringField(version, 'description') ?? '',
status: stringField(version, 'status') ?? 'planned',
currentStage: stringField(version, 'currentStage'),
startDate: stringField(version, 'startDate'),
expectedReleaseDate: stringField(version, 'expectedReleaseDate'),
releaseDate: stringField(version, 'releaseDate') ?? stringField(version, 'expectedReleaseDate'),
members: asArray(version.members),
progress: asArray(version.progress),
priority: priorityRank(version.priority),
links: asRecord(version.links) ?? {},
createdAt: stringField(version, 'createdAt') ?? productRow.createdAt,
updatedAt: stringField(version, 'updatedAt') ?? stringField(version, 'createdAt') ?? productRow.updatedAt,
};

View File

@@ -10,7 +10,22 @@ type ProductOverviewItem = {
createdAt?: string;
updatedAt?: string;
projects?: { id: string; name: string; description?: string; createdAt?: string }[];
versions?: { id: string; name: string; releaseDate?: string | null; createdAt?: string }[];
versions?: {
id: string;
productId?: string;
projectId?: string | null;
name: string;
status?: string;
currentStage?: string | null;
startDate?: string | null;
expectedReleaseDate?: string | null;
releaseDate?: string | null;
members?: unknown[];
progress?: unknown[];
priority?: string | number | null;
links?: unknown;
createdAt?: string;
}[];
_count?: { requirements?: number; projects?: number; versions?: number };
};
@@ -23,30 +38,25 @@ export class ProductService {
}
async findAll() {
const overview = await this.getAppDataOverview();
if (overview) {
return overview.map((product) => {
const normalized = this.normalizeOverviewProduct(product);
const { projects: _projects, versions: _versions, ...rest } = normalized;
return rest;
});
}
return this.prisma.product.findMany({
const products = await this.prisma.product.findMany({
orderBy: { createdAt: 'desc' },
include: {
_count: { select: { requirements: true, projects: true } },
_count: { select: { requirements: true, projects: true, versions: true } },
},
});
if (products.length > 0) return products;
const overview = await this.getAppDataOverview();
if (!overview) return [];
return overview.map((product) => {
const normalized = this.normalizeOverviewProduct(product);
const { projects: _projects, versions: _versions, ...rest } = normalized;
return rest;
});
}
async findAllWithChildren() {
const overview = await this.getAppDataOverview();
if (overview) {
return overview.map((product) => this.normalizeOverviewProduct(product));
}
return this.prisma.product.findMany({
const products = await this.prisma.product.findMany({
orderBy: { createdAt: 'desc' },
include: {
projects: {
@@ -55,34 +65,57 @@ export class ProductService {
},
versions: {
orderBy: { createdAt: 'desc' },
select: { id: true, name: true, releaseDate: true, createdAt: true },
select: {
id: true,
productId: true,
projectId: true,
name: true,
description: true,
status: true,
currentStage: true,
startDate: true,
expectedReleaseDate: true,
releaseDate: true,
members: true,
progress: true,
priority: true,
links: true,
createdAt: true,
updatedAt: true,
},
},
_count: { select: { requirements: true, projects: true, versions: true } },
},
});
if (products.length > 0) return products.map((product) => this.normalizeRelationProduct(product));
const overview = await this.getAppDataOverview();
if (!overview) return [];
return overview.map((product) => this.normalizeOverviewProduct(product));
}
async findOne(id: string) {
const overview = await this.getAppDataOverview();
if (overview) {
const product = overview.find((item) => item.id === id);
if (!product) throw new NotFoundException('产品不存在');
return {
...this.normalizeOverviewProduct(product),
requirements: [],
};
}
const product = await this.prisma.product.findUnique({
where: { id },
include: {
requirements: { orderBy: { createdAt: 'desc' } },
projects: {
orderBy: { createdAt: 'desc' },
select: { id: true, name: true, description: true, createdAt: true },
},
versions: { orderBy: { createdAt: 'desc' } },
_count: { select: { projects: true } },
},
});
if (!product) throw new NotFoundException('产品不存在');
return product;
if (product) return product;
const overview = await this.getAppDataOverview();
const fallback = overview?.find((item) => item.id === id);
if (!fallback) throw new NotFoundException('产品不存在');
return {
...this.normalizeOverviewProduct(fallback),
requirements: [],
};
}
async update(id: string, dto: UpdateProductDto) {
@@ -123,4 +156,53 @@ export class ProductService {
},
};
}
private normalizeRelationProduct(product: any) {
const projects = product.projects ?? [];
const versions = (product.versions ?? []).map((version: any) => ({
...version,
createdAt: toIso(version.createdAt),
updatedAt: toIso(version.updatedAt),
startDate: toIsoOrNull(version.startDate),
expectedReleaseDate: toIsoOrNull(version.expectedReleaseDate),
releaseDate: toIsoOrNull(version.releaseDate),
members: Array.isArray(version.members) ? version.members : [],
progress: Array.isArray(version.progress) ? version.progress : [],
priority: toPriorityLabel(version.priority),
links: isPlainObject(version.links) ? version.links : {},
}));
return {
...product,
createdAt: toIso(product.createdAt),
updatedAt: toIso(product.updatedAt),
projects: projects.map((project: any) => ({ ...project, createdAt: toIso(project.createdAt) })),
versions,
_count: {
requirements: product._count?.requirements ?? 0,
projects: projects.length,
versions: versions.length,
},
};
}
}
function toIso(value: Date | string | undefined): string {
if (value instanceof Date) return value.toISOString();
return value ?? new Date(0).toISOString();
}
function toIsoOrNull(value: Date | string | null | undefined): string | null {
if (!value) return null;
if (value instanceof Date) return value.toISOString();
return value;
}
function toPriorityLabel(value: number | null | undefined): string | undefined {
if (typeof value !== 'number') return undefined;
return `P${Math.max(0, Math.min(4, Math.floor(value)))}`;
}
function isPlainObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}

View File

@@ -0,0 +1,11 @@
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
export class CreateProjectDto {
@IsString()
@IsNotEmpty()
name!: string;
@IsString()
@IsOptional()
description?: string;
}

View File

@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateProjectDto } from './create-project.dto';
export class UpdateProjectDto extends PartialType(CreateProjectDto) {}

View File

@@ -0,0 +1,33 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { ProjectService } from './project.service';
import { CreateProjectDto } from './dto/create-project.dto';
import { UpdateProjectDto } from './dto/update-project.dto';
@Controller('products/:productId/projects')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Post()
create(@Param('productId') productId: string, @Body() dto: CreateProjectDto) {
return this.projectService.create(productId, dto);
}
@Get()
findAll(@Param('productId') productId: string) {
return this.projectService.findAll(productId);
}
@Patch(':projectId')
update(
@Param('productId') productId: string,
@Param('projectId') projectId: string,
@Body() dto: UpdateProjectDto,
) {
return this.projectService.update(productId, projectId, dto);
}
@Delete(':projectId')
remove(@Param('productId') productId: string, @Param('projectId') projectId: string) {
return this.projectService.remove(productId, projectId);
}
}

View File

@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ProjectController } from './project.controller';
import { ProjectService } from './project.service';
@Module({
controllers: [ProjectController],
providers: [ProjectService],
})
export class ProjectModule {}

View File

@@ -0,0 +1,83 @@
import { NotFoundException } from '@nestjs/common';
import { ProjectService } from './project.service';
describe('ProjectService domain writes', () => {
const makeService = () => {
const prisma = {
product: {
findUnique: jest.fn(),
},
project: {
create: jest.fn(),
delete: jest.fn(),
findFirst: jest.fn(),
findMany: jest.fn(),
update: jest.fn(),
},
};
return {
prisma,
service: new ProjectService(prisma as any),
};
};
it('creates projects directly under a product relation row', async () => {
const { prisma, service } = makeService();
prisma.product.findUnique.mockResolvedValue({ id: 'product-1' });
prisma.project.create.mockResolvedValue({ id: 'project-1', productId: 'product-1' });
await service.create('product-1', { name: 'CRM', description: 'Customer system' });
expect(prisma.project.create).toHaveBeenCalledWith({
data: {
productId: 'product-1',
name: 'CRM',
description: 'Customer system',
},
});
});
it('lists projects by product id', async () => {
const { prisma, service } = makeService();
prisma.project.findMany.mockResolvedValue([]);
await service.findAll('product-1');
expect(prisma.project.findMany).toHaveBeenCalledWith({
where: { productId: 'product-1' },
orderBy: { createdAt: 'desc' },
});
});
it('updates projects only inside their product scope', async () => {
const { prisma, service } = makeService();
prisma.project.findFirst.mockResolvedValue({ id: 'project-1', productId: 'product-1' });
prisma.project.update.mockResolvedValue({ id: 'project-1', name: 'CRM v2' });
await service.update('product-1', 'project-1', { name: 'CRM v2' });
expect(prisma.project.update).toHaveBeenCalledWith({
where: { id: 'project-1' },
data: { name: 'CRM v2' },
});
});
it('throws when updating a project outside the product scope', async () => {
const { prisma, service } = makeService();
prisma.project.findFirst.mockResolvedValue(null);
await expect(service.update('product-1', 'project-404', { name: 'Ghost' })).rejects.toBeInstanceOf(NotFoundException);
expect(prisma.project.update).not.toHaveBeenCalled();
});
it('deletes projects only inside their product scope', async () => {
const { prisma, service } = makeService();
prisma.project.findFirst.mockResolvedValue({ id: 'project-1', productId: 'product-1' });
prisma.project.delete.mockResolvedValue({ id: 'project-1' });
await service.remove('product-1', 'project-1');
expect(prisma.project.delete).toHaveBeenCalledWith({ where: { id: 'project-1' } });
});
});

View File

@@ -0,0 +1,53 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
import { CreateProjectDto } from './dto/create-project.dto';
import { UpdateProjectDto } from './dto/update-project.dto';
@Injectable()
export class ProjectService {
constructor(private readonly prisma: PrismaService) {}
async create(productId: string, dto: CreateProjectDto) {
await this.ensureProductExists(productId);
return this.prisma.project.create({
data: {
productId,
name: dto.name,
description: dto.description ?? '',
},
});
}
findAll(productId: string) {
return this.prisma.project.findMany({
where: { productId },
orderBy: { createdAt: 'desc' },
});
}
async update(productId: string, projectId: string, dto: UpdateProjectDto) {
await this.ensureProjectInProduct(productId, projectId);
return this.prisma.project.update({
where: { id: projectId },
data: {
...(dto.name !== undefined && { name: dto.name }),
...(dto.description !== undefined && { description: dto.description }),
},
});
}
async remove(productId: string, projectId: string) {
await this.ensureProjectInProduct(productId, projectId);
return this.prisma.project.delete({ where: { id: projectId } });
}
private async ensureProductExists(productId: string) {
const product = await this.prisma.product.findUnique({ where: { id: productId } });
if (!product) throw new NotFoundException('产品不存在');
}
private async ensureProjectInProduct(productId: string, projectId: string) {
const project = await this.prisma.project.findFirst({ where: { id: projectId, productId } });
if (!project) throw new NotFoundException('项目不存在');
}
}

View File

@@ -0,0 +1,50 @@
import { IsArray, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
export class CreateVersionDto {
@IsString()
@IsOptional()
projectId?: string;
@IsString()
@IsNotEmpty()
name!: string;
@IsString()
@IsOptional()
description?: string;
@IsString()
@IsOptional()
status?: string;
@IsString()
@IsOptional()
currentStage?: string;
@IsString()
@IsOptional()
startDate?: string | null;
@IsString()
@IsOptional()
expectedReleaseDate?: string | null;
@IsString()
@IsOptional()
releaseDate?: string | null;
@IsArray()
@IsOptional()
members?: unknown[];
@IsArray()
@IsOptional()
progress?: unknown[];
@IsOptional()
priority?: string | number | null;
@IsObject()
@IsOptional()
links?: Record<string, unknown>;
}

View File

@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateVersionDto } from './create-version.dto';
export class UpdateVersionDto extends PartialType(CreateVersionDto) {}

View File

@@ -0,0 +1,47 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { VersionService } from './version.service';
import { CreateVersionDto } from './dto/create-version.dto';
import { UpdateVersionDto } from './dto/update-version.dto';
@Controller('products/:productId')
export class VersionController {
constructor(private readonly versionService: VersionService) {}
@Post('versions')
create(@Param('productId') productId: string, @Body() dto: CreateVersionDto) {
return this.versionService.create(productId, dto);
}
@Get('versions')
findAll(@Param('productId') productId: string) {
return this.versionService.findAll(productId);
}
@Post('projects/:projectId/versions')
createForProject(
@Param('productId') productId: string,
@Param('projectId') projectId: string,
@Body() dto: CreateVersionDto,
) {
return this.versionService.create(productId, dto, projectId);
}
@Get('projects/:projectId/versions')
findAllForProject(@Param('productId') productId: string, @Param('projectId') projectId: string) {
return this.versionService.findAll(productId, projectId);
}
@Patch('versions/:versionId')
update(
@Param('productId') productId: string,
@Param('versionId') versionId: string,
@Body() dto: UpdateVersionDto,
) {
return this.versionService.update(productId, versionId, dto);
}
@Delete('versions/:versionId')
remove(@Param('productId') productId: string, @Param('versionId') versionId: string) {
return this.versionService.remove(productId, versionId);
}
}

View File

@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { VersionController } from './version.controller';
import { VersionService } from './version.service';
@Module({
controllers: [VersionController],
providers: [VersionService],
})
export class VersionModule {}

View File

@@ -0,0 +1,117 @@
import { NotFoundException } from '@nestjs/common';
import { VersionService } from './version.service';
describe('VersionService domain writes', () => {
const makeService = () => {
const tx = {
requirement: { updateMany: jest.fn() },
versionPlan: { deleteMany: jest.fn() },
devTask: { deleteMany: jest.fn() },
testCase: { deleteMany: jest.fn() },
bug: { deleteMany: jest.fn() },
version: { delete: jest.fn() },
};
const prisma = {
product: { findUnique: jest.fn() },
project: { findFirst: jest.fn() },
version: {
create: jest.fn(),
findFirst: jest.fn(),
findMany: jest.fn(),
update: jest.fn(),
},
$transaction: jest.fn(async (callback: (client: typeof tx) => Promise<unknown>) => callback(tx)),
};
return {
prisma,
service: new VersionService(prisma as any),
tx,
};
};
it('creates versions with root metadata in the relation table', async () => {
const { prisma, service } = makeService();
prisma.product.findUnique.mockResolvedValue({ id: 'product-1' });
prisma.project.findFirst.mockResolvedValue({ id: 'project-1', productId: 'product-1' });
prisma.version.create.mockResolvedValue({ id: 'version-1', productId: 'product-1' });
await service.create('product-1', {
projectId: 'project-1',
name: 'CRM 1.0',
status: 'developing',
expectedReleaseDate: '2026-08-01T00:00:00.000Z',
members: [{ role: 'frontend', name: '张三' }],
priority: 'P1',
});
expect(prisma.version.create).toHaveBeenCalledWith({
data: expect.objectContaining({
productId: 'product-1',
projectId: 'project-1',
name: 'CRM 1.0',
status: 'developing',
expectedReleaseDate: new Date('2026-08-01T00:00:00.000Z'),
members: [{ role: 'frontend', name: '张三' }],
priority: 1,
}),
});
});
it('rejects versions for projects outside the product scope', async () => {
const { prisma, service } = makeService();
prisma.product.findUnique.mockResolvedValue({ id: 'product-1' });
prisma.project.findFirst.mockResolvedValue(null);
await expect(
service.create('product-1', { projectId: 'project-404', name: 'CRM 1.0' }),
).rejects.toBeInstanceOf(NotFoundException);
expect(prisma.version.create).not.toHaveBeenCalled();
});
it('lists versions by product and optional project scope', async () => {
const { prisma, service } = makeService();
prisma.version.findMany.mockResolvedValue([]);
await service.findAll('product-1', 'project-1');
expect(prisma.version.findMany).toHaveBeenCalledWith({
where: { productId: 'product-1', projectId: 'project-1' },
orderBy: { createdAt: 'desc' },
});
});
it('updates versions only inside their product scope', async () => {
const { prisma, service } = makeService();
prisma.version.findFirst.mockResolvedValue({ id: 'version-1', productId: 'product-1' });
prisma.version.update.mockResolvedValue({ id: 'version-1', status: 'paused' });
await service.update('product-1', 'version-1', { status: 'paused', releaseDate: '2026-09-01T00:00:00.000Z' });
expect(prisma.version.update).toHaveBeenCalledWith({
where: { id: 'version-1' },
data: {
status: 'paused',
releaseDate: new Date('2026-09-01T00:00:00.000Z'),
},
});
});
it('deletes version-scoped data and releases linked requirements before deleting a version', async () => {
const { prisma, service, tx } = makeService();
prisma.version.findFirst.mockResolvedValue({ id: 'version-1', productId: 'product-1' });
tx.version.delete.mockResolvedValue({ id: 'version-1' });
await service.remove('product-1', 'version-1');
expect(tx.requirement.updateMany).toHaveBeenCalledWith({
where: { productId: 'product-1', versionId: 'version-1' },
data: { versionId: null },
});
expect(tx.versionPlan.deleteMany).toHaveBeenCalledWith({ where: { versionId: 'version-1' } });
expect(tx.devTask.deleteMany).toHaveBeenCalledWith({ where: { versionId: 'version-1' } });
expect(tx.testCase.deleteMany).toHaveBeenCalledWith({ where: { versionId: 'version-1' } });
expect(tx.bug.deleteMany).toHaveBeenCalledWith({ where: { versionId: 'version-1' } });
expect(tx.version.delete).toHaveBeenCalledWith({ where: { id: 'version-1' } });
});
});

View File

@@ -0,0 +1,102 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
import { CreateVersionDto } from './dto/create-version.dto';
import { UpdateVersionDto } from './dto/update-version.dto';
@Injectable()
export class VersionService {
constructor(private readonly prisma: PrismaService) {}
async create(productId: string, dto: CreateVersionDto, scopedProjectId?: string) {
await this.ensureProductExists(productId);
const projectId = scopedProjectId ?? dto.projectId;
if (projectId) await this.ensureProjectInProduct(productId, projectId);
const data = this.toVersionData(dto);
return this.prisma.version.create({
data: {
...data,
productId,
projectId,
name: dto.name,
} as any,
});
}
findAll(productId: string, projectId?: string) {
return this.prisma.version.findMany({
where: { productId, ...(projectId ? { projectId } : {}) },
orderBy: { createdAt: 'desc' },
});
}
async update(productId: string, versionId: string, dto: UpdateVersionDto) {
await this.ensureVersionInProduct(productId, versionId);
if (dto.projectId) await this.ensureProjectInProduct(productId, dto.projectId);
return this.prisma.version.update({
where: { id: versionId },
data: this.toVersionData(dto) as any,
});
}
async remove(productId: string, versionId: string) {
await this.ensureVersionInProduct(productId, versionId);
return this.prisma.$transaction(async (tx) => {
await tx.requirement.updateMany({
where: { productId, versionId },
data: { versionId: null },
});
await tx.versionPlan.deleteMany({ where: { versionId } });
await tx.devTask.deleteMany({ where: { versionId } });
await tx.testCase.deleteMany({ where: { versionId } });
await tx.bug.deleteMany({ where: { versionId } });
return tx.version.delete({ where: { id: versionId } });
});
}
private toVersionData(dto: CreateVersionDto | UpdateVersionDto) {
return {
...(dto.projectId !== undefined && { projectId: dto.projectId }),
...(dto.name !== undefined && { name: dto.name }),
...(dto.description !== undefined && { description: dto.description }),
...(dto.status !== undefined && { status: dto.status }),
...(dto.currentStage !== undefined && { currentStage: dto.currentStage }),
...(dto.startDate !== undefined && { startDate: parseOptionalDate(dto.startDate) }),
...(dto.expectedReleaseDate !== undefined && { expectedReleaseDate: parseOptionalDate(dto.expectedReleaseDate) }),
...(dto.releaseDate !== undefined && { releaseDate: parseOptionalDate(dto.releaseDate) }),
...(dto.members !== undefined && { members: dto.members }),
...(dto.progress !== undefined && { progress: dto.progress }),
...(dto.priority !== undefined && { priority: priorityToNumber(dto.priority) }),
...(dto.links !== undefined && { links: dto.links }),
};
}
private async ensureProductExists(productId: string) {
const product = await this.prisma.product.findUnique({ where: { id: productId } });
if (!product) throw new NotFoundException('产品不存在');
}
private async ensureProjectInProduct(productId: string, projectId: string) {
const project = await this.prisma.project.findFirst({ where: { id: projectId, productId } });
if (!project) throw new NotFoundException('项目不存在');
}
private async ensureVersionInProduct(productId: string, versionId: string) {
const version = await this.prisma.version.findFirst({ where: { id: versionId, productId } });
if (!version) throw new NotFoundException('版本不存在');
}
}
function parseOptionalDate(value: string | null | undefined): Date | null {
if (!value) return null;
return new Date(value);
}
function priorityToNumber(value: string | number | null | undefined): number | null {
if (value === null || value === undefined || value === '') return null;
if (typeof value === 'number') return Number.isFinite(value) ? value : null;
const match = /^P([0-4])$/i.exec(value.trim());
if (match) return Number(match[1]);
const parsed = Number(value);
return Number.isFinite(parsed) ? Math.max(0, Math.min(4, Math.floor(parsed))) : null;
}