diff --git a/orval.config.ts b/orval.config.ts index c8a3dbd..59ba8c2 100644 --- a/orval.config.ts +++ b/orval.config.ts @@ -1,6 +1,28 @@ import { defineConfig } from 'orval' export default defineConfig({ + events: { + input: { + target: 'https://api.innohassle.ru/events/staging-v0/openapi.json', + }, + output: { + mode: 'single', + target: './src/shared/innohassle-api/events/__generated__.ts', + client: 'axios', + override: { + mutator: { + path: './src/shared/innohassle-api/events/axios.ts', + name: 'eventsQueryPromise', + }, + }, + }, + hooks: { + afterAllFilesWrite: { + command: 'pnpm run lint:fix:generated', + injectGeneratedDirsAndFiles: false, + }, + }, + }, search: { input: { target: 'https://api.innohassle.ru/search/staging-v0/openapi.json', diff --git a/src/shared/config/innohassle.ts b/src/shared/config/innohassle.ts index 46868da..49169a2 100644 --- a/src/shared/config/innohassle.ts +++ b/src/shared/config/innohassle.ts @@ -1,3 +1,4 @@ export const INNOHASSLE_ACCOUNTS_URL = 'https://api.innohassle.ru/accounts/v0' export const INNOHASSLE_ACCOUNTS_TOKEN_URL = `${INNOHASSLE_ACCOUNTS_URL}/tokens/generate-my-token` export const INNOHASSLE_SEARCH_URL = 'https://api.innohassle.ru/search/staging-v0' +export const INNOHASSLE_EVENTS_URL = 'https://api.innohassle.ru/events/v0' diff --git a/src/shared/innohassle-api/events/__generated__.ts b/src/shared/innohassle-api/events/__generated__.ts new file mode 100644 index 0000000..3eaec9c --- /dev/null +++ b/src/shared/innohassle-api/events/__generated__.ts @@ -0,0 +1,961 @@ +/** + * Generated by orval v6.31.0 🍺 + * Do not edit manually. + * InNoHassle Events API + * +### About this project + +This is the API for Events project in InNoHassle ecosystem developed by one-zero-eight community. + +Using this API you can browse, view, create and edit schedules at Innopolis University. + +Backend is developed using FastAPI framework on Python. + +Note: API is unstable. Endpoints and models may change in the future. + +Useful links: +- [Backend source code](https://github.com/one-zero-eight/InNoHassle-Events) +- [Frontend source code](https://github.com/one-zero-eight/InNoHassle-Website) +- [Website](https://innohassle.ru/schedule) + + * OpenAPI spec version: 0.1.0 + */ +import { eventsQueryPromise } from './axios' + +export interface IcsGetEventGroupIcsByAliasParams { + user_id: number + export_type: string +} + +export interface IcsGetMoodleCurrentUserScheduleParams { + access_key: string +} + +export interface IcsGetSportUserScheduleParams { + access_key: string +} + +export interface IcsGetMusicRoomUserScheduleParams { + access_key: string +} + +export interface IcsGetUserScheduleParams { + access_key: string +} + +export interface EventGroupsDeleteEventGroupByAliasParams { + alias: string +} + +export interface EventGroupsFindEventGroupByAliasParams { + alias: string +} + +export interface EventGroupsFindEventGroupByPathParams { + path: string +} + +export interface UsersSetUserMoodleDataParams { + moodle_userid: number + moodle_calendar_authtoken: string +} + +export interface UsersDeleteUserScheduleKeyParams { + access_key: string + resource_path: string +} + +export interface UsersGenerateUserScheduleKeyParams { + resource_path: string +} + +export interface UsersHideTargetParams { + hide?: boolean +} + +export interface UsersHideFavoriteParams { + group_id: number + hide?: boolean +} + +export interface UsersDeleteFavoriteParams { + group_id: number +} + +export interface UsersAddFavoriteParams { + group_id: number +} + +export interface Workshop { + checkin?: string + instructor?: string + limit?: string + location?: string + subject: string + when: string +} + +/** + * Represents a user schedule key. + */ +export interface ViewUserScheduleKey { + access_key: string + resource_path: string + user_id: number +} + +export interface _GetScheduleAccessKeyResponse { + access_key: ViewUserScheduleKey + new: boolean +} + +export type ViewUserName = string | null + +export type ViewUserMoodleUserid = number | null + +export type ViewUserMoodleCalendarAuthtoken = string | null + +export interface ViewUserLinkedCalendars { [key: string]: LinkedCalendarView } + +export type ViewUserInnohassleId = string | null + +/** + * Represents a user instance from the database excluding sensitive information. + */ +export interface ViewUser { + email: string + favorite_event_groups?: number[] + hidden_event_groups?: number[] + id: number + innohassle_id?: ViewUserInnohassleId + linked_calendars?: ViewUserLinkedCalendars + moodle_calendar_authtoken?: ViewUserMoodleCalendarAuthtoken + moodle_hidden: boolean + moodle_userid?: ViewUserMoodleUserid + music_room_hidden: boolean + name?: ViewUserName + sports_hidden: boolean +} + +export type ViewTagType = string | null + +export interface ViewTagSatelliteAnyOf { [key: string]: unknown } + +export type ViewTagSatellite = ViewTagSatelliteAnyOf | null + +export type ViewTagName = string | null + +export interface ViewTag { + alias: string + id: number + name?: ViewTagName + satellite?: ViewTagSatellite + type?: ViewTagType +} + +export type ViewEventGroupPath = string | null + +export type ViewEventGroupName = string | null + +export type ViewEventGroupDescription = string | null + +/** + * Represents a group instance from the database excluding sensitive information. + */ +export interface ViewEventGroup { + alias: string + created_at: string + description?: ViewEventGroupDescription + id: number + name?: ViewEventGroupName + path?: ViewEventGroupPath + tags?: ViewTag[] + updated_at: string +} + +export type ValidationErrorLocItem = string | number + +export interface ValidationError { + loc: ValidationErrorLocItem[] + msg: string + type: string +} + +export interface UserPredefinedGroupsResponse { + event_groups: number[] +} + +export type UpdateEventGroupPath = string | null + +export type UpdateEventGroupName = string | null + +export type UpdateEventGroupDescription = string | null + +export type UpdateEventGroupAlias = string | null + +/** + * Represents a group instance to be updated. + */ +export interface UpdateEventGroup { + alias?: UpdateEventGroupAlias + description?: UpdateEventGroupDescription + name?: UpdateEventGroupName + path?: UpdateEventGroupPath +} + +export interface ListTagsResponse { + tags: ViewTag[] +} + +/** + * Represents a list of event groups. + */ +export interface ListEventGroupsResponseOutput { + event_groups: ViewEventGroup[] +} + +/** + * Represents a list of event groups. + */ +export interface ListEventGroupsResponseInput { + event_groups: ViewEventGroup[] +} + +export type LinkedCalendarViewName = string | null + +export type LinkedCalendarViewDescription = string | null + +export type LinkedCalendarViewColor = string | null + +/** + * Represents a linked calendar instance from the database excluding sensitive information. + */ +export interface LinkedCalendarView { + alias: string + color?: LinkedCalendarViewColor + description?: LinkedCalendarViewDescription + id: number + is_active?: boolean + name?: LinkedCalendarViewName + url: string + user_id: number +} + +export type LinkedCalendarCreateName = string | null + +export type LinkedCalendarCreateDescription = string | null + +export type LinkedCalendarCreateColor = string | null + +/** + * Represents a linked calendar instance to be created. + */ +export interface LinkedCalendarCreate { + alias: string + color?: LinkedCalendarCreateColor + description?: LinkedCalendarCreateDescription + is_active?: boolean + name?: LinkedCalendarCreateName + url: string +} + +export interface LinenChangeEntryRrule { [key: string]: string } + +export interface LinenChangeEntry { + location: string + name?: string + rrule: LinenChangeEntryRrule +} + +export interface InJsonUser { + email: string + groups?: string[] +} + +export interface JsonPredefinedUsers { + users?: InJsonUser[] +} + +export interface HTTPValidationError { + detail?: ValidationError[] +} + +export type EntrySubjectRu = string | null + +export type EntrySubject = string | null + +export type EntryLocationRu = string | null + +export type EntryLocation = string | null + +export type EntryInstructor = string | null + +export interface Entry { + buddy?: boolean + instructor?: EntryInstructor + location?: EntryLocation + location_ru?: EntryLocationRu + subject?: EntrySubject + subject_ru?: EntrySubjectRu + when: string[] +} + +export type CreateTagType = string | null + +export type CreateTagSatellite = string | null + +export type CreateTagName = string | null + +export interface CreateTag { + alias: string + name?: CreateTagName + satellite?: CreateTagSatellite + type?: CreateTagType +} + +export type CreateEventGroupPath = string | null + +export type CreateEventGroupDescription = string | null + +export interface CreateEventGroup { + alias: string + description?: CreateEventGroupDescription + name: string + path?: CreateEventGroupPath + tags?: CreateTag[] +} + +export interface CleaningEntry { + dates: string[] + location: string + name?: string +} + +export interface CleaningParserConfig { + cleaning_entries: CleaningEntry[] + linen_change_entries: LinenChangeEntry[] + start_date: string +} + +export interface BuddyGroup { + name: string + number: string + tg: string +} + +export interface BootcampParserConfig { + academic_groups: AcademicGroup[] + buddy_groups: BuddyGroup[] + general_events: Entry[] + when: string + workshops: Workshop[] +} + +export interface BodyTagsBatchCreateTags { + tags: CreateTag[] +} + +export interface BodyEventGroupsSetEventGroupIcs { + ics_file: Blob +} + +export interface BodyEventGroupsBatchCreateEventGroups { + event_groups: CreateEventGroup[] +} + +export type AcademicGroupMath = Entry | null + +export type AcademicGroupLabs = Entry | null + +export type AcademicGroupEnglish = Entry | null + +export interface AcademicGroup { + english?: AcademicGroupEnglish + labs?: AcademicGroupLabs + math?: AcademicGroupMath + name: string + ru?: boolean +} + +type SecondParameter any> = Parameters[1] + +export function getInNoHassleEventsAPI() { +/** + * Get current user info if authenticated + * @summary Get Me + */ + const usersGetMe = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me`, method: 'GET', + }, + options, + ) + } + + /** + * Get predefined event groups for user + * @summary Get Predefined + */ + const usersGetPredefined = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/predefined`, method: 'GET', + }, + options, + ) + } + + /** + * Add favorite to current user + * @summary Add Favorite + */ + const usersAddFavorite = ( + params: UsersAddFavoriteParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/favorites`, method: 'POST', params }, + options, + ) + } + + /** + * Delete favorite from current user + * @summary Delete Favorite + */ + const usersDeleteFavorite = ( + params: UsersDeleteFavoriteParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/favorites`, method: 'DELETE', params }, + options, + ) + } + + /** + * Hide favorite from current user + * @summary Hide Favorite + */ + const usersHideFavorite = ( + params: UsersHideFavoriteParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/favorites/hide`, method: 'POST', params }, + options, + ) + } + + /** + * Hide music room, sports or moodle from current user + * @summary Hide Target + */ + const usersHideTarget = ( + target: 'music-room' | 'sports' | 'moodle', + params?: UsersHideTargetParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/${target}/hide`, method: 'POST', params }, + options, + ) + } + + /** + * Add linked calendar to current user + * @summary Link Calendar + */ + const usersLinkCalendar = ( + linkedCalendarCreate: LinkedCalendarCreate, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/linked`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: linkedCalendarCreate }, + options, + ) + } + + /** + * Generate an access key for the user schedule + * @summary Generate User Schedule Key + */ + const usersGenerateUserScheduleKey = ( + params: UsersGenerateUserScheduleKeyParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise<_GetScheduleAccessKeyResponse>( + { url: `/users/me/get-schedule-access-key`, method: 'POST', params }, + options, + ) + } + + /** + * Get all access keys for the user schedule + * @summary Get User Schedule Keys + */ + const usersGetUserScheduleKeys = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/schedule-access-keys`, method: 'GET', + }, + options, + ) + } + + /** + * Delete an access key for the user schedule + * @summary Delete User Schedule Key + */ + const usersDeleteUserScheduleKey = ( + params: UsersDeleteUserScheduleKeyParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/schedule-access-key`, method: 'DELETE', params }, + options, + ) + } + + /** + * @summary Set User Moodle Data + */ + const usersSetUserMoodleData = ( + params: UsersSetUserMoodleDataParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/me/set-moodle`, method: 'POST', params }, + options, + ) + } + + /** + * Get a list of all event groups + * @summary List Event Groups + */ + const eventGroupsListEventGroups = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/event-groups/`, method: 'GET', + }, + options, + ) + } + + /** + * @summary Create Event Group + */ + const eventGroupsCreateEventGroup = ( + createEventGroup: CreateEventGroup, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createEventGroup }, + options, + ) + } + + /** + * @summary Batch Create Event Groups + */ + const eventGroupsBatchCreateEventGroups = ( + bodyEventGroupsBatchCreateEventGroups: BodyEventGroupsBatchCreateEventGroups, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/batch-create-or-read`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: bodyEventGroupsBatchCreateEventGroups }, + options, + ) + } + + /** + * @summary Update Event Group + */ + const eventGroupsUpdateEventGroup = ( + eventGroupId: number, + updateEventGroup: UpdateEventGroup, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/${eventGroupId}`, method: 'PUT', headers: { 'Content-Type': 'application/json' }, data: updateEventGroup }, + options, + ) + } + + /** + * Get event group info by id + * @summary Get Event Group + */ + const eventGroupsGetEventGroup = ( + eventGroupId: number, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/${eventGroupId}`, method: 'GET', + }, + options, + ) + } + + /** + * Get event group info by path + * @summary Find Event Group By Path + */ + const eventGroupsFindEventGroupByPath = ( + params: EventGroupsFindEventGroupByPathParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/by-path`, method: 'GET', params }, + options, + ) + } + + /** + * Get event group info by alias + * @summary Find Event Group By Alias + */ + const eventGroupsFindEventGroupByAlias = ( + params: EventGroupsFindEventGroupByAliasParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/by-alias`, method: 'GET', params }, + options, + ) + } + + /** + * Delete event group by alias + * @summary Delete Event Group By Alias + */ + const eventGroupsDeleteEventGroupByAlias = ( + params: EventGroupsDeleteEventGroupByAliasParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/event-groups/by-alias`, method: 'DELETE', params }, + options, + ) + } + + /** + * Load .ics file to event group by event group id and save file to predefined path + * @summary Set Event Group Ics + */ + const eventGroupsSetEventGroupIcs = ( + eventGroupId: number, + bodyEventGroupsSetEventGroupIcs: BodyEventGroupsSetEventGroupIcs, + options?: SecondParameter, + ) => { + const formData = new FormData() + formData.append('ics_file', bodyEventGroupsSetEventGroupIcs.ics_file) + + return eventsQueryPromise( + { url: `/event-groups/${eventGroupId}/schedule.ics`, method: 'PUT', headers: { 'Content-Type': 'multipart/form-data' }, data: formData }, + options, + ) + } + + /** + * Get a list of all tags + * @summary List Tags + */ + const tagsListTags = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/tags/`, method: 'GET', + }, + options, + ) + } + + /** + * Create tags in batch + * @summary Batch Create Tags + */ + const tagsBatchCreateTags = ( + bodyTagsBatchCreateTags: BodyTagsBatchCreateTags, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/tags/batch-create-or-read`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: bodyTagsBatchCreateTags }, + options, + ) + } + + /** + * Get schedule in ICS format for the current user + * @summary Get Current User Schedule + */ + const icsGetCurrentUserSchedule = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/all.ics`, method: 'GET', + }, + options, + ) + } + + /** + * Get schedule in ICS format for the user; requires access key for `/users/{user_id}/all.ics` resource + * @summary Get User Schedule + */ + const icsGetUserSchedule = ( + userId: number, + params: IcsGetUserScheduleParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/${userId}/all.ics`, method: 'GET', params }, + options, + ) + } + + /** + * Get schedule in ICS format for the current user + * @summary Get Music Room Current User Schedule + */ + const icsGetMusicRoomCurrentUserSchedule = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/music-room.ics`, method: 'GET', + }, + options, + ) + } + + /** + * Get schedule in ICS format for the user; requires access key for `/users/{user_id}/music-room.ics` resource + * @summary Get Music Room User Schedule + */ + const icsGetMusicRoomUserSchedule = ( + userId: number, + params: IcsGetMusicRoomUserScheduleParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/${userId}/music-room.ics`, method: 'GET', params }, + options, + ) + } + + /** + * Get schedule in ICS format for the current user + * @summary Get Sport Current User Schedule + */ + const icsGetSportCurrentUserSchedule = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/sport.ics`, method: 'GET', + }, + options, + ) + } + + /** + * Get schedule in ICS format for the user; requires access key for `/users/{user_id}/sport.ics` resource + * @summary Get Sport User Schedule + */ + const icsGetSportUserSchedule = ( + userId: number, + params: IcsGetSportUserScheduleParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/${userId}/sport.ics`, method: 'GET', params }, + options, + ) + } + + /** + * Get schedule in ICS format for the current user + * @summary Get Moodle User Schedule + */ + const icsGetMoodleUserSchedule = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/users/me/moodle.ics`, method: 'GET', + }, + options, + ) + } + + /** + * Get schedule in ICS format for the user; requires access key for `/users/{user_id}/moodle.ics` resource + * @summary Get Moodle Current User Schedule + */ + const icsGetMoodleCurrentUserSchedule = ( + userId: number, + params: IcsGetMoodleCurrentUserScheduleParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/${userId}/moodle.ics`, method: 'GET', params }, + options, + ) + } + + /** + * Get schedule in ICS format for the user + * @summary Get User Linked Schedule + */ + const icsGetUserLinkedSchedule = ( + userId: number, + linkedAlias: string, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/users/${userId}/linked/${linkedAlias}.ics`, method: 'GET', + }, + options, + ) + } + + /** + * Get schedule in ICS format for the music room + * @summary Get Music Room Schedule + */ + const icsGetMusicRoomSchedule = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/music-room.ics`, method: 'GET', responseType: 'blob', + }, + options, + ) + } + + /** + * Get event group .ics file by id + * @summary Get Event Group Ics By Alias + */ + const icsGetEventGroupIcsByAlias = ( + eventGroupAlias: string, + params: IcsGetEventGroupIcsByAliasParams, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/${eventGroupAlias}.ics`, method: 'GET', params, responseType: 'blob', + }, + options, + ) + } + + /** + * @summary Parse Cleaning Schedule + */ + const parseParseCleaningSchedule = ( + cleaningParserConfig: CleaningParserConfig, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/parse/cleaning`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: cleaningParserConfig }, + options, + ) + } + + /** + * @summary Parse Bootcamp Schedule + */ + const parseParseBootcampSchedule = ( + bootcampParserConfig: BootcampParserConfig, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/parse/bootcamp`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: bootcampParserConfig }, + options, + ) + } + + /** + * @summary Get Predefined Data + */ + const predefinedGetPredefinedData = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/get-predefined-data`, method: 'GET', + }, + options, + ) + } + + /** + * @summary Update Predefined Data + */ + const predefinedUpdatePredefinedData = ( + jsonPredefinedUsers: JsonPredefinedUsers, + options?: SecondParameter, + ) => { + return eventsQueryPromise( + { url: `/update-predefined-data`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: jsonPredefinedUsers }, + options, + ) + } + + /** + * Endpoint that serves Prometheus metrics. + * @summary Metrics + */ + const metrics = ( + + options?: SecondParameter) => { + return eventsQueryPromise( + { url: `/metrics`, method: 'GET', + }, + options, + ) + } + + return { usersGetMe, usersGetPredefined, usersAddFavorite, usersDeleteFavorite, usersHideFavorite, usersHideTarget, usersLinkCalendar, usersGenerateUserScheduleKey, usersGetUserScheduleKeys, usersDeleteUserScheduleKey, usersSetUserMoodleData, eventGroupsListEventGroups, eventGroupsCreateEventGroup, eventGroupsBatchCreateEventGroups, eventGroupsUpdateEventGroup, eventGroupsGetEventGroup, eventGroupsFindEventGroupByPath, eventGroupsFindEventGroupByAlias, eventGroupsDeleteEventGroupByAlias, eventGroupsSetEventGroupIcs, tagsListTags, tagsBatchCreateTags, icsGetCurrentUserSchedule, icsGetUserSchedule, icsGetMusicRoomCurrentUserSchedule, icsGetMusicRoomUserSchedule, icsGetSportCurrentUserSchedule, icsGetSportUserSchedule, icsGetMoodleUserSchedule, icsGetMoodleCurrentUserSchedule, icsGetUserLinkedSchedule, icsGetMusicRoomSchedule, icsGetEventGroupIcsByAlias, parseParseCleaningSchedule, parseParseBootcampSchedule, predefinedGetPredefinedData, predefinedUpdatePredefinedData, metrics } +} +export type UsersGetMeResult = NonNullable['usersGetMe']>>> +export type UsersGetPredefinedResult = NonNullable['usersGetPredefined']>>> +export type UsersAddFavoriteResult = NonNullable['usersAddFavorite']>>> +export type UsersDeleteFavoriteResult = NonNullable['usersDeleteFavorite']>>> +export type UsersHideFavoriteResult = NonNullable['usersHideFavorite']>>> +export type UsersHideTargetResult = NonNullable['usersHideTarget']>>> +export type UsersLinkCalendarResult = NonNullable['usersLinkCalendar']>>> +export type UsersGenerateUserScheduleKeyResult = NonNullable['usersGenerateUserScheduleKey']>>> +export type UsersGetUserScheduleKeysResult = NonNullable['usersGetUserScheduleKeys']>>> +export type UsersDeleteUserScheduleKeyResult = NonNullable['usersDeleteUserScheduleKey']>>> +export type UsersSetUserMoodleDataResult = NonNullable['usersSetUserMoodleData']>>> +export type EventGroupsListEventGroupsResult = NonNullable['eventGroupsListEventGroups']>>> +export type EventGroupsCreateEventGroupResult = NonNullable['eventGroupsCreateEventGroup']>>> +export type EventGroupsBatchCreateEventGroupsResult = NonNullable['eventGroupsBatchCreateEventGroups']>>> +export type EventGroupsUpdateEventGroupResult = NonNullable['eventGroupsUpdateEventGroup']>>> +export type EventGroupsGetEventGroupResult = NonNullable['eventGroupsGetEventGroup']>>> +export type EventGroupsFindEventGroupByPathResult = NonNullable['eventGroupsFindEventGroupByPath']>>> +export type EventGroupsFindEventGroupByAliasResult = NonNullable['eventGroupsFindEventGroupByAlias']>>> +export type EventGroupsDeleteEventGroupByAliasResult = NonNullable['eventGroupsDeleteEventGroupByAlias']>>> +export type EventGroupsSetEventGroupIcsResult = NonNullable['eventGroupsSetEventGroupIcs']>>> +export type TagsListTagsResult = NonNullable['tagsListTags']>>> +export type TagsBatchCreateTagsResult = NonNullable['tagsBatchCreateTags']>>> +export type IcsGetCurrentUserScheduleResult = NonNullable['icsGetCurrentUserSchedule']>>> +export type IcsGetUserScheduleResult = NonNullable['icsGetUserSchedule']>>> +export type IcsGetMusicRoomCurrentUserScheduleResult = NonNullable['icsGetMusicRoomCurrentUserSchedule']>>> +export type IcsGetMusicRoomUserScheduleResult = NonNullable['icsGetMusicRoomUserSchedule']>>> +export type IcsGetSportCurrentUserScheduleResult = NonNullable['icsGetSportCurrentUserSchedule']>>> +export type IcsGetSportUserScheduleResult = NonNullable['icsGetSportUserSchedule']>>> +export type IcsGetMoodleUserScheduleResult = NonNullable['icsGetMoodleUserSchedule']>>> +export type IcsGetMoodleCurrentUserScheduleResult = NonNullable['icsGetMoodleCurrentUserSchedule']>>> +export type IcsGetUserLinkedScheduleResult = NonNullable['icsGetUserLinkedSchedule']>>> +export type IcsGetMusicRoomScheduleResult = NonNullable['icsGetMusicRoomSchedule']>>> +export type IcsGetEventGroupIcsByAliasResult = NonNullable['icsGetEventGroupIcsByAlias']>>> +export type ParseParseCleaningScheduleResult = NonNullable['parseParseCleaningSchedule']>>> +export type ParseParseBootcampScheduleResult = NonNullable['parseParseBootcampSchedule']>>> +export type PredefinedGetPredefinedDataResult = NonNullable['predefinedGetPredefinedData']>>> +export type PredefinedUpdatePredefinedDataResult = NonNullable['predefinedUpdatePredefinedData']>>> +export type MetricsResult = NonNullable['metrics']>>> diff --git a/src/shared/innohassle-api/events/axios.ts b/src/shared/innohassle-api/events/axios.ts new file mode 100644 index 0000000..b6a1e4a --- /dev/null +++ b/src/shared/innohassle-api/events/axios.ts @@ -0,0 +1,54 @@ +import type { AxiosRequestConfig } from 'axios' +import axios from 'axios' +import { getToken, invalidateToken } from '../token-store' +import { getStored } from '@/shared/storage' +import { INNOHASSLE_EVENTS_URL } from '@/shared/config/innohassle' + +// Axios client for InNoHassle Events API +export const AxiosEvents = axios.create({ + baseURL: INNOHASSLE_EVENTS_URL, +}) + +// Add token to Authorization header +AxiosEvents.interceptors.request.use(async (request) => { + const overrideBaseUrl = await getStored('innohassleEventsUrl') + if (overrideBaseUrl) { + request.baseURL = overrideBaseUrl + } + + const token = await getToken() + if (token) { + request.headers.Authorization = `Bearer ${token}` + } + + return request +}) + +// Invalidate token on errors +AxiosEvents.interceptors.response.use( + response => response, + async (error) => { + const { response } = error + if (response.status === 401) { + invalidateToken() + return Promise.reject(error) + } + }, +) + +// Method to query InNoHassle Events API and receive 'data' field on success +export function eventsQueryPromise(config: AxiosRequestConfig, options?: AxiosRequestConfig): Promise { + const source = axios.CancelToken.source() + const promise = AxiosEvents({ + ...config, + ...options, + cancelToken: source.token, + }).then(({ data }) => data) + + // @ts-expect-error + promise.cancel = () => { + source.cancel('Query was cancelled') + } + + return promise +} diff --git a/src/shared/innohassle-api/events/index.ts b/src/shared/innohassle-api/events/index.ts new file mode 100644 index 0000000..6fe7d09 --- /dev/null +++ b/src/shared/innohassle-api/events/index.ts @@ -0,0 +1,5 @@ +import { getInNoHassleEventsAPI } from './__generated__' + +export type * from './__generated__' + +export const events = getInNoHassleEventsAPI() diff --git a/src/shared/storage/types.d.ts b/src/shared/storage/types.d.ts index f132ac6..64bc960 100644 --- a/src/shared/storage/types.d.ts +++ b/src/shared/storage/types.d.ts @@ -24,4 +24,5 @@ export interface SharedStorage { allowSyncingCourses: boolean syncCoursesLastUpdateMS: number innohassleSearchUrl: string + innohassleEventsUrl: string }