mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
34 lines
900 B
TypeScript
34 lines
900 B
TypeScript
import "server-only";
|
|
|
|
import { TResponseDates, TResponseTtc } from "@formbricks/types/responses";
|
|
|
|
export const formatResponseDateFields = (response: TResponseDates): TResponseDates => {
|
|
if (typeof response.createdAt === "string") {
|
|
response.createdAt = new Date(response.createdAt);
|
|
}
|
|
if (typeof response.updatedAt === "string") {
|
|
response.updatedAt = new Date(response.updatedAt);
|
|
}
|
|
|
|
response.notes = response.notes.map((note) => {
|
|
if (typeof note.createdAt === "string") {
|
|
note.createdAt = new Date(note.createdAt);
|
|
}
|
|
|
|
if (typeof note.updatedAt === "string") {
|
|
note.updatedAt = new Date(note.updatedAt);
|
|
}
|
|
|
|
return note;
|
|
});
|
|
|
|
return response;
|
|
};
|
|
|
|
export function calculateTtcTotal(ttc: TResponseTtc) {
|
|
const result = { ...ttc };
|
|
result._total = Object.values(result).reduce((acc: number, val: number) => acc + val, 0);
|
|
|
|
return result;
|
|
}
|