55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { useAccessToken } from '../composables/useAccessToken';
|
|
import { BACKEND_URL } from '../constants';
|
|
import { BuildingListItem } from '../interfaces/building.interfaces';
|
|
import { FloorListItem } from '../interfaces/floor.interfaces';
|
|
import { RoomListItem } from '../interfaces/room.interfaces';
|
|
import jfetch from '../utils/jfetch';
|
|
|
|
const { authHeader } = useAccessToken();
|
|
export const useBuildingStore = defineStore('building', {
|
|
state: () => {
|
|
return {
|
|
buildings: [] as BuildingListItem[],
|
|
floors: [] as FloorListItem[],
|
|
};
|
|
},
|
|
actions: {
|
|
async getBuildings() {
|
|
const { data: buildings } = await jfetch(`${BACKEND_URL}/buildings`, {
|
|
headers: authHeader.value,
|
|
});
|
|
this.buildings = buildings;
|
|
},
|
|
async getFloors(building: number) {
|
|
const { data: floors } = await jfetch(
|
|
`${BACKEND_URL}/buildings/${building}/floors`,
|
|
{
|
|
headers: authHeader.value,
|
|
}
|
|
);
|
|
this.floors = floors;
|
|
},
|
|
async saveFloor(
|
|
building: number,
|
|
number: number,
|
|
floor: Partial<FloorListItem>
|
|
) {
|
|
await jfetch(`${BACKEND_URL}/buildings/${building}/floors/${number}`, {
|
|
method: 'PATCH',
|
|
headers: {
|
|
...authHeader.value,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(floor),
|
|
});
|
|
},
|
|
async upsertFloorRooms(
|
|
building: number,
|
|
floorNo: number,
|
|
rooms: RoomListItem[],
|
|
removedRooms: number[]
|
|
) {},
|
|
},
|
|
});
|