Skip to content

Commit

Permalink
rebase fix: updated getting meeting rooms according to new config
Browse files Browse the repository at this point in the history
  • Loading branch information
piggydoughnut committed Feb 20, 2024
1 parent 1360004 commit fc33ee1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/modules/room-reservation/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
})
const reservedRooms = reservations.map((room) => room.roomId)

return (getRooms(office) || []).filter((room) => {
return getRooms(req.office).filter((room) => {
if (!room) {
return false
}
Expand Down Expand Up @@ -355,7 +355,9 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
}
const requestedDuration = req.query.duration ?? 30
const office = req.office
const room = office.rooms!.find((room) => room.id === req.params.roomId)
const room = getRooms(office).find(
(room) => room?.id === req.params.roomId
)
if (!room || !room.available) {
return reply.throw.badParams('Invalid room ID')
}
Expand Down Expand Up @@ -463,7 +465,7 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
const office = req.office
let earliestStart: Array<string> = []
let latestEnd: Array<string> = []
const rooms = (office.rooms || []).filter((room) => room.available)
const rooms = getRooms(office).filter((room) => room?.available)
rooms.forEach((room) => {
const [workingHoursStart, workingHoursEnd] = room.workingHours.map(
(time) => time.split(':')
Expand Down Expand Up @@ -574,11 +576,11 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
) => {
req.check(Permissions.Create)
if (req.office) {
const rooms = req.office.rooms || []
const rooms = getRooms(req.office)
return req.query.allRooms ? rooms : rooms.filter((x) => x.available)
}
const rooms = appConfig.offices
.map((x) => x.rooms)
.map((x) => getRooms(x))
.flat()
.filter(Boolean)
return req.query.allRooms ? rooms : rooms.filter((x) => x?.available)
Expand All @@ -599,7 +601,9 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
return reply.throw.badParams('Invalid office ID')
}
req.check(Permissions.Create, req.office.id)
const room = req.office.rooms!.find((x) => x.id === req.params.roomId)
const room = getRooms(req.office)!.find(
(x) => x?.id === req.params.roomId
)
if (!room || !room.available) {
return reply.throw.badParams('Invalid room ID')
}
Expand Down Expand Up @@ -635,7 +639,7 @@ const userRouter: FastifyPluginCallback = async function (fastify, opts) {
}
req.check(Permissions.Create, req.office.id)
const data = req.body
const room = (req.office.rooms || []).find((x) => x.id === data.roomId)
const room = getRooms(req.office).find((x) => x?.id === data.roomId)
if (!room || !room.available) {
return reply.throw.badParams('Invalid room ID')
}
Expand Down Expand Up @@ -980,7 +984,7 @@ const adminRouter: FastifyPluginCallback = async function (fastify, opts) {
return appConfig.offices
.filter((x) => (officeIds.length ? officeIds.includes(x.id) : true))
.reduce<OfficeRoomCompact[]>((acc, x) => {
const rooms = (x.rooms || []).map((r) => ({
const rooms = getRooms(x).map((r) => ({
id: r.id,
name: r.name,
officeId: x.id,
Expand Down

0 comments on commit fc33ee1

Please sign in to comment.