-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-utils.js
87 lines (71 loc) · 2.61 KB
/
fetch-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const SUPABASE_URL = 'https://jmrcnnpbxtcmnkrrltge.supabase.co';
const SUPABASE_KEY =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImptcmNubnBieHRjbW5rcnJsdGdlIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NjYwMjY2NjksImV4cCI6MTk4MTYwMjY2OX0.ASGAnJldIXzH5t23Vvah5XvxOI9SHEFPxgXkDvZEck8';
const client = supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
/* Auth related functions */
export function getUser() {
return client.auth.user();
}
export async function signUpUser(email, password) {
return await client.auth.signUp({
email,
password,
});
}
export async function signInUser(email, password) {
return await client.auth.signIn({
email,
password,
});
}
export async function signOutUser() {
return await client.auth.signOut();
}
/* Data functions */
export async function getCoffeeShops() {
return await client.from('coffee_shops').select('*');
}
export async function getActivities() {
return await client.from('activities').select('*');
}
export async function getEateries() {
return await client.from('eateries').select('*');
}
export async function saveAdventure(adventure, user_id) {
return await client.from('saved_adventures').insert(adventure, user_id).single();
}
export async function updateProfile(profile) {
return await client.from('profiles').upsert(profile).maybeSingle().eq('id', profile.id);
}
export async function getProfile(id) {
return await client.from('profiles').select('*').eq('id', id).single();
}
export async function getSavedAdventures(user_id) {
const adventures = await client.from('saved_adventures').select('*').eq('user_id', user_id);
let adventureList = [];
for (let adventure of adventures.data) {
let adventureObject = {
id: adventure.id,
coffee: '',
activity: '',
eatery: '',
};
const coffee = await client
.from('coffee_shops')
.select('name')
.eq('id', adventure.coffee_id);
adventureObject.coffee = coffee.data[0].name;
const activity = await client
.from('activities')
.select('name')
.eq('id', adventure.activity_id);
adventureObject.activity = activity.data[0].name;
const eatery = await client.from('eateries').select('name').eq('id', adventure.eatery_id);
adventureObject.eatery = eatery.data[0].name;
adventureList.push(adventureObject);
}
return adventureList;
}
export async function deleteSavedAdventures(id) {
return await client.from('saved_adventures').delete().eq('id', id).single();
}