feat(gehege): Reinigungszyklus (Maße, Kapazität, letzte/nächste Reinigung)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -261,6 +261,22 @@ export async function installMockApi(page: Page): Promise<MockDb> {
|
||||
return json(route, 405)
|
||||
}
|
||||
if (path.match(/^\/enclosure-photos\/[^/]+$/) && method === 'DELETE') return json(route, 204)
|
||||
// Gehege-Reinigungszyklus: nächste fällige Reinigung = letzte Reinigung + Zyklus (Tage).
|
||||
const nextCleaning = (lastCleaned?: string | null, cycleDays?: number | null): string | null => {
|
||||
if (!lastCleaned || cycleDays == null || cycleDays <= 0) return null
|
||||
const d = new Date(`${lastCleaned}T00:00:00Z`)
|
||||
d.setUTCDate(d.getUTCDate() + cycleDays)
|
||||
return d.toISOString().slice(0, 10)
|
||||
}
|
||||
// "Als gereinigt markieren": setzt letzte Reinigung auf heute (wie das echte Backend).
|
||||
m = path.match(/^\/enclosures\/([^/]+)\/mark-cleaned$/)
|
||||
if (m && method === 'POST') {
|
||||
const enc = db.enclosures.find((x) => x.id === m![1])
|
||||
if (!enc) return json(route, 404, { title: 'Not Found' })
|
||||
enc.lastCleanedDate = new Date().toISOString().slice(0, 10)
|
||||
enc.nextCleaningDate = nextCleaning(enc.lastCleanedDate, enc.cleaningCycleDays)
|
||||
return json(route, 200, enc)
|
||||
}
|
||||
m = path.match(/^\/gerbils\/([^/]+)\/inbreeding-coefficient$/)
|
||||
if (m) {
|
||||
const isKruemel = m[1] === 'kruemel'
|
||||
@@ -427,6 +443,13 @@ export async function installMockApi(page: Page): Promise<MockDb> {
|
||||
if (method === 'POST') {
|
||||
const body = request.postDataJSON() as Row
|
||||
const created = { id: newId(col.idPrefix), ...body }
|
||||
// Gehege: berechnetes Feld nextCleaningDate wie das echte Backend ableiten.
|
||||
if (m[1] === 'enclosures') {
|
||||
created.nextCleaningDate = nextCleaning(
|
||||
created.lastCleanedDate as string | null,
|
||||
created.cleaningCycleDays as number | null,
|
||||
)
|
||||
}
|
||||
col.rows.push(created)
|
||||
return json(route, 201, created)
|
||||
}
|
||||
@@ -440,6 +463,12 @@ export async function installMockApi(page: Page): Promise<MockDb> {
|
||||
if (method === 'PUT') {
|
||||
if (idx < 0) return json(route, 404, { title: 'Not Found' })
|
||||
Object.assign(col.rows[idx], request.postDataJSON() as Row)
|
||||
if (m[1] === 'enclosures') {
|
||||
col.rows[idx].nextCleaningDate = nextCleaning(
|
||||
col.rows[idx].lastCleanedDate as string | null,
|
||||
col.rows[idx].cleaningCycleDays as number | null,
|
||||
)
|
||||
}
|
||||
return json(route, 200, col.rows[idx])
|
||||
}
|
||||
if (method === 'DELETE') {
|
||||
|
||||
Reference in New Issue
Block a user