fix: Pass only supported properties of account to CreateAccount (#2445)

Co-authored-by: Shubham Palriwala <spalriwalau@gmail.com>
This commit is contained in:
Gideon Mohr
2024-04-17 10:26:14 +02:00
committed by GitHub
parent 74b4be99a4
commit 4fc8ee8181
2 changed files with 14 additions and 1 deletions

View File

@@ -5,13 +5,15 @@ import { TAccount, TAccountInput, ZAccountInput } from "@formbricks/types/accoun
import { DatabaseError } from "@formbricks/types/errors";
import { validateInputs } from "../utils/validate";
import { filterAccountInputData } from "./utils";
export const createAccount = async (accountData: TAccountInput): Promise<TAccount> => {
validateInputs([accountData, ZAccountInput]);
try {
const supportedAccountData = filterAccountInputData(accountData);
const account = await prisma.account.create({
data: accountData,
data: supportedAccountData,
});
return account;
} catch (error) {

View File

@@ -0,0 +1,11 @@
import { TAccountInput, ZAccountInput } from "@formbricks/types/account";
export const filterAccountInputData = (account: any) => {
const supportedProps = Object.keys(ZAccountInput.shape);
return supportedProps.reduce((acc, prop) => {
if (account.hasOwnProperty(prop)) {
acc[prop] = account[prop];
}
return acc;
}, {} as TAccountInput);
};