Skip to content

Commit 5ef8ffc

Browse files
committed
docs: Update code examples to align with lessons learned (#2627)
1 parent 7dabae3 commit 5ef8ffc

File tree

1 file changed

+14
-32
lines changed
  • docs/dev-notes/2025-09-23/contest-task-pair-mapping

1 file changed

+14
-32
lines changed

docs/dev-notes/2025-09-23/contest-task-pair-mapping/plan.md

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,20 @@ export async function createContestTaskPair(
8888
contestId: string,
8989
taskTableIndex: string,
9090
taskId: string,
91-
): Promise<void> {
91+
): Promise<ContestTaskPair> {
9292
try {
93-
// 既存レコードの確認
94-
const existingRecord = await getContestTaskPair(contestId, taskId);
95-
96-
if (existingRecord) {
97-
console.log(`ContestTaskPair already exists: contestId=${contestId}, taskId=${taskId}`);
98-
return;
99-
}
100-
101-
// 新規レコード作成
102-
let contestTaskPair: ContestTaskPair | undefined;
103-
104-
contestTaskPair = await db.contestTaskPair.create({
93+
return await db.contestTaskPair.create({
10594
data: {
10695
contestId,
10796
taskTableIndex,
10897
taskId,
10998
},
11099
});
111-
112-
console.log('Created ContestTaskPair:', contestTaskPair);
113100
} catch (error) {
114-
if (error && typeof error === 'object' && 'code' in error && (error as any).code === 'P2002') {
115-
console.log(`Found ContestTaskPair (race): contestId=${contestId}, taskId=${taskId}`);
116-
return;
101+
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === 'P2002') {
102+
const errorMessage = `ContestTaskPair already exists: contestId=${contestId}, taskId=${taskId}`;
103+
console.error(errorMessage);
104+
throw new Error(errorMessage);
117105
}
118106

119107
console.error('Failed to create ContestTaskPair:', error);
@@ -128,19 +116,9 @@ export async function updateContestTaskPair(
128116
contestId: string,
129117
taskTableIndex: string,
130118
taskId: string,
131-
): Promise<void> {
119+
): Promise<ContestTaskPair> {
132120
try {
133-
// 既存レコードの確認
134-
const existingRecord = await getContestTaskPair(contestId, taskId);
135-
136-
if (!existingRecord) {
137-
const errorMessage = `Not found ContestTaskPair: contestId=${contestId}, taskId=${taskId}`;
138-
console.log(errorMessage);
139-
throw new Error(errorMessage);
140-
}
141-
142-
// レコード更新
143-
const updatedContestTaskPair = await db.contestTaskPair.update({
121+
return await db.contestTaskPair.update({
144122
where: {
145123
contestId_taskId: {
146124
contestId,
@@ -151,9 +129,13 @@ export async function updateContestTaskPair(
151129
taskTableIndex,
152130
},
153131
});
154-
155-
console.log('Updated ContestTaskPair:', updatedContestTaskPair);
156132
} catch (error) {
133+
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === 'P2025') {
134+
const errorMessage = `Not found ContestTaskPair: contestId=${contestId}, taskId=${taskId}`;
135+
console.error(errorMessage);
136+
throw new Error(errorMessage);
137+
}
138+
157139
console.error('Failed to update ContestTaskPair:', error);
158140
throw error;
159141
}

0 commit comments

Comments
 (0)