2023-06-01 20:29:13 +00:00
|
|
|
import type { Field, Response } from "../types/types";
|
|
|
|
|
|
|
|
export default function transformResponse({
|
|
|
|
field,
|
|
|
|
value,
|
|
|
|
}: {
|
|
|
|
field: Field;
|
2023-08-23 15:12:51 +00:00
|
|
|
value: Response[string]["value"] | undefined;
|
2023-06-01 20:29:13 +00:00
|
|
|
}) {
|
2023-08-23 15:12:51 +00:00
|
|
|
if (!value) {
|
|
|
|
return "";
|
|
|
|
}
|
2023-06-01 20:29:13 +00:00
|
|
|
// type="number" still gives value as a string but we need to store that as number so that number operators can work.
|
2023-08-23 15:12:51 +00:00
|
|
|
if (field.type === "number") {
|
|
|
|
if (typeof value === "string") {
|
|
|
|
return Number(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
if (field.type === "multiselect") {
|
|
|
|
if (value instanceof Array) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
.toString()
|
|
|
|
.split(",")
|
|
|
|
.map((v) => v.trim());
|
|
|
|
}
|
|
|
|
return value;
|
2023-06-01 20:29:13 +00:00
|
|
|
}
|