1
0
Fork 0
polaris-task-force/src/collections/operations/OperationEffects.ts
Z8MB1E acf47a75ea feat(operations): gate logistics extractions behind an officer review screen
Logistics operation-extraction effects now park as pending_action instead of auto-settling. Officers visit Operations > Extractions to keep, scrap, or expel each line; only kept lines deposit into HQ. A capacity failure leaves the effect retryable (pending_action) so a full HQ can free space and re-resolve. Adds resolveLogisticsExtraction/listPendingExtractions actions + ExtractionReview UI + tests.
2026-10-26 22:20:14 -04:00

120 lines
No EOL
3.4 KiB
TypeScript

import type { CollectionConfig } from "payload";
/**
* Derived-effect ledger for validated operation events.
*
* One row per (event, effect type) pair, keyed by `effectKey` =
* `${eventId}:${effectType}` so an exact retry is a no-op. Effects are the
* only place derived operation state may be recorded; they always carry
* provenance back to both the operation event and the raw source event.
*
* Writes are internal only (create/update/delete denied; the bridge writes
* via `overrideAccess`). Read is open to any logged-in user.
*/
export const OperationEffects: CollectionConfig = {
slug: "operation-effects",
admin: {
group: "Operations",
useAsTitle: "effectKey",
defaultColumns: ["effectKey", "operationId", "effectType", "status", "appliedAt"],
},
access: {
read: ({ req }) => !!req.user,
create: () => false,
update: () => false,
delete: () => false,
},
fields: [
{
name: "operationEvent",
type: "relationship",
relationTo: "operation-events",
required: true,
index: true,
admin: {
description: "The validated operation event this effect derives from.",
},
},
{
name: "sourceEvent",
type: "relationship",
relationTo: "arma-sync-events",
required: true,
index: true,
admin: {
description: "The raw source event this effect derives from.",
},
},
{
name: "operationId",
type: "text",
required: true,
index: true,
},
{
name: "effectKey",
type: "text",
required: true,
unique: true,
index: true,
admin: {
description: "Idempotency key: `${eventId}:${effectType}`.",
},
},
{
name: "effectType",
type: "select",
required: true,
options: [
{ label: "Operation Started", value: "operation.started" },
{ label: "Operation Ended", value: "operation.ended" },
{ label: "Objective Updated", value: "operation.objective-updated" },
{ label: "Extraction Recorded", value: "operation.extraction-recorded" },
{ label: "Inventory Recorded", value: "operation.inventory-recorded" },
],
},
{
name: "status",
type: "select",
required: true,
defaultValue: "applied",
options: [
{ label: "Applied", value: "applied" },
{ label: "Pending", value: "pending" },
{
label: "Awaiting Action",
value: "pending_action",
},
{ label: "Failed", value: "failed" },
{ label: "Reversed", value: "reversed" },
],
},
{
name: "decisions",
type: "json",
admin: {
description:
"Per-item officer resolution for a gated extraction: [{ relationTo, id, decision }]. decision is keep (deposit), scrap, or expel (hold back). Absent = not yet reviewed.",
},
},
{ name: "payload", type: "json" },
{
name: "reversalOf",
type: "relationship",
relationTo: "operation-effects",
admin: {
description: "Set when this effect reverses another effect.",
},
},
{
name: "reversedBy",
type: "relationship",
relationTo: "operation-effects",
admin: {
description: "Set when this effect has been reversed.",
},
},
{ name: "reconciliationNotes", type: "textarea" },
{ name: "appliedAt", type: "date" },
],
};