fix: rename on-time rate label, hoist getApiKey above escalation loop, remove broken capa-owner incident link

This commit is contained in:
2026-07-11 19:03:23 +08:00
parent 87264a5497
commit 871ef7c53a
3 changed files with 7 additions and 8 deletions
+5 -4
View File
@@ -45,6 +45,9 @@ export async function escalateOverdueCapa(
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000'
let notified = 0
const whatsappPhoneNumberId = await getApiKey(supabase, 'META_WHATSAPP_PHONE_NUMBER_ID')
const whatsappAccessToken = await getApiKey(supabase, 'META_WHATSAPP_ACCESS_TOKEN')
for (const capa of capas) {
const threshold = getEscalationThreshold((capa as { due_date: string }).due_date)
if (!threshold) continue
@@ -98,14 +101,12 @@ export async function escalateOverdueCapa(
const ownerPhone = (capa.owner as unknown as { phone: string | null } | null)?.phone ?? ''
if (ownerPhone) {
try {
const phoneNumberId = await getApiKey(supabase, 'META_WHATSAPP_PHONE_NUMBER_ID')
const accessToken = await getApiKey(supabase, 'META_WHATSAPP_ACCESS_TOKEN')
await sendWhatsAppMessage(
ownerPhone,
'ims_capa_overdue',
[incidentRef, (capa as { description: string }).description, (capa as { due_date: string }).due_date],
phoneNumberId,
accessToken,
whatsappPhoneNumberId,
whatsappAccessToken,
)
} catch (waErr) {
console.error('WhatsApp escalation error:', waErr)