v1.27: Zaehleranlage ohne Haus-Feld, Ablesedatum Pflicht
This commit is contained in:
+5
-3
@@ -552,11 +552,13 @@ const ZAEHLER_ARTEN = ['Strom', 'Wasser', 'Gas', 'Wärme', 'Sonstiges']
|
||||
|
||||
app.post('/api/meters', auth, adminOnly, async (req, res, next) => {
|
||||
try {
|
||||
const { nummer, art, stand, unitId, building } = req.body || {}
|
||||
const { nummer, art, stand, unitId, building, standAm } = req.body || {}
|
||||
if (!String(nummer || '').trim()) return res.status(400).json({ fehler: 'Zählernummer fehlt.' })
|
||||
if (!ZAEHLER_ARTEN.includes(art)) return res.status(400).json({ fehler: 'Ungültige Zählerart.' })
|
||||
const standZahl = Number(stand)
|
||||
if (!Number.isFinite(standZahl) || standZahl < 0) return res.status(400).json({ fehler: 'Ungültiger Zählerstand.' })
|
||||
const datum = String(standAm || '').trim() || deutschesDatum()
|
||||
if (!zaehlerVerlauf.parseDatum(datum)) return res.status(400).json({ fehler: 'Ungültiges Ablesedatum.' })
|
||||
// Wohnung angegeben → Haus aus der Wohnung ableiten; sonst muss das Haus im Body stehen
|
||||
let einheitId = unitId ? String(unitId) : null
|
||||
let haus = String(building || '').trim()
|
||||
@@ -571,11 +573,11 @@ app.post('/api/meters', auth, adminOnly, async (req, res, next) => {
|
||||
const { rows } = await pool.query(
|
||||
`INSERT INTO meters (id, unit_id, building, nummer, art, stand, stand_am, geaendert_am)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING *`,
|
||||
[id, einheitId, haus, String(nummer).trim(), art, standZahl, deutschesDatum(), deutschesDatumZeit()],
|
||||
[id, einheitId, haus, String(nummer).trim(), art, standZahl, datum, deutschesDatumZeit()],
|
||||
)
|
||||
// Anfangsstand als erster Verlaufseintrag
|
||||
await zaehlerVerlauf.standEintragen({
|
||||
meter: rows[0], stand: standZahl, standAm: deutschesDatum(),
|
||||
meter: rows[0], stand: standZahl, standAm: datum,
|
||||
erfasstVon: req.user.name, quelle: 'erstbefund',
|
||||
})
|
||||
res.json({ meter: mapMeter(rows[0]) })
|
||||
|
||||
Reference in New Issue
Block a user