Skip to content

Commit

Permalink
feat: checkin by department instead of by manager
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Sep 14, 2024
1 parent 98ba68c commit 3075c80
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/slack/handlers/actions/checkin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Blocks, Elements, Message } from 'slack-block-builder'

Check warning on line 1 in src/slack/handlers/actions/checkin.ts

View workflow job for this annotation

GitHub Actions / Lint

'Elements' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 1 in src/slack/handlers/actions/checkin.ts

View workflow job for this annotation

GitHub Actions / Lint

'Elements' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 1 in src/slack/handlers/actions/checkin.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/slack/handlers/actions/checkin.ts#L1

[@typescript-eslint/no-unused-vars] 'Elements' is defined but never used. Allowed unused vars must match /^_/u.
import config from '~lib/config'
import logger from '~lib/logger'
import prisma from '~lib/prisma'
import { formatList } from '~slack/lib/messages'
import { EventMiddleware } from '~slack/lib/types'

export const handleAppMentioned: EventMiddleware<'app_mention'> = async ({ event, client }) => {
Expand All @@ -11,23 +13,54 @@ export const handleAppMentioned: EventMiddleware<'app_mention'> = async ({ event
name: 'stopwatch'
})
const user = await client.auth.test()
const managers = await prisma.member.findMany({ where: { MemberCerts: { some: { Cert: { isManager: true } } } } })
const copres_string = config.slack.users.copres.join(',')
for (const manager of managers) {
if (!manager.slack_id) {
logger.warn('No slack id for manager ' + manager.email)

const departments = await prisma.department.findMany({
select: {
name: true,
Certs: {
where: {
isManager: true
},
select: {
Instances: {
select: {
Member: {
select: {
email: true,
slack_id: true
}
}
}
}
}
}
}
})

const dept_managers = departments.map((dept) => ({
name: dept.name,
managers: dept.Certs.flatMap((cert) => cert.Instances.map((instance) => instance.Member.slack_id).filter((v) => v != null))
}))

for (const dept of dept_managers) {
if (dept.managers.length == 0) {
logger.warn('No manager slack ids for dept ' + dept.name)
continue
}
const dm = await client.conversations.open({
users: copres_string + ',' + manager.slack_id
users: [...config.slack.users.copres, ...dept.managers].join(',')
})
if (dm.channel?.id == null) {
logger.warn('No group dm for manager ' + manager.email)
logger.warn('No group dm for dept ' + dept.name)
continue
}
const text = event.text.replace('<@' + user.user_id! + '>', formatList(dept.managers.map((id) => '<@' + id + '>')))
await client.chat.postMessage({
channel: dm.channel!.id!,
text: event.text.replace(user.user_id!, manager.slack_id)
text,
blocks: Message()
.blocks(Blocks.Section().text(text), Blocks.Context().elements('Copresident Checkin for ' + dept.name))
.buildToObject().blocks
})
}
await client.reactions.remove({
Expand Down

0 comments on commit 3075c80

Please sign in to comment.