Skip to content

Commit

Permalink
refactor: update nullable stuff (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf authored Dec 16, 2023
1 parent b03af35 commit f2f0a50
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions components/layout/app-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export async function AppLayout({ children }: PropsWithChildren) {
appHeader = (
<AppHeader
user={{
avatarURL: account.avatar_url || '',
credits: account.ai_credit || 0,
username: account.display_name || '',
avatarURL: account.avatar_url ?? '',
credits: account.ai_credit,
username: account.display_name ?? '',
}}
variant="authenticated"
/>
Expand Down
4 changes: 2 additions & 2 deletions lib/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const fetchAccountAICredits = async () => {
throw new DatabaseError(accountQuery.error);
}

return accountQuery.data.ai_credit || 0;
return accountQuery.data.ai_credit;
};

export const validateAccountAICredits = async () => {
Expand Down Expand Up @@ -82,5 +82,5 @@ export const updateAccountAICredits = async (amount: number) => {
throw new DatabaseError(accountQuery.error);
}

return accountQuery.data.ai_credit || 0;
return accountQuery.data.ai_credit;
};
4 changes: 2 additions & 2 deletions lib/services/spotify/save-user-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type UserMetadata = {
};

const spotifyUserInfoResponseSchema = z.object({
avatar_url: z.string().min(1),
full_name: z.string().min(1),
avatar_url: z.string().default(''),
full_name: z.string().default(''),
provider_id: z.string().min(1),
provider_token: z.string().min(1),
});
Expand Down
3 changes: 1 addition & 2 deletions lib/services/stripe/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ export async function fulfillOrder(session: Stripe.Checkout.Session) {
const updateAccountQuery = await supabase
.from('account')
.update({
ai_credit:
(currentAccountCreditsQuery.data.ai_credit ?? 0) + purchasedCredits,
ai_credit: currentAccountCreditsQuery.data.ai_credit + purchasedCredits,
})
.eq('id', validatedSession.data.metadata.accountId);

Expand Down
6 changes: 3 additions & 3 deletions types/supabase/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Database {
Tables: {
account: {
Row: {
ai_credit: number | null;
ai_credit: number;
avatar_url: string | null;
created_at: string;
display_name: string | null;
Expand All @@ -22,7 +22,7 @@ export interface Database {
user_id: string;
};
Insert: {
ai_credit?: number | null;
ai_credit?: number;
avatar_url?: string | null;
created_at?: string;
display_name?: string | null;
Expand All @@ -33,7 +33,7 @@ export interface Database {
user_id: string;
};
Update: {
ai_credit?: number | null;
ai_credit?: number;
avatar_url?: string | null;
created_at?: string;
display_name?: string | null;
Expand Down

0 comments on commit f2f0a50

Please sign in to comment.