|
1 | 1 | import { createClient } from "@/lib/utils/supabase/client";
|
2 | 2 |
|
3 | 3 | export async function addAssignment({ match, team, alliance, assignee }) {
|
4 |
| - const supabase = createClient(); |
| 4 | + const supabase = createClient(); |
| 5 | + console.log("sadfsafdfsd"); |
| 6 | + const { data: profileData, error: profileError } = await supabase |
| 7 | + .from("profiles") |
| 8 | + .select("id") |
| 9 | + .eq("email", assignee) |
| 10 | + .single(); |
5 | 11 |
|
6 |
| - const { data: profileData, error: profileError } = await supabase |
7 |
| - .from("profiles") |
8 |
| - .select("id") |
9 |
| - .eq("email", assignee) |
10 |
| - .single(); |
| 12 | + const { data, error } = await supabase |
| 13 | + .from("assignments") |
| 14 | + .upsert([ |
| 15 | + { |
| 16 | + match: match, |
| 17 | + team: team, |
| 18 | + alliance: alliance, |
| 19 | + assignee: profileData?.id, |
| 20 | + event_log: { |
| 21 | + auto: { log: [], checkboxes: null }, |
| 22 | + teleop: { log: [], checkboxes: null }, |
| 23 | + endgame: { log: [], checkboxes: null }, |
| 24 | + }, |
| 25 | + }, |
| 26 | + ]) |
| 27 | + .select(); |
11 | 28 |
|
12 |
| - const { data, error } = await supabase |
13 |
| - .from("assignments") |
14 |
| - .insert([ |
15 |
| - { |
16 |
| - match: match, |
17 |
| - team: team, |
18 |
| - alliance: alliance, |
19 |
| - assignee: profileData?.id, |
20 |
| - event_log: { |
21 |
| - auto: { log: [], checkboxes: null }, |
22 |
| - teleop: { log: [], checkboxes: null }, |
23 |
| - endgame: { log: [], checkboxes: null }, |
24 |
| - }, |
25 |
| - }, |
26 |
| - ]) |
27 |
| - .select(); |
28 |
| - |
29 |
| - if (error) { |
30 |
| - console.error("Error: ", error); |
31 |
| - } else { |
32 |
| - console.log("Data: ", data); |
33 |
| - } |
| 29 | + if (error) { |
| 30 | + console.error("Error: ", error); |
| 31 | + } else { |
| 32 | + console.log("Data: ", data); |
| 33 | + } |
34 | 34 | }
|
35 | 35 |
|
36 | 36 | export async function addEvents({ event }) {
|
37 |
| - const supabase = createClient(); |
| 37 | + const supabase = createClient(); |
38 | 38 |
|
39 |
| - const { data, error } = await supabase |
40 |
| - .from("events") |
41 |
| - .insert([ |
42 |
| - { |
43 |
| - key: event.key, |
44 |
| - name: event.name, |
45 |
| - }, |
46 |
| - ]) |
47 |
| - .select(); |
| 39 | + const { data, error } = await supabase |
| 40 | + .from("events") |
| 41 | + .insert([ |
| 42 | + { |
| 43 | + key: event.key, |
| 44 | + name: event.name, |
| 45 | + }, |
| 46 | + ]) |
| 47 | + .select(); |
48 | 48 |
|
49 |
| - if (error) { |
50 |
| - console.error("Error: ", error); |
51 |
| - } else { |
52 |
| - console.log("Data: ", data); |
53 |
| - } |
| 49 | + if (error) { |
| 50 | + console.error("Error: ", error); |
| 51 | + } else { |
| 52 | + console.log("Data: ", data); |
| 53 | + } |
54 | 54 | }
|
55 | 55 |
|
56 | 56 | export async function addMatches({ match }) {
|
57 |
| - const supabase = createClient(); |
| 57 | + const supabase = createClient(); |
58 | 58 |
|
59 |
| - const { data, error } = await supabase |
60 |
| - .from("matches") |
61 |
| - .insert([ |
62 |
| - { |
63 |
| - key: match.match_key, |
64 |
| - event: match.event, |
65 |
| - }, |
66 |
| - ]) |
67 |
| - .select(); |
| 59 | + const { data, error } = await supabase |
| 60 | + .from("matches") |
| 61 | + .insert([ |
| 62 | + { |
| 63 | + key: match.match_key, |
| 64 | + event: match.event, |
| 65 | + }, |
| 66 | + ]) |
| 67 | + .select(); |
68 | 68 |
|
69 |
| - if (error) { |
70 |
| - console.error("Error: ", error); |
71 |
| - } else { |
72 |
| - console.log("Data: ", data); |
73 |
| - } |
| 69 | + if (error) { |
| 70 | + console.error("Error: ", error); |
| 71 | + } else { |
| 72 | + console.log("Data: ", data); |
| 73 | + } |
74 | 74 | }
|
75 | 75 |
|
76 | 76 | export async function getEmails(
|
77 |
| - setMembers: (members: { [key: string]: string[] }) => void, |
| 77 | + setMembers: (members: { [key: string]: string[] }) => void, |
78 | 78 | ) {
|
79 |
| - const supabase = createClient(); |
| 79 | + const supabase = createClient(); |
80 | 80 |
|
81 |
| - // const { data, error } = await supabase.from("users").select("email"); |
82 |
| - const { data, error } = await supabase.from("profiles").select("email"); |
| 81 | + // const { data, error } = await supabase.from("users").select("email"); |
| 82 | + const { data, error } = await supabase.from("profiles").select("email"); |
83 | 83 |
|
84 |
| - if (error) { |
85 |
| - console.error("Error: ", error); |
86 |
| - } else { |
87 |
| - console.log("Data: ", data); |
88 |
| - } |
| 84 | + if (error) { |
| 85 | + console.error("Error: ", error); |
| 86 | + } else { |
| 87 | + console.log("Data: ", data); |
| 88 | + } |
89 | 89 |
|
90 |
| - const extractedEmails = data.map((obj) => obj.email); |
| 90 | + const extractedEmails = data.map((obj) => obj.email); |
91 | 91 |
|
92 |
| - // Update the state to create an object where each email is a key with an empty array value |
93 |
| - setMembers((previousState) => ({ |
94 |
| - ...previousState, // This keeps existing state entries intact |
95 |
| - ...extractedEmails.reduce((acc, email) => { |
96 |
| - acc[email] = []; |
97 |
| - return acc; |
98 |
| - }, {}), |
99 |
| - })); |
| 92 | + // Update the state to create an object where each email is a key with an empty array value |
| 93 | + setMembers((previousState) => ({ |
| 94 | + ...previousState, // This keeps existing state entries intact |
| 95 | + ...extractedEmails.reduce((acc, email) => { |
| 96 | + acc[email] = []; |
| 97 | + return acc; |
| 98 | + }, {}), |
| 99 | + })); |
100 | 100 | }
|
0 commit comments