Skip to content

Commit

Permalink
fix: Pass only supported properties of account to CreateAccount (#…
Browse files Browse the repository at this point in the history
…2445)

Co-authored-by: Shubham Palriwala <spalriwalau@gmail.com>
  • Loading branch information
gdnmhr and ShubhamPalriwala committed Apr 17, 2024
1 parent 74b4be9 commit 4fc8ee8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/lib/account/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions packages/lib/account/utils.ts
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit 4fc8ee8

Please sign in to comment.