Skip to content

timeentry list/export: bad ?from / ?to dates cause 500 instead of the documented silent-drop #310

@CryptoJones

Description

@CryptoJones

Both listByCompany and exportCsv in app/controllers/timeentrycontroller.js declare in a doc comment that "bad dates are silently dropped rather than 400'd." The implementation doesn't match: the raw req.query.from / req.query.to string is plugged straight into Sequelize's Op.gte / Op.lte.

Postgres parses ISO 8601 fine but throws invalid input syntax for type timestamp on garbage like ?from=not-a-date, which Sequelize surfaces. The controller's catch returns a 500.

So GET /v1/timeentry/bycompany/1?from=garbage returns 500 instead of "treat as no filter" as documented.

Fix: add a parseDateOrNull(s) helper that returns a Date for valid inputs and null otherwise. Wire both handlers through it. Unit-test via the _internals export.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions