unit(D3): slot materialization (headcount, call time)
Slot materialization (ARCHITECTURE §5.2): for each non-published instance, plan the seats planSlots() computes and upsert them on (service_instance_id, role_id, slot_index). onConflictDoNothing makes it idempotent; published weeks are skipped (owned by the publish flow). - src/domain/slots.ts: pure planSlots()/planSlotsForRole(); headcount fills slotIndex 1..N, call_time = start + offset (null if no offset). - src/domain/slots.test.ts: 5 tests (Audio headcount 2 -> 2 slots with correct call_time, clamp to 1, null offset, multi-role flatten). - src/db/slots.ts: materializeSlotsForInstance() + materializeSlots(). - src/app/api/dev/cron/slots/route.ts: GET drives the daily job. No schema change (slots unique index predates this unit; position_skills stays deferred to D5). Verified: draft instance + Audio headcount 2 -> 4 seats (Audio x2 + Livestream + Slides), Audio call_time 09:30 EST; re-run creates 0 rows. Seed restored to canonical 4 instances / 12 slots after testing.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { materializeSlots } from "@/db/slots";
|
||||
|
||||
/**
|
||||
* Slot materialization (ARCHITECTURE §5.2). Drives `materializeSlots()` —
|
||||
* idempotent on (instance, role, seat). Re-runs create 0 rows.
|
||||
*
|
||||
* GET /api/dev/cron/slots
|
||||
*/
|
||||
export const GET = async () => {
|
||||
const result = await materializeSlots();
|
||||
return new Response(JSON.stringify({ result }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user