diff --git a/src/deskstar-backend/Deskstar/Controllers/AuthController.cs b/src/deskstar-backend/Deskstar/Controllers/AuthController.cs index d859d3ed..a97051f4 100644 --- a/src/deskstar-backend/Deskstar/Controllers/AuthController.cs +++ b/src/deskstar-backend/Deskstar/Controllers/AuthController.cs @@ -31,7 +31,7 @@ public AuthController(ILogger logger, IAuthUsecases authUsecases /// Sample request: /// Post /auth/createToken /// - /// + /// /// Login succesful /// Credentials wrong or user not approved [HttpPost("createToken")] @@ -56,7 +56,7 @@ public IActionResult CreateToken(CreateTokenUser user) /// Sample request: /// Post /auth/register /// - /// + /// /// User added to db /// Mail already in use /// Company not found @@ -82,7 +82,7 @@ public IActionResult Register(RegisterUser registerUser) /// Sample request: /// Post /auth/registerAdmin /// - /// + /// /// Admin added to db /// Mail or Company name already in use [HttpPost("registerAdmin")] @@ -102,7 +102,7 @@ public IActionResult RegisterAdmin(RegisterAdminDto registerAdmin) } catch (Exception e) { - return Problem(statusCode: 500); + return Problem(statusCode: 500, detail:e.Message); } } -} \ No newline at end of file +} diff --git a/src/deskstar-backend/Deskstar/Controllers/ResourceController.cs b/src/deskstar-backend/Deskstar/Controllers/ResourceController.cs index 36f94985..f0f075a8 100644 --- a/src/deskstar-backend/Deskstar/Controllers/ResourceController.cs +++ b/src/deskstar-backend/Deskstar/Controllers/ResourceController.cs @@ -473,17 +473,49 @@ public IActionResult GetFloorsByBuildingId(string buildingId) return Ok(floor.ToList()); } + // /// + // /// Returns a list of Floors. + // /// + // /// A List of Floors in JSON Format + // /// + // /// Sample request: + // /// GET /resources/floors with JWT Token + // /// + // /// + // /// Returns the floor list + // /// Bad Request + // /// Internal Server Error + // [HttpGet("floors")] + // [Authorize] + // [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + // [ProducesResponseType(StatusCodes.Status500InternalServerError)] + // [Produces("application/json")] + // public IActionResult GetAllFloors() + // { + // var callerId = RequestInteractions.ExtractIdFromRequest(Request); + // List floor; + // try + // { + // floor = _resourceUsecases.GetFloors(callerId, ""); + // } + // catch (ArgumentException e) + // { + // return Problem(statusCode: 500, detail: e.Message); + // } + + // return Ok(floor.ToList()); + // } + /// - /// Returns a list of Floors. + /// Returns a list of all Floors. /// - /// A List of Floors in JSON Format + /// A List of Floors in JSON Format (can be empty) /// /// Sample request: /// GET /resources/floors with JWT Token /// /// /// Returns the floor list - /// Bad Request /// Internal Server Error [HttpGet("floors")] [Authorize] @@ -492,17 +524,16 @@ public IActionResult GetFloorsByBuildingId(string buildingId) [Produces("application/json")] public IActionResult GetAllFloors() { - var callerId = RequestInteractions.ExtractIdFromRequest(Request); List floor; + var adminId = RequestInteractions.ExtractIdFromRequest(Request); try { - floor = _resourceUsecases.GetFloors(callerId, ""); + floor = _resourceUsecases.GetAllFloors(adminId); } catch (ArgumentException e) { return Problem(statusCode: 500, detail: e.Message); } - return Ok(floor.ToList()); } @@ -670,17 +701,49 @@ public IActionResult GetRoomsByFloorId(string floorId) return Ok(rooms.ToList()); } + // /// + // /// Returns a list of Rooms. + // /// + // /// A List of Rooms in JSON Format + // /// + // /// Sample request: + // /// GET /resources/rooms with JWT Token + // /// + // /// + // /// Returns the rooms list + // /// Bad Request + // /// Internal Server Error + // [HttpGet("rooms")] + // [Authorize] + // [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + // [ProducesResponseType(StatusCodes.Status500InternalServerError)] + // [Produces("application/json")] + // public IActionResult GetAllRooms() + // { + // var callerId = RequestInteractions.ExtractIdFromRequest(Request); + // List rooms; + // try + // { + // rooms = _resourceUsecases.GetRooms(callerId, ""); + // } + // catch (ArgumentException e) + // { + // return Problem(statusCode: 500, detail: e.Message); + // } + + // return Ok(rooms.ToList()); + // } + /// - /// Returns a list of Rooms. + /// Returns a list of all Rooms. /// - /// A List of Rooms in JSON Format + /// A List of Rooms in JSON Format (can be empty) /// /// Sample request: /// GET /resources/rooms with JWT Token /// /// /// Returns the rooms list - /// Bad Request /// Internal Server Error [HttpGet("rooms")] [Authorize] @@ -689,11 +752,11 @@ public IActionResult GetRoomsByFloorId(string floorId) [Produces("application/json")] public IActionResult GetAllRooms() { - var callerId = RequestInteractions.ExtractIdFromRequest(Request); List rooms; + var adminId = RequestInteractions.ExtractIdFromRequest(Request); try { - rooms = _resourceUsecases.GetRooms(callerId, ""); + rooms = _resourceUsecases.GetAllRooms(adminId); } catch (ArgumentException e) { @@ -871,18 +934,50 @@ public IActionResult GetDesksByRoomId(string roomId, long start = 0, long end = return Ok(desks.ToList()); } + // /// + // /// Returns a list of Desks. + // /// + // /// A List of Desks in JSON Format + // /// + // /// Sample request: + // /// GET /resources/desks + // /// with JWT Token + // /// + // /// + // /// Returns the desks list + // /// Bad Request + // /// Internal Server Error + // [HttpGet("desks")] + // [Authorize] + // [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + // [ProducesResponseType(StatusCodes.Status500InternalServerError)] + // [Produces("application/json")] + // public IActionResult GetAllDesks() + // { + // var callerId = RequestInteractions.ExtractIdFromRequest(Request); + // List desks; + // try + // { + // desks = _resourceUsecases.GetDesks(callerId, "", DateTime.MinValue, DateTime.MaxValue); + // } + // catch (ArgumentException e) + // { + // return Problem(statusCode: 500, detail: e.Message); + // } + + // return Ok(desks.ToList()); + // } + /// - /// Returns a list of Desks. + /// Returns a list of all Desks. /// - /// A List of Desks in JSON Format + /// A List of Desks in JSON Format by RoomId (can be empty) /// /// Sample request: - /// GET /resources/desks - /// with JWT Token + /// GET /resources/desks with JWT Token /// /// /// Returns the desks list - /// Bad Request /// Internal Server Error [HttpGet("desks")] [Authorize] @@ -891,11 +986,11 @@ public IActionResult GetDesksByRoomId(string roomId, long start = 0, long end = [Produces("application/json")] public IActionResult GetAllDesks() { - var callerId = RequestInteractions.ExtractIdFromRequest(Request); List desks; + var adminId = RequestInteractions.ExtractIdFromRequest(Request); try { - desks = _resourceUsecases.GetDesks(callerId, "", DateTime.MinValue, DateTime.MaxValue); + desks = _resourceUsecases.GetAllDesks(adminId); } catch (ArgumentException e) { @@ -1246,4 +1341,4 @@ public IActionResult RestoreDeskType(string deskTypeId) return Problem(statusCode: 500); } } -} \ No newline at end of file +} diff --git a/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs b/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs index 9ecb0293..82de9c1b 100644 --- a/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs +++ b/src/deskstar-backend/Deskstar/Models/CurrentFloor.cs @@ -10,6 +10,9 @@ public class CurrentFloor [Required] public string FloorName { get; set; } = null!; + [Required] + public string BuildingId { get; set; } = null!; + [Required] public string BuildingName { get; set; } = null!; diff --git a/src/deskstar-backend/Deskstar/Models/CurrentRoom.cs b/src/deskstar-backend/Deskstar/Models/CurrentRoom.cs index b85af5e4..3aedeb51 100644 --- a/src/deskstar-backend/Deskstar/Models/CurrentRoom.cs +++ b/src/deskstar-backend/Deskstar/Models/CurrentRoom.cs @@ -10,6 +10,9 @@ public class CurrentRoom [Required] public string RoomName { get; set; } = null!; + [Required] + public string FloorId { get; set; } = null!; + [Required] public string Floor { get; set; } = null!; diff --git a/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs b/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs index b54f61cb..92f6b9f0 100644 --- a/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs +++ b/src/deskstar-backend/Deskstar/Usecases/ResourceUsecases.cs @@ -12,8 +12,12 @@ public interface IResourceUsecases public List GetDeskTypes(Guid companyId); public List GetBuildings(Guid userId); public List GetFloors(Guid callerId, string buildingId); + public List GetAllFloors(Guid userId); public List GetRooms(Guid callerId, string floorId); + + public List GetAllRooms(Guid userId); public List GetDesks(Guid callerId, string roomId, DateTime start, DateTime end); + public List GetAllDesks(Guid userId); public CurrentDesk GetDesk(Guid deskId, DateTime startDateTime, DateTime endDateTime); public Desk CreateDesk(string deskName, Guid deskTypeId, Guid roomId); @@ -371,6 +375,37 @@ public List GetFloors(Guid callerId, string buildingId) return mapFloorsToCurrentFloors.ToList(); } + public List GetAllFloors(Guid userId) + { + IQueryable databaseFloors; + try + { + var companyId = _context.Users.Where(user => user.UserId == userId).Select(user => user.CompanyId).First(); + databaseFloors = _context.Floors.Where(floor => floor.Building.CompanyId == companyId); + } + catch (Exception e) when (e is FormatException or ArgumentNullException or OverflowException) + { + _logger.LogError(e, e.Message); + throw new ArgumentException($"'{userId}' is not a valid UserId"); + } + catch (InvalidOperationException) + { + throw new ArgumentException($"There is no User with id '{userId}'"); + } + + if (databaseFloors.ToList().Count == 0) return new List(); + + var mapFloorsToCurrentFloors = databaseFloors.Select(f => new CurrentFloor + { + BuildingId = f.BuildingId.ToString(), + BuildingName = f.Building.BuildingName, + FloorName = f.FloorName, + FloorId = f.FloorId.ToString(), + IsMarkedForDeletion = f.IsMarkedForDeletion + }); + + return mapFloorsToCurrentFloors.ToList(); + } public List GetRooms(Guid callerId, string floorId) { IQueryable databaseRooms; @@ -445,6 +480,36 @@ public List GetRooms(Guid callerId, string floorId) return mapRoomsToCurrentRooms.ToList(); } + public List GetAllRooms(Guid userId) + { + IQueryable databaseRooms; + try + { + var companyId = _context.Users.Where(user => user.UserId == userId).Select(user => user.CompanyId).First(); + databaseRooms = _context.Rooms.Where(room => room.Floor.Building.CompanyId == companyId); + } + catch (Exception e) when (e is FormatException or ArgumentNullException or OverflowException) + { + _logger.LogError(e, e.Message); + throw new ArgumentException($"'{userId}' is not a valid UserId"); + } + catch (InvalidOperationException) + { + throw new ArgumentException($"There is no User with id '{userId}'"); + } + + if (databaseRooms.ToList().Count == 0) return new List(); + + var mapRoomsToCurrentRooms = databaseRooms.Select(r => new CurrentRoom + { + RoomId = r.RoomId.ToString(), + RoomName = r.RoomName, + FloorId = r.FloorId.ToString(), + IsMarkedForDeletion = r.IsMarkedForDeletion + }); + + return mapRoomsToCurrentRooms.ToList(); + } public List GetDesks(Guid callerId, string roomId, DateTime start, DateTime end) { IQueryable mapDesksToCurrentDesks; @@ -536,6 +601,41 @@ private static IQueryable MapDesksToCurrentDesks(IQueryable d }); } + public List GetAllDesks(Guid userId) + { + IQueryable mapDesksToCurrentDesks; + try + { + var companyId = _context.Users.Where(user => user.UserId == userId).Select(user => user.CompanyId).First(); + var databaseDesks = _context.Desks.Where(desk => desk.Room.Floor.Building.CompanyId == companyId); + + mapDesksToCurrentDesks = databaseDesks.Select(desk => new CurrentDesk + { + DeskId = desk.DeskId.ToString(), + DeskName = desk.DeskName, + DeskTyp = desk.DeskType.DeskTypeName, + FloorName = desk.Room.Floor.FloorName, + FloorId = desk.Room.Floor.FloorId.ToString(), + RoomId = desk.Room.RoomId.ToString(), + RoomName = desk.Room.RoomName, + BuildingId = desk.Room.Floor.Building.BuildingId.ToString(), + BuildingName = desk.Room.Floor.Building.BuildingName, + Location = desk.Room.Floor.Building.Location, + IsMarkedForDeletion = desk.IsMarkedForDeletion + }); + } + catch (Exception e) when (e is FormatException or ArgumentNullException or OverflowException) + { + _logger.LogError(e, e.Message); + throw new ArgumentException($"'{userId}' is not a valid UserId"); + } + catch (InvalidOperationException) + { + throw new ArgumentException($"There is no User with id '{userId}'"); + } + + return mapDesksToCurrentDesks.ToList(); + } public CurrentDesk GetDesk(Guid deskId, DateTime startDateTime, DateTime endDateTime) { CurrentDesk mapDeskToCurrentDesk; diff --git a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecasesTests.cs b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecasesTests.cs index b9e91c40..44646089 100644 --- a/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecasesTests.cs +++ b/src/deskstar-backend/Teststar.Tests/Tests/ResourceUsecasesTests.cs @@ -2365,6 +2365,48 @@ public void GetBuildings_WhenOneBuildingFound_ShouldReturnAException() db.Database.EnsureDeleted(); } + [Test] + public void GetAllFloors_WhenNoFloorFound_ShouldReturnAEmptyList() + { + //setup + using var db = new DataContext(); + + var userId = Guid.NewGuid(); + var companyId = Guid.NewGuid(); + var hasher = new PasswordHasher(); + var company = new Company + { + CompanyId = companyId, + CompanyName = "gehmalbierholn" + }; + var user = new User + { + UserId = userId, + MailAddress = "test@example.de", + FirstName = "testF", + LastName = "testL", + CompanyId = company.CompanyId, + IsApproved = true + }; + user.Password = hasher.HashPassword(user, "testpw"); + db.Add(company); + db.Add(user); + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act + var result = usecases.GetAllFloors(userId); + + //assert + Assert.That(result, Is.Empty); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] public void GetFloors_WhenNoFloorFound_ShouldReturnAEmptyList() { @@ -2569,6 +2611,90 @@ public void GetRooms_WhenNoRoomIdProvided_ShouldReturnAnList() db.Database.EnsureDeleted(); } + [Test] + public void GetAllRooms_WhenNoRoomIsFound_ShouldReturnEmptyList() + { + //setup + using var db = new DataContext(); + + var userId = Guid.NewGuid(); + var companyId = Guid.NewGuid(); + var hasher = new PasswordHasher(); + var company = new Company + { + CompanyId = companyId, + CompanyName = "gehmalbierholn" + }; + var user = new User + { + UserId = userId, + MailAddress = "test@example.de", + FirstName = "testF", + LastName = "testL", + CompanyId = company.CompanyId, + IsApproved = true + }; + user.Password = hasher.HashPassword(user, "testpw"); + db.Add(company); + db.Add(user); + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act + var result = usecases.GetAllRooms(userId); + + //assert + Assert.IsEmpty(result); + + //cleanup + db.Database.EnsureDeleted(); + } + + [Test] + public void GetAllDesks_WhenNoDeskIsFound_ShouldReturnEmptyList() + { + //setup + using var db = new DataContext(); + + var userId = Guid.NewGuid(); + var companyId = Guid.NewGuid(); + var hasher = new PasswordHasher(); + var company = new Company + { + CompanyId = companyId, + CompanyName = "gehmalbierholn" + }; + var user = new User + { + UserId = userId, + MailAddress = "test@example.de", + FirstName = "testF", + LastName = "testL", + CompanyId = company.CompanyId, + IsApproved = true + }; + user.Password = hasher.HashPassword(user, "testpw"); + db.Add(company); + db.Add(user); + db.SaveChanges(); + + //arrange + var logger = new Mock>(); + var usecases = new ResourceUsecases(logger.Object, db, SetupUserUsecases(db)); + + //act + var result = usecases.GetAllDesks(userId); + + //assert + Assert.That(result, Is.Empty); + + //cleanup + db.Database.EnsureDeleted(); + } + [Test] public void GetDesks_WhenNoDeskFound_ShouldReturnAEmptyList() { diff --git a/src/deskstar-frontend/lib/api/ResourceService.ts b/src/deskstar-frontend/lib/api/ResourceService.ts index b53775fa..66e02866 100644 --- a/src/deskstar-frontend/lib/api/ResourceService.ts +++ b/src/deskstar-frontend/lib/api/ResourceService.ts @@ -50,22 +50,31 @@ export async function getBuildings(session: Session): Promise { /** * Lists all floors of a building * @param session The user session - * @param buildingId The building id + * @param buildingId? The building id * @returns All floors of `buildingId` * @throws Error containing status code and/or error message */ export async function getFloors( session: Session, - buildingId: string + buildingId?: string ): Promise { - const response = await fetch( - BACKEND_URL + `/resources/buildings/${buildingId}/floors`, - { + let response; + if (buildingId) { + response = await fetch( + BACKEND_URL + `/resources/buildings/${buildingId}/floors`, + { + headers: { + Authorization: `Bearer ${session.accessToken}`, + }, + } + ); + } else { + response = await fetch(BACKEND_URL + `/resources/floors`, { headers: { Authorization: `Bearer ${session.accessToken}`, }, - } - ); + }); + } if (!response.ok) throw Error(`${response.status} ${response.statusText}`); @@ -95,22 +104,28 @@ export async function getAllFloors(session: Session): Promise { /** * Lists all rooms of a floor * @param session The user session - * @param floorId The floor id + * @param floorId? The floor id * @returns All rooms of `floorId` * @throws Error containing status code and/or error message */ export async function getRooms( session: Session, - floorId: string + floorId?: string ): Promise { - const response = await fetch( - BACKEND_URL + `/resources/floors/${floorId}/rooms`, - { + let response; + if (floorId) { + response = await fetch(BACKEND_URL + `/resources/floors/${floorId}/rooms`, { headers: { Authorization: `Bearer ${session.accessToken}`, }, - } - ); + }); + } else { + response = await fetch(BACKEND_URL + `/resources/rooms`, { + headers: { + Authorization: `Bearer ${session.accessToken}`, + }, + }); + } if (!response.ok) throw Error(`${response.status} ${response.statusText}`); @@ -140,15 +155,15 @@ export async function getAllRooms(session: Session): Promise { /** * Lists all available desks of a room * @param session The user session - * @param roomId The room id - * @param startTime optional - * @param endTime optional + * @param roomId? optional The room id + * @param startTime? optional + * @param endTime? optional * @returns All available desks * @throws Error containing status code and/or error message */ export async function getDesks( session: Session, - roomId: string, + roomId?: string, startTime?: number, endTime?: number ): Promise { @@ -156,14 +171,26 @@ export async function getDesks( if (startTime) params.append("start", startTime.toString()); if (endTime) params.append("end", endTime.toString()); - const response = await fetch( - BACKEND_URL + `/resources/rooms/${roomId}/desks?${params.toString()}`, - { - headers: { - Authorization: `Bearer ${session.accessToken}`, - }, - } - ); + let response; + if (roomId) { + response = await fetch( + BACKEND_URL + `/resources/rooms/${roomId}/desks?${params.toString()}`, + { + headers: { + Authorization: `Bearer ${session.accessToken}`, + }, + } + ); + } else { + response = await fetch( + BACKEND_URL + `/resources/desks?${params.toString()}`, + { + headers: { + Authorization: `Bearer ${session.accessToken}`, + }, + } + ); + } if (!response.ok) throw Error(`${response.status} ${response.statusText}`); diff --git a/src/deskstar-frontend/pages/resources/index.tsx b/src/deskstar-frontend/pages/resources/index.tsx index 2f5de41e..529bc5d9 100644 --- a/src/deskstar-frontend/pages/resources/index.tsx +++ b/src/deskstar-frontend/pages/resources/index.tsx @@ -52,9 +52,15 @@ import { UpdateDeskDto } from "../../types/models/UpdateDeskDto"; const ResourceOverview = ({ buildings: origBuildings, + floors: origFloors, + rooms: origRooms, + desks: origDesks, deskTypes: origDeskTypes, }: { buildings: IBuilding[]; + floors: IFloor[]; + rooms: IRoom[]; + desks: IDesk[]; deskTypes: IDeskType[]; }) => { let { data: session } = useSession(); @@ -128,6 +134,7 @@ const ResourceOverview = ({ .filter((building) => !building.isMarkedForDeletion); setBuildings(buildings); + onSelectedBuildingChange(buildings); } function stopFetchingAnimation() { @@ -138,95 +145,44 @@ const ResourceOverview = ({ async function onSelectedBuildingChange(selectedBuildings: IBuilding[]) { setIsFetching(true); - const promises = await Promise.all( - selectedBuildings.map(async (building) => { - if (!session) return []; - - let resFloors; - try { - resFloors = await getFloors(session, building.buildingId); - } catch (error) { - toast.error(`${error}`); - return []; - } - - const enrichedFloors = resFloors - .map((floor) => { - floor.buildingName = building.buildingName; - floor.location = building.location; - return floor; - }) - .filter((floor) => !floor.isMarkedForDeletion); - return enrichedFloors; + setIsFetching(true); + let floors = origFloors.filter((floor) => + selectedBuildings.some((building) => { + return building.buildingId === floor.buildingId; }) ); - - setFloors(promises.flat()); - setIsFetching(true); + floors = floors.filter((floor) => !floor.isMarkedForDeletion); + setFloors(floors); + onSelectedFloorChange(floors); stopFetchingAnimation(); } async function onSelectedFloorChange(selectedFloors: IFloor[]) { setIsFetching(true); - const promises = await Promise.all( - selectedFloors.map(async (floor) => { - if (!session) return []; - - let resRooms; - try { - resRooms = await getRooms(session, floor.floorId); - } catch (error) { - toast.error(`${error}`); - return []; - } - - const enrichedRooms = resRooms - .map((room) => { - room.building = floor.buildingName; - room.location = floor.location; - room.floor = floor.floorName; - return room; - }) - .filter((room) => !room.isMarkedForDeletion); - return enrichedRooms; + let rooms = origRooms.filter((room) => + selectedFloors.some((floor) => { + return floor.floorId === room.floorId; }) ); + rooms = rooms.filter((room) => !room.isMarkedForDeletion); - setRooms(promises.flat()); + setRooms(rooms); + onSelectedRoomChange(rooms); stopFetchingAnimation(); } async function onSelectedRoomChange(selectedRooms: IRoom[]) { setIsFetching(true); - const promises = await Promise.all( - selectedRooms.map(async (room) => { - if (!session) { - return []; - } - - let resDeskType; - try { - resDeskType = await getDesks( - session, - room.roomId, - new Date().getTime(), - new Date().getTime() - ); - } catch (error) { - toast.error(`${error}`); - return []; - } - - resDeskType.filter((deskType) => !deskType.isMarkedForDeletion); - - return resDeskType; + let desks = origDesks.filter((desk) => + selectedRooms.some((room) => { + return room.roomId === desk.roomId; }) ); - const desks = promises.flat(); const filteredDesks: IDesk[] = desks .filter((desk) => desk.bookings.length === 0) .filter((desk) => !desk.isMarkedForDeletion); + setDesks(filteredDesks); stopFetchingAnimation(); } @@ -440,7 +396,7 @@ const ResourceOverview = ({ const doDeleteRoom = async (): Promise => { if (room) { if (session == null) return; - let result = await deleteRoom(session, room.roomName); + let result = await deleteRoom(session, room.roomId); if (result.response == ResourceResponse.Success) { toast.success(result.message); @@ -782,10 +738,16 @@ export const getServerSideProps: GetServerSideProps = async (context) => { try { const buildings = await getBuildings(session); + const floors = await getFloors(session); + const rooms = await getRooms(session); + const desks = await getDesks(session); const deskTypes = await getDeskTypes(session); return { props: { buildings, + floors, + rooms, + desks, deskTypes, }, }; diff --git a/src/deskstar-frontend/types/floor.ts b/src/deskstar-frontend/types/floor.ts index 45f0f5b2..62bdc188 100644 --- a/src/deskstar-frontend/types/floor.ts +++ b/src/deskstar-frontend/types/floor.ts @@ -1,6 +1,7 @@ export interface IFloor { floorId: string; floorName: string; + buildingId: string; buildingName: string; location: string; isMarkedForDeletion: boolean; diff --git a/src/deskstar-frontend/types/room.ts b/src/deskstar-frontend/types/room.ts index add8be99..a412c365 100644 --- a/src/deskstar-frontend/types/room.ts +++ b/src/deskstar-frontend/types/room.ts @@ -1,7 +1,9 @@ export interface IRoom { roomId: string; roomName: string; + buildingId: string; building: string; + floorId: string; floor: string; location: string; isMarkedForDeletion: boolean;