UNPKG

motidata

Version:

Data retrieval library for services (e.g. App) accessing MotiMate's main Api

67 lines 2.76 kB
import { SimpleResponseHelpers, } from "../DTOs/SimpleResponseDTO.js"; import { BaseRepository, } from "./BaseRepository.js"; export class UserRepository extends BaseRepository { constructor(baseArgs) { super(baseArgs.apiBaseUrl, baseArgs.publicApiKey, baseArgs.sessionRepository); } /** * Sends a request to register the new user with {@link RegistrationDTO} and handles saving the sessionID from the Responses Header * @throws any `fetch()` related error * @throws any `Response.json()` related error * @throws any {@link sessionRepository} related Error */ async registerUser(body) { const RESPONSE = await fetch(await this._bulildRequest({ route: BaseRepository.Routes.registration, method: "POST", queryParams: new URLSearchParams({ username: body.username }), body: JSON.stringify(body), })); await this._handleResponseAfterAuthentication(RESPONSE); return SimpleResponseHelpers.transformToSimpleResponse(RESPONSE); } /** * @throws any `fetch()` related error * @throws any `Response.json()` related error * @throws any {@link sessionRepository} related Error */ async verifyUser(verificationCode) { const RESPONSE = await fetch(await this._bulildRequest({ route: BaseRepository.Routes.activation, method: "POST", queryParams: new URLSearchParams({ code: verificationCode }), body: JSON.stringify(verificationCode), })); return SimpleResponseHelpers.transformToSimpleResponse(RESPONSE); } /** * @throws any `fetch()` related error * @throws any `Response.json()` related error * @throws any {@link sessionRepository} related Error */ async updatePersonalGoal(goalPerWeek) { const RESPONSE = await fetch(await this._bulildRequest({ route: BaseRepository.Routes.personalGoal, method: "PUT", queryParams: new URLSearchParams({ goal: goalPerWeek.toString(), }), body: JSON.stringify(goalPerWeek), })); return SimpleResponseHelpers.transformToSimpleResponse(RESPONSE); } /** * @throws any `fetch()` related error * @throws any `Response.json()` related error * @throws any {@link sessionRepository} related Error */ async getUserInfo(abortSignal) { const RESPONSE = await fetch(await this._bulildRequest({ route: BaseRepository.Routes.userInfo, method: "GET", signal: abortSignal, })); return SimpleResponseHelpers.transformToSimpleResponse(RESPONSE); } } //# sourceMappingURL=UserRepository.js.map