2024-06-30 18:55:39 -04:00
|
|
|
import { API_URL } from '../Config'
|
|
|
|
import { Fetch, HEADERS } from './TokenManager'
|
|
|
|
|
|
|
|
const createChore = userID => {
|
|
|
|
return Fetch(`${API_URL}/chores/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify({
|
|
|
|
createdBy: Number(userID),
|
|
|
|
}),
|
|
|
|
}).then(response => response.json())
|
|
|
|
}
|
|
|
|
|
|
|
|
const signUp = (username, password, displayName, email) => {
|
|
|
|
return fetch(`${API_URL}/auth/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ username, password, displayName, email }),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const login = (username, password) => {
|
|
|
|
return fetch(`${API_URL}/auth/login`, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({ username, password }),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetAllUsers = () => {
|
|
|
|
return fetch(`${API_URL}/users/`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetChores = () => {
|
|
|
|
return Fetch(`${API_URL}/chores/`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetChoreByID = id => {
|
|
|
|
return Fetch(`${API_URL}/chores/${id}`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
2024-07-06 02:33:06 -04:00
|
|
|
const GetChoreDetailById = id => {
|
|
|
|
return Fetch(`${API_URL}/chores/${id}/details`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
2024-07-07 00:25:11 -04:00
|
|
|
const MarkChoreComplete = (id, note, completedDate) => {
|
|
|
|
const body = {
|
|
|
|
note,
|
|
|
|
}
|
|
|
|
let completedDateFormated = ''
|
|
|
|
if (completedDate) {
|
|
|
|
completedDateFormated = `?completedDate=${new Date(
|
|
|
|
completedDate,
|
|
|
|
).toISOString()}`
|
|
|
|
}
|
|
|
|
return Fetch(`${API_URL}/chores/${id}/do${completedDateFormated}`, {
|
2024-07-06 02:33:06 -04:00
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
2024-07-07 00:25:11 -04:00
|
|
|
body: JSON.stringify(body),
|
2024-07-06 02:33:06 -04:00
|
|
|
})
|
|
|
|
}
|
2024-07-15 21:58:23 -04:00
|
|
|
|
|
|
|
const SkipChore = id => {
|
|
|
|
return Fetch(`${API_URL}/chores/${id}/skip`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
body: JSON.stringify({}),
|
|
|
|
})
|
|
|
|
}
|
2024-06-30 18:55:39 -04:00
|
|
|
const CreateChore = chore => {
|
|
|
|
return Fetch(`${API_URL}/chores/`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify(chore),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const DeleteChore = id => {
|
|
|
|
return Fetch(`${API_URL}/chores/${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const SaveChore = chore => {
|
|
|
|
console.log('chore', chore)
|
|
|
|
return Fetch(`${API_URL}/chores/`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify(chore),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const GetChoreHistory = choreId => {
|
|
|
|
return Fetch(`${API_URL}/chores/${choreId}/history`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetAllCircleMembers = () => {
|
|
|
|
return Fetch(`${API_URL}/circles/members`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetUserProfile = () => {
|
|
|
|
return Fetch(`${API_URL}/users/profile`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetUserCircle = () => {
|
|
|
|
return Fetch(`${API_URL}/circles/`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const JoinCircle = inviteCode => {
|
|
|
|
return Fetch(`${API_URL}/circles/join?invite_code=${inviteCode}`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetCircleMemberRequests = () => {
|
|
|
|
return Fetch(`${API_URL}/circles/members/requests`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const AcceptCircleMemberRequest = id => {
|
|
|
|
return Fetch(`${API_URL}/circles/members/requests/accept?requestId=${id}`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const LeaveCircle = id => {
|
|
|
|
return Fetch(`${API_URL}/circles/leave?circle_id=${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const DeleteCircleMember = (circleID, memberID) => {
|
|
|
|
return Fetch(
|
|
|
|
`${API_URL}/circles/${circleID}/members/delete?member_id=${memberID}`,
|
|
|
|
{
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: HEADERS(),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const UpdateUserDetails = userDetails => {
|
|
|
|
return Fetch(`${API_URL}/users`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify(userDetails),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetSubscriptionSession = () => {
|
|
|
|
return Fetch(API_URL + `/payments/create-subscription`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const CancelSubscription = () => {
|
|
|
|
return Fetch(API_URL + `/payments/cancel-subscription`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetThings = () => {
|
|
|
|
return Fetch(`${API_URL}/things`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const CreateThing = thing => {
|
|
|
|
return Fetch(`${API_URL}/things`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify(thing),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const SaveThing = thing => {
|
|
|
|
return Fetch(`${API_URL}/things`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify(thing),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const UpdateThingState = thing => {
|
|
|
|
return Fetch(`${API_URL}/things/${thing.id}/state?value=${thing.state}`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const DeleteThing = id => {
|
|
|
|
return Fetch(`${API_URL}/things/${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-01 22:12:19 -04:00
|
|
|
const GetThingHistory = (id, offset) => {
|
|
|
|
return Fetch(`${API_URL}/things/${id}/history?offset=${offset}`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-30 18:55:39 -04:00
|
|
|
const CreateLongLiveToken = name => {
|
|
|
|
return Fetch(`${API_URL}/users/tokens`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: HEADERS(),
|
|
|
|
body: JSON.stringify({ name }),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const DeleteLongLiveToken = id => {
|
|
|
|
return Fetch(`${API_URL}/users/tokens/${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const GetLongLiveTokens = () => {
|
|
|
|
return Fetch(`${API_URL}/users/tokens`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: HEADERS(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
export {
|
|
|
|
AcceptCircleMemberRequest,
|
|
|
|
CancelSubscription,
|
|
|
|
createChore,
|
|
|
|
CreateChore,
|
|
|
|
CreateLongLiveToken,
|
|
|
|
CreateThing,
|
|
|
|
DeleteChore,
|
|
|
|
DeleteCircleMember,
|
|
|
|
DeleteLongLiveToken,
|
|
|
|
DeleteThing,
|
|
|
|
GetAllCircleMembers,
|
|
|
|
GetAllUsers,
|
|
|
|
GetChoreByID,
|
2024-07-06 02:33:06 -04:00
|
|
|
GetChoreDetailById,
|
2024-06-30 18:55:39 -04:00
|
|
|
GetChoreHistory,
|
|
|
|
GetChores,
|
|
|
|
GetCircleMemberRequests,
|
|
|
|
GetLongLiveTokens,
|
|
|
|
GetSubscriptionSession,
|
2024-07-01 22:12:19 -04:00
|
|
|
GetThingHistory,
|
2024-06-30 18:55:39 -04:00
|
|
|
GetThings,
|
|
|
|
GetUserCircle,
|
|
|
|
GetUserProfile,
|
|
|
|
JoinCircle,
|
|
|
|
LeaveCircle,
|
|
|
|
login,
|
2024-07-06 02:33:06 -04:00
|
|
|
MarkChoreComplete,
|
2024-06-30 18:55:39 -04:00
|
|
|
SaveChore,
|
|
|
|
SaveThing,
|
|
|
|
signUp,
|
2024-07-15 21:58:23 -04:00
|
|
|
SkipChore,
|
2024-06-30 18:55:39 -04:00
|
|
|
UpdateThingState,
|
|
|
|
UpdateUserDetails,
|
|
|
|
}
|