-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use user id param in api call routes (#19)
* Use user id param in api call routes * Add missing hook dependency
- Loading branch information
Showing
9 changed files
with
48 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
import { CalendarEvent } from '@context'; | ||
import { CalendarEvent, type LocalUser } from '@context'; | ||
|
||
import { composeAuthorizationHeader, destroy, get, patch, post } from './http'; | ||
|
||
export const createCalendarEvent = ( | ||
date: Date, | ||
habitId: number, | ||
accessToken: string | ||
user: LocalUser | ||
) => { | ||
return post<CalendarEvent>( | ||
'/calendar-events', | ||
`/users/${user.id}/calendar-events`, | ||
{ | ||
date: date.toISOString(), | ||
habit: habitId, | ||
}, | ||
composeAuthorizationHeader(accessToken) | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const getCalendarEvents = (accessToken: string) => { | ||
export const getCalendarEvents = (user: LocalUser) => { | ||
return get<CalendarEvent[]>( | ||
'/calendar-events', | ||
composeAuthorizationHeader(accessToken) | ||
`/users/${user.id}/calendar-events`, | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const updateCalendarEvent = ( | ||
id: number, | ||
calendarEvent: Omit<CalendarEvent, 'id'>, | ||
accessToken: string | ||
user: LocalUser | ||
) => { | ||
return patch<CalendarEvent>( | ||
`/calendar-events/${id}`, | ||
`/users/${user.id}/calendar-events/${id}`, | ||
calendarEvent, | ||
composeAuthorizationHeader(accessToken) | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const destroyCalendarEvent = (id: number, accessToken: string) => { | ||
export const destroyCalendarEvent = (id: number, user: LocalUser) => { | ||
return destroy<CalendarEvent>( | ||
`/calendar-events/${id}`, | ||
composeAuthorizationHeader(accessToken) | ||
`/users/${user.id}/calendar-events/${id}`, | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,46 @@ | ||
import { Habit } from '@context'; | ||
import { Habit, type LocalUser } from '@context'; | ||
|
||
import { composeAuthorizationHeader, destroy, get, patch, post } from './http'; | ||
|
||
export const createHabit = ( | ||
name: string, | ||
description: string, | ||
trait: 'good' | 'bad', | ||
accessToken: string | ||
user: LocalUser | ||
) => { | ||
return post<Habit>( | ||
'/habits', | ||
`/users/${user.id}/habits`, | ||
{ | ||
name, | ||
description, | ||
trait, | ||
}, | ||
composeAuthorizationHeader(accessToken) | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const getHabits = (accessToken: string) => { | ||
return get<Habit[]>('/habits', composeAuthorizationHeader(accessToken)); | ||
export const getHabits = (user: LocalUser) => { | ||
return get<Habit[]>( | ||
`/users/${user.id}/habits`, | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const updateHabit = ( | ||
id: number, | ||
habit: Omit<Habit, 'id'>, | ||
accessToken: string | ||
user: LocalUser | ||
) => { | ||
return patch<Habit>( | ||
`/habits/${id}`, | ||
`/users/${user.id}/habits/${id}`, | ||
habit, | ||
composeAuthorizationHeader(accessToken) | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; | ||
|
||
export const destroyHabit = (id: number, accessToken: string) => { | ||
export const destroyHabit = (id: number, user: LocalUser) => { | ||
return destroy<Habit>( | ||
`/habits/${id}`, | ||
composeAuthorizationHeader(accessToken) | ||
`/users/${user.id}/habits/${id}`, | ||
composeAuthorizationHeader(user.token) | ||
); | ||
}; |