2
0

🚑 Fix answer upsert missing groupId

This commit is contained in:
Baptiste Arnaud
2023-06-30 12:56:50 +02:00
parent b0f25f301b
commit 24126ac9b8
3 changed files with 14 additions and 8 deletions

View File

@@ -193,16 +193,16 @@ const saveAnswer =
(state: SessionState, block: InputBlock, itemId?: string) => (state: SessionState, block: InputBlock, itemId?: string) =>
async (reply: string): Promise<SessionState> => { async (reply: string): Promise<SessionState> => {
const resultId = state.result?.id const resultId = state.result?.id
const answer = { const answer: Omit<Prisma.AnswerUncheckedCreateInput, 'resultId'> = {
resultId,
blockId: block.id, blockId: block.id,
itemId, itemId,
groupId: block.groupId,
content: reply, content: reply,
variableId: block.options.variableId, variableId: block.options.variableId,
storageUsed: 0, storageUsed: 0,
} }
if (state.result.answers.length === 0 && state.result.id) if (state.result.answers.length === 0 && resultId)
await setResultAsStarted(state.result.id) await setResultAsStarted(resultId)
const newSessionState = setNewAnswerInState(state)({ const newSessionState = setNewAnswerInState(state)({
blockId: block.id, blockId: block.id,
@@ -221,9 +221,13 @@ const saveAnswer =
blockId: block.id, blockId: block.id,
groupId: block.groupId, groupId: block.groupId,
}, },
itemId: answer.itemId,
},
create: { ...answer, resultId },
update: {
content: answer.content,
storageUsed: answer.storageUsed,
}, },
create: answer as Prisma.AnswerUncheckedCreateInput,
update: answer,
}) })
} }

View File

@@ -1,5 +1,6 @@
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
previewFeatures = ["extendedWhereUnique"]
} }
datasource db { datasource db {

View File

@@ -1,5 +1,6 @@
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
previewFeatures = ["extendedWhereUnique"]
} }
datasource db { datasource db {