2022-09-05 00:55:52 +00:00
|
|
|
import { BaseAPI, route } from '../base';
|
2022-09-03 09:17:57 +00:00
|
|
|
import { Label } from './labels';
|
|
|
|
import { Location } from './locations';
|
|
|
|
import { Results } from './types';
|
|
|
|
|
|
|
|
export interface ItemCreate {
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
locationId: string;
|
|
|
|
labelIds: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Item {
|
|
|
|
createdAt: string;
|
|
|
|
description: string;
|
|
|
|
id: string;
|
|
|
|
labels: Label[];
|
|
|
|
location: Location;
|
|
|
|
manufacturer: string;
|
|
|
|
modelNumber: string;
|
|
|
|
name: string;
|
|
|
|
notes: string;
|
|
|
|
purchaseFrom: string;
|
|
|
|
purchasePrice: number;
|
|
|
|
purchaseTime: string;
|
|
|
|
serialNumber: string;
|
|
|
|
soldNotes: string;
|
|
|
|
soldPrice: number;
|
|
|
|
soldTime: string;
|
|
|
|
soldTo: string;
|
|
|
|
updatedAt: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ItemsApi extends BaseAPI {
|
|
|
|
async getAll() {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.get<Results<Item>>(route('/items'));
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async create(item: ItemCreate) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.post<ItemCreate, Item>(route('/items'), item);
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async get(id: string) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.get<Item>(route(`/items/${id}`));
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async delete(id: string) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.delete<void>(route(`/items/${id}`));
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async update(id: string, item: ItemCreate) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.put<ItemCreate, Item>(route(`/items/${id}`), item);
|
2022-09-03 09:17:57 +00:00
|
|
|
}
|
|
|
|
}
|