kia-ml
Version:
Kia
65 lines (53 loc) • 1.93 kB
JavaScript
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { getGeneralApiProblem } from './api-problem';
import { bookmarkedRequestTransformer, singleRequestTransformer } from "../transformers/request-transformer";
import { paginatedRequestTransformer } from "../transformers/request-transformer";
import { paginationTransformer } from '../transformers/pagination-transformer';
export class RequestApi {
constructor(api) {
_defineProperty(this, "api", void 0);
this.api = api;
}
async getRequest(clientId, requestId) {
try {
const response = await this.api.apisauce.get(`api/client-user/${clientId}/request/${requestId}`);
if (!response.ok) {
const problem = getGeneralApiProblem(response);
if (problem) return problem;
}
return {
kind: "ok",
request: singleRequestTransformer(response)
};
} catch (e) {
return {
kind: "bad-data"
};
}
}
async getRequests(endPoint, screenMode) {
const response = await this.api.apisauce.get(endPoint);
if (!response.ok) {
const problem = getGeneralApiProblem(response);
if (problem) return problem;
}
console.log(response);
return {
kind: "ok",
requests: screenMode === 'bookmarks' ? bookmarkedRequestTransformer(response) : paginatedRequestTransformer(response),
pagination: paginationTransformer(response)
};
}
async createRequest(userId, data) {
const response = await this.api.apisauce.post(`api/request/${userId}`, data);
if (!response.ok) {
const problem = getGeneralApiProblem(response);
if (problem) return problem;
}
console.log(response);
return {
kind: "ok"
};
}
}
//# sourceMappingURL=request-api.js.map