mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 14:56:36 +00:00
refactor(prisma): 重构测试用例数据及配置的插入逻辑
- 先查找关联的测试用例 - 创建测试用例数据时添加 testcaseId 外键 - 创建测试用例数据配置,关联测试用例数据 ID- 添加了对未找到关联测试用例的错误处理
This commit is contained in:
parent
614552bfc6
commit
6fbe505c40
@ -1123,21 +1123,42 @@ export async function main() {
|
||||
await prisma.user.create({ data: u });
|
||||
}
|
||||
|
||||
// 插入 TestcaseData 和其配置
|
||||
for (const item of testcaseDataConfigData) {
|
||||
// 1. 先找对应的 Testcase
|
||||
const associatedTestcase = await prisma.testcase.findFirst({
|
||||
where: {
|
||||
data: {
|
||||
some: { label: item.label },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!associatedTestcase) {
|
||||
throw new Error(`No associated testcase found for label: ${item.label}`);
|
||||
}
|
||||
|
||||
// 2. 创建 TestcaseData,带上 testcaseId 外键
|
||||
const testcaseData = await prisma.testcaseData.create({
|
||||
data: {
|
||||
label: item.label,
|
||||
value: item.value,
|
||||
index: item.index,
|
||||
// 直接写外键
|
||||
testcaseId: associatedTestcase.id,
|
||||
// 或者:
|
||||
// testcase: { connect: { id: associatedTestcase.id } },
|
||||
},
|
||||
});
|
||||
|
||||
// 3. 创建 TestcaseDataConfig,此模型只需要 testcaseDataId
|
||||
await prisma.testcaseDataConfig.create({
|
||||
data: {
|
||||
testcaseDataId: testcaseData.id,
|
||||
type: item.config.type,
|
||||
pattern: item.config.pattern,
|
||||
// 如果你的 item.config 里还有 min/max/length,也一并写进来:
|
||||
// min: item.config.min,
|
||||
// max: item.config.max,
|
||||
// length: item.config.length,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user