Skip to content

Commit

Permalink
fix: actually void at midnight
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Sep 6, 2024
1 parent 38c1f1c commit a7315e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/hour_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function completeHourLog(email: string, isVoid: boolean): Promise<{
where: { id: log.id },
data: {
time_out: new Date(),
state: 'complete',
state: isVoid ? 'cancelled' : 'complete',
duration: new Prisma.Decimal(isVoid ? 0 : duration)
}
})
Expand Down
29 changes: 23 additions & 6 deletions src/tasks/midnight.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Prisma } from '@prisma/client'
import schedule from 'node-schedule'
import logger from '~lib/logger'
import prisma from '~lib/prisma'
import { slack_client } from '~slack'
import responses from '~slack/blocks/responses'
Expand All @@ -13,13 +15,28 @@ export function setupAutoLogout() {
select: { time_in: true, Member: { select: { slack_id: true } } }
})
for (const log of loggedIn) {
const slack_id = log.Member.slack_id
if (slack_id) {
await slack_client.chat.postMessage({
...responses.autoSignoutDM({ slack_id, time_in: log.time_in }),
channel: log.Member.slack_id
})
try {
const slack_id = log.Member.slack_id
if (slack_id) {
await slack_client.chat.postMessage({
...responses.autoSignoutDM({ slack_id, time_in: log.time_in }),
channel: log.Member.slack_id
})
}
} catch (e) {
logger.warn(e)
}
}
await prisma.hourLog.updateMany({
where: {
state: 'pending',
type: 'lab'
},
data: {
state: 'cancelled',
time_out: new Date(),
duration: new Prisma.Decimal(0)
}
})
})
}

0 comments on commit a7315e2

Please sign in to comment.