Skip to content

Commit

Permalink
Fix office occupancy stats to count confirmed visits only
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1uev committed May 29, 2024
1 parent 206d9dd commit 00745ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/modules/visits/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {

result.visitsTotal = await fastify.db.Visit.count({
where: {
status: 'confirmed',
officeId: office.id,
date: {
[Op.gte]: startDate,
Expand All @@ -742,6 +743,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {
})
result.visitsToday = await fastify.db.Visit.count({
where: {
status: 'confirmed',
officeId: office.id,
date: {
[Op.gte]: dayjs().startOf('day').toDate(),
Expand All @@ -752,6 +754,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {

result.topVisitors = (await fastify.db.Visit.findAll({
where: {
status: 'confirmed',
officeId: office.id,
date: {
[Op.gte]: startDate,
Expand Down Expand Up @@ -783,6 +786,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {

result.topDesks = (await fastify.db.Visit.findAll({
where: {
status: 'confirmed',
officeId: office.id,
date: {
[Op.gte]: startDate,
Expand All @@ -808,6 +812,7 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {
// TODO: check if startdate and enddate contains a year
result.annualVisits = (await fastify.db.Visit.findAll({
where: {
status: 'confirmed',
officeId: office.id,
date: {
[Op.gte]: startDate,
Expand Down Expand Up @@ -856,7 +861,10 @@ const adminRouter: FastifyPluginCallback = async (fastify, opts) => {
FROM
visits v
WHERE
v."officeId" = :officeId AND v."date" BETWEEN :startDate AND :endDate
1=1 AND
v."status" = 'confirmed' AND
v."officeId" = :officeId AND
v."date" BETWEEN :startDate AND :endDate
GROUP BY
to_char(v."date", :dateFormat)
) AS daily_stats
Expand Down
2 changes: 1 addition & 1 deletion src/server/app-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class AppConfig {
try {
this.unsafeLoad()
} catch (err) {
if (err instanceof AppError) {
if (config.env !== 'production' && err instanceof AppError) {
log.error(err)
this.error = err
} else {
Expand Down

0 comments on commit 00745ba

Please sign in to comment.