diff --git a/src/lib/hour_operations.ts b/src/lib/hour_operations.ts index 9ff84f2..cba52ce 100644 --- a/src/lib/hour_operations.ts +++ b/src/lib/hour_operations.ts @@ -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) } }) diff --git a/src/tasks/midnight.ts b/src/tasks/midnight.ts index 26cde2a..81b888c 100644 --- a/src/tasks/midnight.ts +++ b/src/tasks/midnight.ts @@ -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' @@ -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) + } + }) }) }