mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-17 03:21:51 -05:00
fix: made ttc and userAgent optional (#1727)
This commit is contained in:
committed by
GitHub
parent
25525e0b03
commit
48e9148728
@@ -63,7 +63,7 @@ export default function SummaryMetadata({
|
||||
const ttc = useMemo(() => {
|
||||
let validTtcResponsesCountAcc = 0; //stores the count of responses that contains a _total value
|
||||
const ttc = responses.reduce((acc, response) => {
|
||||
if (response.ttc._total) {
|
||||
if (response.ttc?._total) {
|
||||
validTtcResponsesCountAcc++;
|
||||
return acc + response.ttc._total;
|
||||
}
|
||||
|
||||
@@ -270,14 +270,15 @@ export const createResponseLegacy = async (responseInput: TResponseLegacyInput):
|
||||
if (responseInput.personId) {
|
||||
person = await getPerson(responseInput.personId);
|
||||
}
|
||||
const ttcTemp = responseInput.ttc;
|
||||
const ttcTemp = responseInput.ttc ?? {};
|
||||
const questionId = Object.keys(ttcTemp)[0];
|
||||
const ttc = responseInput.finished
|
||||
? {
|
||||
...ttcTemp,
|
||||
_total: ttcTemp[questionId], // Add _total property with the same value
|
||||
}
|
||||
: ttcTemp;
|
||||
const ttc =
|
||||
responseInput.finished && responseInput.ttc
|
||||
? {
|
||||
...ttcTemp,
|
||||
_total: ttcTemp[questionId], // Add _total property with the same value
|
||||
}
|
||||
: ttcTemp;
|
||||
const responsePrisma = await prisma.response.create({
|
||||
data: {
|
||||
survey: {
|
||||
@@ -512,7 +513,11 @@ export const updateResponse = async (
|
||||
...currentResponse.data,
|
||||
...responseInput.data,
|
||||
};
|
||||
const ttc = responseInput.finished ? calculateTtcTotal(responseInput.ttc) : responseInput.ttc;
|
||||
const ttc = responseInput.ttc
|
||||
? responseInput.finished
|
||||
? calculateTtcTotal(responseInput.ttc)
|
||||
: responseInput.ttc
|
||||
: {};
|
||||
|
||||
const responsePrisma = await prisma.response.update({
|
||||
where: {
|
||||
|
||||
@@ -37,11 +37,13 @@ export type TResponseNote = z.infer<typeof ZResponseNote>;
|
||||
export const ZResponseMeta = z.object({
|
||||
source: z.string().optional(),
|
||||
url: z.string().optional(),
|
||||
userAgent: z.object({
|
||||
browser: z.string().optional(),
|
||||
os: z.string().optional(),
|
||||
device: z.string().optional(),
|
||||
}),
|
||||
userAgent: z
|
||||
.object({
|
||||
browser: z.string().optional(),
|
||||
os: z.string().optional(),
|
||||
device: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type TResponseMeta = z.infer<typeof ZResponseMeta>;
|
||||
@@ -55,7 +57,7 @@ export const ZResponse = z.object({
|
||||
personAttributes: ZResponsePersonAttributes,
|
||||
finished: z.boolean(),
|
||||
data: ZResponseData,
|
||||
ttc: ZResponseTtc,
|
||||
ttc: ZResponseTtc.optional(),
|
||||
notes: z.array(ZResponseNote),
|
||||
tags: z.array(ZTag),
|
||||
meta: ZResponseMeta.nullable(),
|
||||
@@ -77,7 +79,7 @@ export const ZResponseInput = z.object({
|
||||
singleUseId: z.string().nullable().optional(),
|
||||
finished: z.boolean(),
|
||||
data: ZResponseData,
|
||||
ttc: ZResponseTtc,
|
||||
ttc: ZResponseTtc.optional(),
|
||||
meta: z
|
||||
.object({
|
||||
source: z.string().optional(),
|
||||
@@ -104,7 +106,7 @@ export type TResponseLegacyInput = z.infer<typeof ZResponseLegacyInput>;
|
||||
export const ZResponseUpdateInput = z.object({
|
||||
finished: z.boolean(),
|
||||
data: ZResponseData,
|
||||
ttc: ZResponseTtc,
|
||||
ttc: ZResponseTtc.optional(),
|
||||
});
|
||||
|
||||
export type TResponseUpdateInput = z.infer<typeof ZResponseUpdateInput>;
|
||||
@@ -118,7 +120,7 @@ export type TResponseWithSurvey = z.infer<typeof ZResponseWithSurvey>;
|
||||
export const ZResponseUpdate = z.object({
|
||||
finished: z.boolean(),
|
||||
data: ZResponseData,
|
||||
ttc: ZResponseTtc,
|
||||
ttc: ZResponseTtc.optional(),
|
||||
meta: z
|
||||
.object({
|
||||
url: z.string().optional(),
|
||||
|
||||
Reference in New Issue
Block a user