Skip to content

Commit

Permalink
Merge pull request #106 from compsci-adl/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 authored Feb 23, 2024
2 parents 1399514 + f68f690 commit ed79abc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const client = createClient({
authToken: env.DATABASE_AUTH_TOKEN,
});

export const db = drizzle(client, { schema });
export const db = drizzle(client, { schema, logger: process.env.NODE_ENV === 'development' });
5 changes: 3 additions & 2 deletions src/server/check-user-exists.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { db } from '@/db';
import { memberTable } from '@/db/schema';
import { eq } from 'drizzle-orm';
import { cache } from 'react';

export const checkUserExists = async (clerkUserId: string) => {
export const checkUserExists = cache(async (clerkUserId: string) => {
const existingUser = await db
.select({ count: memberTable.id })
.from(memberTable)
.where(eq(memberTable.clerkId, clerkUserId));
return existingUser.length > 0;
};
});
5 changes: 3 additions & 2 deletions src/server/verify-membership-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { memberTable } from '@/db/schema';
import { redisClient } from '@/lib/redis';
import { squareClient } from '@/lib/square';
import { eq } from 'drizzle-orm';
import { cache } from 'react';
import { updateMemberExpiryDate } from './update-member-expiry-date';

export const verifyMembershipPayment = async (clerkId: string) => {
export const verifyMembershipPayment = cache(async (clerkId: string) => {
// Get user's membership expiry date from the database
const [member] = await db
.select({
Expand Down Expand Up @@ -47,5 +48,5 @@ export const verifyMembershipPayment = async (clerkId: string) => {
} catch {
return { paid: false as const };
}
};
});
export type MembershipPayment = Awaited<ReturnType<typeof verifyMembershipPayment>>;

0 comments on commit ed79abc

Please sign in to comment.