location API

This commit is contained in:
Hayden 2022-08-30 21:22:10 -08:00
parent c7cfb4335b
commit ec170f9b93
4 changed files with 43 additions and 4 deletions

View file

@ -0,0 +1,3 @@
export type Results<T> = {
items: T[];
};

View file

@ -0,0 +1,24 @@
import { BaseAPI, UrlBuilder } from '../base';
import { type Results } from '../base/base-types';
export type LocationCreate = {
name: string;
description: string;
};
export type Location = LocationCreate & {
id: string;
groupId: string;
createdAt: string;
updatedAt: string;
};
export class LocationsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Location>>(UrlBuilder('/locations'));
}
async create(location: LocationCreate) {
return this.http.post<LocationCreate, Location>(UrlBuilder('/locations'), location);
}
}

View file

@ -1,4 +1,6 @@
import { Requests } from '@/lib/requests';
import { BaseAPI, UrlBuilder } from './base'; import { BaseAPI, UrlBuilder } from './base';
import { LocationsApi } from './classes/locations';
export type Result<T> = { export type Result<T> = {
item: T; item: T;
@ -12,6 +14,16 @@ export type User = {
}; };
export class UserApi extends BaseAPI { export class UserApi extends BaseAPI {
locations: LocationsApi;
constructor(requests: Requests) {
super(requests);
this.locations = new LocationsApi(requests);
Object.freeze(this);
}
public self() { public self() {
return this.http.get<Result<User>>(UrlBuilder('/users/self')); return this.http.get<Result<User>>(UrlBuilder('/users/self'));
} }