feat: platform backbone and field capture complete (checkpoint)
Platform backbone (plan 2026-10-13-plattform-rueckgrat), all tasks reviewed: - webhooks with delivery table, retries and stable delivery id - calendar handlers; a finished task removes its Outlook event - tasks, automations, inspections, varroa, treatments, feedings, harvests, colonies, wintering, stock and bottling record domain events in the same transaction; legacy post-commit calls removed - row locks through one helper (lockRowForUpdate, lockRowsForShare, lockRowsForUpdate) - job framework with JobRun, cli exit codes, cleanup, task templates, daily evaluation, hourly app-backup and the rekey job - system API and page "Verwaltung > System" with retry - @nestjs/schedule removed, guard tests against in-process schedulers Field capture T3 (plan 2026-10-13-t3-erfassung-am-stand), all tasks reviewed: - inspection photo offline without metadata - bulk capture for treatments, feedings and varroa (backend + frontend) - offline stand mode with service worker, offline pages and packs - offline session, cold start and logout on shared devices Docs: ARCHITECTURE.md assumptions and sections updated, TASKS.md. Gates: backend lint, typecheck, 1770 unit, 420 e2e, build, no schema drift; frontend lint, typecheck, 913 tests, build. Not rolled out. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
c01a38835a
commit
cdd30cf3ee
288 files changed
+39165
-2853
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { Prisma } from '../../../generated/prisma';
|
||||
import { PrismaService } from '../../prisma/prisma.service';
|
||||
import { assertLivingColonies, LivingColony } from './assert-living-colonies';
|
||||
import { BulkCreateResult } from './bulk-create';
|
||||
import { BULK_TRANSACTION_TIMEOUT_MS } from './bulk-limits';
|
||||
|
||||
/**
|
||||
* Writes the record of one entry - record, audit entry and domain event,
|
||||
* all through `tx`. `colony` is the entry's colony as read under the share
|
||||
* lock; `bulkId` goes into the event payload.
|
||||
*/
|
||||
export type BulkEntryWork<E, T> = (
|
||||
tx: Prisma.TransactionClient,
|
||||
entry: E,
|
||||
colony: LivingColony,
|
||||
bulkId: string,
|
||||
) => Promise<T>;
|
||||
|
||||
/**
|
||||
* The frame of every bulk entry, all or none: one transaction with
|
||||
* BULK_TRANSACTION_TIMEOUT_MS, first assertLivingColonies for all colonies,
|
||||
* then `perEntry` once per entry in request order. The first failure rolls
|
||||
* back every record; the records come back in request order with a new
|
||||
* bulkId.
|
||||
*/
|
||||
export async function runBulk<E extends { colonyId: string }, T>(
|
||||
prisma: PrismaService,
|
||||
entries: readonly E[],
|
||||
perEntry: BulkEntryWork<E, T>,
|
||||
): Promise<BulkCreateResult<T>> {
|
||||
const bulkId = randomUUID();
|
||||
const records = await prisma.$transaction(
|
||||
async (tx) => {
|
||||
const colonies = await assertLivingColonies(
|
||||
tx,
|
||||
entries.map((entry) => entry.colonyId),
|
||||
);
|
||||
const created: T[] = [];
|
||||
for (const entry of entries) {
|
||||
// Every requested id is in the map - assertLivingColonies threw
|
||||
// otherwise.
|
||||
const colony = colonies.get(entry.colonyId)!;
|
||||
created.push(await perEntry(tx, entry, colony, bulkId));
|
||||
}
|
||||
return created;
|
||||
},
|
||||
{ timeout: BULK_TRANSACTION_TIMEOUT_MS },
|
||||
);
|
||||
return { bulkId, records };
|
||||
}
|
||||
Reference in new issue
Block a user