feat(tier): Erwerb/Kauf je Tier (Datum, Preis, Notiz)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -416,6 +416,50 @@ export async function installMockApi(page: Page): Promise<MockDb> {
|
||||
return json(route, 405)
|
||||
}
|
||||
|
||||
// ERWERB: Erwerb/Kauf je Tier — GET ?gerbilId= (Array, kein Gridify-Paging),
|
||||
// POST/PUT/DELETE. Vor den generischen Kollektionen, weil GET kein {items}-Objekt
|
||||
// liefert und nach gerbilId statt Gridify-filter selektiert.
|
||||
const acqMatch = path.match(/^\/acquisitions(?:\/([^/]+))?$/)
|
||||
if (acqMatch) {
|
||||
const acqId = acqMatch[1] ? decodeURIComponent(acqMatch[1]) : null
|
||||
if (!acqId) {
|
||||
if (method === 'GET') {
|
||||
const gid = url.searchParams.get('gerbilId')
|
||||
const rows = db.acquisitions.filter((a) => !gid || a.gerbilId === gid)
|
||||
return json(route, 200, [...rows].reverse())
|
||||
}
|
||||
if (method === 'POST') {
|
||||
const created = {
|
||||
id: newId('acq'),
|
||||
sourceContactId: null,
|
||||
date: null,
|
||||
price: null,
|
||||
note: null,
|
||||
...(request.postDataJSON() as Row),
|
||||
createdAt: new Date().toISOString(),
|
||||
}
|
||||
db.acquisitions.push(created)
|
||||
return json(route, 201, created)
|
||||
}
|
||||
return json(route, 405)
|
||||
}
|
||||
const ai = db.acquisitions.findIndex((a) => a.id === acqId)
|
||||
if (method === 'GET') {
|
||||
return ai >= 0 ? json(route, 200, db.acquisitions[ai]) : json(route, 404, { title: 'Not Found' })
|
||||
}
|
||||
if (method === 'PUT') {
|
||||
if (ai < 0) return json(route, 404, { title: 'Not Found' })
|
||||
Object.assign(db.acquisitions[ai], request.postDataJSON() as Row)
|
||||
return json(route, 204)
|
||||
}
|
||||
if (method === 'DELETE') {
|
||||
if (ai < 0) return json(route, 404, { title: 'Not Found' })
|
||||
db.acquisitions.splice(ai, 1)
|
||||
return json(route, 204)
|
||||
}
|
||||
return json(route, 405)
|
||||
}
|
||||
|
||||
// Generische Kollektionen: /<resource> und /<resource>/<id>
|
||||
m = path.match(/^\/([a-z-]+)(?:\/([^/]+))?$/)
|
||||
const col = m ? collections[m[1]] : undefined
|
||||
|
||||
Reference in New Issue
Block a user