diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 54b1fb97e..ee639e0f3 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -42,7 +42,7 @@ model Waitlist {
}
model Users {
- uid String @id()
+ uid String @id @default(cuid())
email String @unique
username String?
firstName String?
@@ -68,6 +68,45 @@ model Users {
streak Streaks?
roadmaps UserRoadmaps[]
+
+ workspaceOwner Workspaces[] @relation(name: "WorkspaceOwner")
+
+ workspaceUsers Workspaces[] @relation(name: "WorkspaceUsers")
+
+ WorkspaceUsers WorkspaceUsers[]
+}
+
+model Workspaces {
+ uid String @id @default(cuid())
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ name String
+ description String?
+ ownerUid String
+ owner Users @relation(fields: [ownerUid], references: [uid], onDelete: Cascade, onUpdate: Cascade, name: "WorkspaceOwner")
+
+ users WorkspaceUsers[]
+
+ @@unique([name, ownerUid])
+ Users Users[] @relation(name: "WorkspaceUsers")
+}
+
+model WorkspaceUsers {
+ uid String @id @default(cuid())
+ workspaceUid String
+ workspace Workspaces @relation(fields: [workspaceUid], references: [uid], onDelete: Cascade)
+ userUid String
+ user Users @relation(fields: [userUid], references: [uid], onDelete: Cascade)
+ role UserRole @default(MEMBER)
+
+ @@unique([workspaceUid, userUid])
+}
+
+enum UserRole {
+ ADMIN
+ MEMBER
+ VIEWER
}
model Subscriptions {
diff --git a/src/app/(marketing)/page.tsx b/src/app/(marketing)/page.tsx
index 8b6c3b0cd..338bbe2bd 100644
--- a/src/app/(marketing)/page.tsx
+++ b/src/app/(marketing)/page.tsx
@@ -6,11 +6,22 @@ import HomepageHero from '@/components/marketing/homepage/hero/hero';
import HomepageHeroImages from '@/components/marketing/homepage/hero/hero-images';
import HomepageLargeText from '@/components/marketing/large-text';
+import { supabase } from '@/lib/supabase';
+
import posthog from 'posthog-js';
export default async function AuthedPage() {
posthog.capture('page_view', { page_name: 'Landing Page' });
+ // const { data, error } = await supabase.functions.invoke(
+ // 'slack_send-daily-question'
+ // );
+
+ // console.log({
+ // data,
+ // error
+ // });
+
return (
diff --git a/src/components/global/logo.tsx b/src/components/global/logo.tsx
index 9820652b9..a08ae8b82 100644
--- a/src/components/global/logo.tsx
+++ b/src/components/global/logo.tsx
@@ -20,9 +20,9 @@ export default function Logo() {
diff --git a/supabase/functions/slack_send-daily-question/index.ts b/supabase/functions/slack_send-daily-question/index.ts
new file mode 100644
index 000000000..65d98274f
--- /dev/null
+++ b/supabase/functions/slack_send-daily-question/index.ts
@@ -0,0 +1,85 @@
+import { createClient, type SupabaseClient } from '@supabase/supabase-js';
+import { corsHeaders } from '../_shared/cors.ts';
+
+// Follow this setup guide to integrate the Deno language server with your editor:
+// https://deno.land/manual/getting_started/setup_your_environment
+// This enables autocomplete, go to definition, etc.
+
+console.log('Hello from Functions!');
+
+Deno.serve(async (req) => {
+ if (req.method === 'OPTIONS') {
+ return new Response('ok', { headers: corsHeaders });
+ }
+
+ // get today's date
+ const today = new Date();
+
+ // get the day of the week
+ const day = today.getDay();
+
+ // if today is Sunday or Saturday, return
+ if (day === 0 || day === 6) {
+ return new Response("It's the weekend! No daily question today.");
+ }
+
+ // get the current time
+ const time = today.getHours();
+
+ // if it's before 9am, return
+
+ try {
+ const supabase = createClient(
+ Deno.env.get('SUPABASE_URL') ?? '',
+ Deno.env.get('SUPABASE_ANON_KEY') ?? '',
+ {
+ global: {
+ headers: { Authorization: req.headers.get('Authorization') ?? '' }
+ }
+ }
+ );
+
+ const { data, error } = await supabase
+ .from('Questions')
+ .select('uid, correctAnswer')
+ .eq(questionDate, today.toISOString().split('T')[0])
+ .single();
+
+ if (error) {
+ throw error;
+ }
+
+ if (!data) {
+ throw new Error('No question found for today');
+ }
+
+ return new Response(JSON.stringify(data), {
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' },
+ status: 200
+ });
+ } catch (error) {
+ console.error(error);
+ }
+
+ // const { name } = await req.json()
+ // const data = {
+ // message: `Hello ${name}!`,
+ // }
+
+ // return new Response(
+ // JSON.stringify(data),
+ // { headers: { "Content-Type": "application/json" } },
+ // )
+});
+
+/* To invoke locally:
+
+ 1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start)
+ 2. Make an HTTP request:
+
+ curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/slack_send-daily-question' \
+ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
+ --header 'Content-Type: application/json' \
+ --data '{"name":"Functions"}'
+
+*/
diff --git a/supabase/functions/slack_send-daily-question/readme.md b/supabase/functions/slack_send-daily-question/readme.md
new file mode 100644
index 000000000..bf2b958a6
--- /dev/null
+++ b/supabase/functions/slack_send-daily-question/readme.md
@@ -0,0 +1,4 @@
+To update this edge function:
+
+- ensure docker is running on your desktop
+- `supabase functions deploy slack_send-daily-question