From 206d9dda2f4b98545a4d583511e050971da1be3e Mon Sep 17 00:00:00 2001 From: Pavel Baluev Date: Wed, 29 May 2024 13:53:26 +0200 Subject: [PATCH] Fix office occupancy stats queries --- config-demo/company.json | 7 +------ docs/create-new-office.md | 5 ----- src/modules/visits/server/router.ts | 2 ++ src/server/app-config/schemas.ts | 5 ----- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/config-demo/company.json b/config-demo/company.json index 25ffe0e4..8ddfcbfd 100644 --- a/config-demo/company.json +++ b/config-demo/company.json @@ -29,12 +29,7 @@ "visitsConfig": { "workingDays": [0, 1, 2, 3, 4], "bookableDays": 30, - "maxCapacity": 35, - "capacityThresholds": { - "low": 5, - "medium": 14, - "high": 27 - } + "maxCapacity": 35 }, "areas": [ { diff --git a/docs/create-new-office.md b/docs/create-new-office.md index e2033c94..c5dca35a 100644 --- a/docs/create-new-office.md +++ b/docs/create-new-office.md @@ -19,11 +19,6 @@ Open the `app.config.json` file and scroll down to the `offices` section. This s "workingDays": [0, 1, 2, 3, 4], // Mon-Fri "bookableDays": 30, // how many days in advance are allowed to book "maxCapacity": 35, // maximum office capacity (including non-working desks) - "capacityThresholds": { // only for stats - "low": 5, - "medium": 20, - "high": 30 - } }, "areas": [ { diff --git a/src/modules/visits/server/router.ts b/src/modules/visits/server/router.ts index 3773afca..ec0ac574 100644 --- a/src/modules/visits/server/router.ts +++ b/src/modules/visits/server/router.ts @@ -733,6 +733,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => { result.visitsTotal = await fastify.db.Visit.count({ where: { + officeId: office.id, date: { [Op.gte]: startDate, [Op.lte]: endDate, @@ -741,6 +742,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => { }) result.visitsToday = await fastify.db.Visit.count({ where: { + officeId: office.id, date: { [Op.gte]: dayjs().startOf('day').toDate(), [Op.lte]: dayjs().endOf('day').toDate(), diff --git a/src/server/app-config/schemas.ts b/src/server/app-config/schemas.ts index 9df69b9f..4e81f3dd 100644 --- a/src/server/app-config/schemas.ts +++ b/src/server/app-config/schemas.ts @@ -43,11 +43,6 @@ export const officeVisitsConfig = z.object({ workingDays: z.array(z.number().min(0).max(6)).min(1).max(7), bookableDays: z.number().min(1), maxCapacity: z.number().min(1), - capacityThresholds: z.object({ - low: z.number().min(1), - medium: z.number().min(1), - high: z.number().min(1), - }), }) export const officeAreaDesk = z