Skip to content

Commit

Permalink
Allow to configure the availability of office areas
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1uev committed Feb 6, 2024
1 parent efc19b9 commit cce94ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/modules/visits/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const userRouter: FastifyPluginCallback = async (fastify, opts) => {
`The ${req.office.name} office doesn't support desk reservation`
)
}
return reply.send(req.office.areas)
return reply.send(req.office.areas?.filter((x) => x.available) || [])
}
)

Expand Down Expand Up @@ -287,6 +287,12 @@ const userRouter: FastifyPluginCallback = async (fastify, opts) => {
`The ${office.name} office doesn't support desk reservation`
)
}
const availableAreaIds = office
.areas!.filter((x) => x.available)
.map((x) => x.id)
if (visits.some((x) => !availableAreaIds.includes(x.areaId))) {
return reply.throw.badParams('Request contains unavailable areas')
}

try {
await fastify.sequelize.transaction(async (t) => {
Expand Down Expand Up @@ -472,7 +478,8 @@ const userRouter: FastifyPluginCallback = async (fastify, opts) => {
)

const desks = req.office
.areas!.map((a) =>
.areas!.filter((a) => a.available)
.map((a) =>
a.desks.map((d) => ({
areaId: a.id,
deskId: d.id,
Expand Down
1 change: 1 addition & 0 deletions src/server/app-config/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const officeAreaDesk = z

export const officeArea = z.object({
id: z.string(),
available: z.boolean().default(true),
name: z.string(),
capacity: z.number().min(1),
map: z.string(),
Expand Down

0 comments on commit cce94ec

Please sign in to comment.