mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-08 23:59:38 -06:00
fix: Pass only supported properties of account to CreateAccount (#2445)
Co-authored-by: Shubham Palriwala <spalriwalau@gmail.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
11
packages/lib/account/utils.ts
Normal file
11
packages/lib/account/utils.ts
Normal 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);
|
||||
};
|
||||
Reference in New Issue
Block a user