Skip to content

Commit

Permalink
Refactor username uniqueness check into inline function and remove ap…
Browse files Browse the repository at this point in the history
…i.check-username route
  • Loading branch information
jamalsoueidan committed Jul 12, 2024
1 parent 87cb279 commit c9486c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
20 changes: 19 additions & 1 deletion app/routes/account.business._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,29 @@ import {z} from 'zod';
import {MultiTags} from '~/components/form/MultiTags';
import {RadioGroup} from '~/components/form/RadioGroup';
import {CUSTOMER_DETAILS_QUERY} from '~/graphql/customer-account/CustomerDetailsQuery';
import {USER_METAOBJECT_QUERY} from '~/graphql/fragments/UserMetaobject';
import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi';
import {updateCustomerTag} from '~/lib/updateTag';
import {customerCreateBody} from '~/lib/zod/bookingShopifyApi';
import {BottomSection, WrapSection} from './account.business';
import {isUsernameUnique} from './api.check-username';

const isUsernameUnique =
({context}: ActionFunctionArgs) =>
async (username: string) => {
if (username.length <= 3) return true;

const {metaobject: user} = await context.storefront.query(
USER_METAOBJECT_QUERY,
{
variables: {
username,
},
cache: context.storefront.CacheShort(),
},
);

return user !== null;
};

function createSchema(options?: {
isUsernameUnique: (username: string) => Promise<boolean>;
Expand Down
34 changes: 0 additions & 34 deletions app/routes/api.check-username.ts

This file was deleted.

0 comments on commit c9486c3

Please sign in to comment.