Add SETTINGS_URL/SECRET to compose, fix sync email-change and rate-limit bugs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-02 00:23:59 +00:00
parent f08d53d702
commit 42be29b2ce
4 changed files with 23 additions and 10 deletions

View file

@ -1,5 +1,5 @@
import { pool } from './db.js'
import { findEmployeeByEmail, getEmployeeDepartments, getSyncConfig } from './workforce.js'
import { findEmployeeById, findEmployeeByEmail, getEmployeeDepartments, getSyncConfig } from './workforce.js'
export async function syncAllWorkforceUsers() {
const { rows: users } = await pool.query(
@ -10,12 +10,13 @@ export async function syncAllWorkforceUsers() {
for (const user of users) {
try {
// Look up by email (Workforce doesn't reliably expose GET /users/:id)
// Use stored email first; if not found try to detect via workforce_user_id match in dept lists
const wfUser = await findEmployeeByEmail(user.email)
// Prefer ID lookup — survives email changes in Workforce.
// Fall back to email lookup if the API doesn't support GET /users/:id.
let wfUser = await findEmployeeById(user.workforce_user_id)
if (!wfUser) wfUser = await findEmployeeByEmail(user.email)
if (!wfUser || String(wfUser.id) !== user.workforce_user_id) {
// Not found or ID mismatch — deactivate
// Not found in Workforce — deactivate
await pool.query('UPDATE users SET active = false WHERE id = $1', [user.id])
deactivated++
continue