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
@@ -16,6 +16,17 @@ interface FeedingSummaryEntry {
|
||||
totalAmount: number;
|
||||
}
|
||||
|
||||
interface BulkFeedingBody {
|
||||
bulkId: string;
|
||||
records: (FeedingBody & {
|
||||
feedType: string;
|
||||
amount: number;
|
||||
unit: string;
|
||||
batchNumber: string | null;
|
||||
userId: string;
|
||||
})[];
|
||||
}
|
||||
|
||||
describe('Feedings (e2e)', () => {
|
||||
let app: INestApplication<App>;
|
||||
let prisma: PrismaService;
|
||||
@@ -71,6 +82,15 @@ describe('Feedings (e2e)', () => {
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
const feedingIds = (
|
||||
await prisma.feeding.findMany({
|
||||
where: { colonyId },
|
||||
select: { id: true },
|
||||
})
|
||||
).map((feeding) => feeding.id);
|
||||
await prisma.domainEvent.deleteMany({
|
||||
where: { aggregateType: 'Feeding', aggregateId: { in: feedingIds } },
|
||||
});
|
||||
await prisma.feeding.deleteMany({ where: { colonyId } });
|
||||
await prisma.colony.deleteMany({ where: { id: colonyId } });
|
||||
await prisma.apiary.deleteMany({ where: { id: apiaryId } });
|
||||
@@ -116,6 +136,48 @@ describe('Feedings (e2e)', () => {
|
||||
expect(feedingId).toEqual(expect.any(String));
|
||||
});
|
||||
|
||||
it('wrote the audit entry and FeedingRecorded together with the feeding', async () => {
|
||||
expect(
|
||||
await prisma.auditLog.count({
|
||||
where: {
|
||||
entityType: 'Feeding',
|
||||
entityId: feedingId,
|
||||
action: 'CREATE',
|
||||
userId: staffId,
|
||||
},
|
||||
}),
|
||||
).toBe(1);
|
||||
const events = await prisma.domainEvent.findMany({
|
||||
where: { aggregateType: 'Feeding', aggregateId: feedingId },
|
||||
});
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: 'FeedingRecorded',
|
||||
actorUserId: staffId,
|
||||
payload: { colonyId },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('records FeedingCorrected on an edit', async () => {
|
||||
await request(app.getHttpServer())
|
||||
.patch(`/api/v1/feedings/${feedingId}`)
|
||||
.set('Authorization', `Bearer ${staffToken}`)
|
||||
.send({ notes: 'korrigiert' })
|
||||
.expect(200);
|
||||
|
||||
const corrections = await prisma.domainEvent.findMany({
|
||||
where: {
|
||||
aggregateType: 'Feeding',
|
||||
aggregateId: feedingId,
|
||||
type: 'FeedingCorrected',
|
||||
},
|
||||
});
|
||||
expect(corrections).toHaveLength(1);
|
||||
expect(corrections[0].payload).toEqual({ colonyId });
|
||||
});
|
||||
|
||||
it('lists feedings for the colony', async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.get(`/api/v1/colonies/${colonyId}/feedings`)
|
||||
@@ -134,4 +196,128 @@ describe('Feedings (e2e)', () => {
|
||||
const litersEntry = summary.find((entry) => entry.unit === 'l');
|
||||
expect(litersEntry?.totalAmount).toBe(2.5);
|
||||
});
|
||||
|
||||
describe('POST /feedings/bulk', () => {
|
||||
const suffix = Date.now();
|
||||
const shared = {
|
||||
date: '2026-09-01',
|
||||
feedType: 'FEED_SYRUP',
|
||||
product: 'Apiinvert',
|
||||
amount: 10,
|
||||
unit: 'kg',
|
||||
batchNumber: 'L-2026-09',
|
||||
};
|
||||
let bulkColonyIds: string[];
|
||||
let endedColonyId: string;
|
||||
|
||||
const postBulk = (token: string, body: object) =>
|
||||
request(app.getHttpServer())
|
||||
.post('/api/v1/feedings/bulk')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.send(body);
|
||||
|
||||
const storedFeedings = () =>
|
||||
prisma.feeding.count({
|
||||
where: { colonyId: { in: [...bulkColonyIds, endedColonyId] } },
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
const colonyAt = async (
|
||||
code: string,
|
||||
status: 'ACTIVE' | 'SOLD' = 'ACTIVE',
|
||||
) =>
|
||||
(
|
||||
await prisma.colony.create({
|
||||
data: {
|
||||
code: `${code}-${suffix}`,
|
||||
apiaryId,
|
||||
colonyType: 'PRODUCTION_COLONY',
|
||||
status,
|
||||
},
|
||||
})
|
||||
).id;
|
||||
bulkColonyIds = [await colonyAt('FB-1'), await colonyAt('FB-2')];
|
||||
endedColonyId = await colonyAt('FB-X', 'SOLD');
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
const colonyIds = [...bulkColonyIds, endedColonyId];
|
||||
const feedingIds = (
|
||||
await prisma.feeding.findMany({
|
||||
where: { colonyId: { in: colonyIds } },
|
||||
select: { id: true },
|
||||
})
|
||||
).map((feeding) => feeding.id);
|
||||
await prisma.domainEvent.deleteMany({
|
||||
where: { aggregateType: 'Feeding', aggregateId: { in: feedingIds } },
|
||||
});
|
||||
await prisma.feeding.deleteMany({
|
||||
where: { colonyId: { in: colonyIds } },
|
||||
});
|
||||
await prisma.colony.deleteMany({ where: { id: { in: colonyIds } } });
|
||||
});
|
||||
|
||||
it('bulk creates one feeding per colony with the shared fields', async () => {
|
||||
const response = await postBulk(staffToken, {
|
||||
...shared,
|
||||
colonyIds: bulkColonyIds,
|
||||
}).expect(201);
|
||||
|
||||
const { bulkId, records } = response.body as BulkFeedingBody;
|
||||
expect(records.map((record) => record.colonyId)).toEqual(bulkColonyIds);
|
||||
for (const record of records) {
|
||||
expect(record).toEqual(
|
||||
expect.objectContaining({
|
||||
feedType: 'FEED_SYRUP',
|
||||
amount: 10,
|
||||
unit: 'kg',
|
||||
batchNumber: 'L-2026-09',
|
||||
userId: staffId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
await prisma.domainEvent.count({
|
||||
where: {
|
||||
type: 'FeedingRecorded',
|
||||
payload: { path: ['bulkId'], equals: bulkId },
|
||||
},
|
||||
}),
|
||||
).toBe(2);
|
||||
expect(
|
||||
await prisma.auditLog.count({
|
||||
where: {
|
||||
entityType: 'Feeding',
|
||||
action: 'CREATE',
|
||||
entityId: { in: records.map((record) => record.id) },
|
||||
},
|
||||
}),
|
||||
).toBe(2);
|
||||
});
|
||||
|
||||
it('bulk rejects the whole batch when one colony has ended and names it', async () => {
|
||||
const before = await storedFeedings();
|
||||
|
||||
const response = await postBulk(staffToken, {
|
||||
...shared,
|
||||
colonyIds: [...bulkColonyIds, endedColonyId],
|
||||
}).expect(400);
|
||||
|
||||
expect(
|
||||
(response.body as { invalidColonyIds: string[] }).invalidColonyIds,
|
||||
).toEqual([endedColonyId]);
|
||||
expect(await storedFeedings()).toBe(before);
|
||||
});
|
||||
|
||||
it('bulk rejects a duplicate colony', () =>
|
||||
postBulk(staffToken, {
|
||||
...shared,
|
||||
colonyIds: [bulkColonyIds[0], bulkColonyIds[0]],
|
||||
}).expect(400));
|
||||
|
||||
it('bulk rejects a role without feedings:create', () =>
|
||||
postBulk(readonlyToken, { ...shared, colonyIds: bulkColonyIds }).expect(
|
||||
403,
|
||||
));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user