added push notifications
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
const BASE_URL = process.env.EXPO_PUBLIC_API_URL; // TODO change this
|
||||
|
||||
|
||||
export type NotificationType = 'PUSH_NOTIFICATION' | 'NO_NOTIFICATION';
|
||||
function authHeader(token?: string) {
|
||||
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||
}
|
||||
@@ -25,7 +25,13 @@ async function request<T>(
|
||||
headers: { "Content-Type": "application/json", ...authHeader(token) },
|
||||
...(body ? { body: JSON.stringify(body) } : {}),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text().catch(() => `HTTP ${res.status}`));
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text().catch(() => `HTTP ${res.status}`);
|
||||
console.log('Failed URL:', res.url);
|
||||
console.log('Status:', res.status);
|
||||
console.log('Response:', errorText);
|
||||
throw new Error(errorText);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
@@ -65,6 +71,7 @@ export type UserDTO = {
|
||||
id: string;
|
||||
email: string;
|
||||
subjectSet: Subject[];
|
||||
notificationType: NotificationType;
|
||||
|
||||
};
|
||||
|
||||
@@ -115,6 +122,12 @@ export const authApi = {
|
||||
};
|
||||
|
||||
|
||||
export const userApi = {
|
||||
updateNotificationType: (
|
||||
type: 'PUSH_NOTIFICATION' | 'NO_NOTIFICATION',
|
||||
token: string
|
||||
) => post<void>('/users/me/notification-type', { notificationType: type }, token),
|
||||
};
|
||||
|
||||
export const subjectsApi = {
|
||||
getAll: (token?: string) => get<Subject[]>("/subjects", token),
|
||||
@@ -135,6 +148,8 @@ export const subscriptionsApi = {
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const entriesApi = {
|
||||
getEntries: (params: { subjectId?: string; groupName?: string; page?: number }) =>
|
||||
get<SpringPage<Entry>>("/entries", undefined, params),
|
||||
|
||||
Reference in New Issue
Block a user