2
0

🗃️ Add createdAt to sort transcript answers

This commit is contained in:
Baptiste Arnaud
2024-05-22 15:44:49 +02:00
parent ab9e36f68d
commit 79ad1f63de
6 changed files with 34 additions and 17 deletions

View File

@ -76,12 +76,14 @@ export const getResult = authenticatedProcedure
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
answersV2: { answersV2: {
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
}, },
@ -95,7 +97,9 @@ export const getResult = authenticatedProcedure
return { return {
result: resultWithAnswersSchema.parse({ result: resultWithAnswersSchema.parse({
...result, ...result,
answers: answers.concat(answersV2), answers: answers
.concat(answersV2)
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()),
}), }),
} }
}) })

View File

@ -109,12 +109,14 @@ export const getResults = authenticatedProcedure
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
answersV2: { answersV2: {
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
}, },
@ -127,11 +129,14 @@ export const getResults = authenticatedProcedure
} }
return { return {
results: z results: z.array(resultWithAnswersSchema).parse(
.array(resultWithAnswersSchema) results.map((r) => ({
.parse( ...r,
results.map((r) => ({ ...r, answers: r.answersV2.concat(r.answers) })) answers: r.answersV2
), .concat(r.answers)
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()),
}))
),
nextCursor, nextCursor,
} }
}) })

View File

@ -261,12 +261,14 @@ const parseResultTranscriptProps = async (
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
answersV2: { answersV2: {
select: { select: {
blockId: true, blockId: true,
content: true, content: true,
createdAt: true,
}, },
}, },
setVariableHistory: { setVariableHistory: {
@ -281,7 +283,9 @@ const parseResultTranscriptProps = async (
}) })
if (!result) return if (!result) return
return { return {
answers: result.answersV2.concat(result.answers), answers: result.answersV2
.concat(result.answers)
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()),
setVariableHistory: ( setVariableHistory: (
result.setVariableHistory as SetVariableHistoryItem[] result.setVariableHistory as SetVariableHistoryItem[]
).sort((a, b) => a.index - b.index), ).sort((a, b) => a.index - b.index),

View File

@ -320,11 +320,12 @@ model Answer {
} }
model AnswerV2 { model AnswerV2 {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
blockId String createdAt DateTime @default(now())
content String @db.Text blockId String
resultId String content String @db.Text
result Result @relation(fields: [resultId], references: [id], onDelete: Cascade) resultId String
result Result @relation(fields: [resultId], references: [id], onDelete: Cascade)
@@index([resultId]) @@index([resultId])
@@index([blockId]) @@index([blockId])

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "AnswerV2" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

View File

@ -300,11 +300,12 @@ model Answer {
} }
model AnswerV2 { model AnswerV2 {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
blockId String createdAt DateTime @default(now())
content String blockId String
resultId String content String
result Result @relation(fields: [resultId], references: [id], onDelete: Cascade) resultId String
result Result @relation(fields: [resultId], references: [id], onDelete: Cascade)
@@index([blockId]) @@index([blockId])
} }