Over the last four sections, you built each piece of Dev’s ticket API one lesson at a time: Express routes, an endpoint table, IDs and filters, a store that keeps every ticket safe, and a router per resource. Now Dev wants the whole thing ready for next month’s repair café, plus a few rules the desk asked for after last Saturday.
This project gives you a brief instead of a walkthrough. You’ll read what Dev needs, write the endpoint table for what’s new before you write any route, and then build the API from a fresh project in steps that the next three exercises grade one at a time. Start with Dev’s brief.
Read Dev’s Brief
Dev wrote down what the sign-in desk needs from the API. Most of it is what your project already does:
- Tickets: Available at
/ticketsand/tickets/:id. The desk lists them, logs a new one withPOST(a201with aLocationheader), looks one up, changes its status withPATCH, and deletes a ticket logged by mistake withDELETE(a204). - Four statuses: Only
waiting,on-bench,fixed, andcant-fix. - Filters: Applied to the list, such as
?status=waiting&category=electrical, with the sorting and paging you added. - No lost tickets: Everything is saved to
tickets.json, even when two volunteers log a ticket at the same moment. - Volunteers: A second resource, at
/volunteers, in a router of its own.
Three more rules are new, and you haven’t implemented them in a lesson yet. Each one is made from pieces you already have, so the work is deciding how they fit.
A ?visitor= filter. When Priya comes back to collect her toaster, the desk asks for /tickets?visitor=Priya and gets only her tickets. The filter matches a ticket’s name exactly, as status and category match theirs, combines with them, and gets the same 400 when it’s repeated or empty.
Closed tickets stay closed. A ticket that’s fixed or cant-fix has left the bench, so a PATCH that tries to change its status gets 409 Conflict, in the API’s error shape, with the code ticket_closed.
The body is fine, since the same body would get a 200 on a waiting ticket. The API refuses the request because of the ticket’s current state, and 409 is the status for a conflict with a resource’s current state.
The body checks come first, so a bad body still gets its 400, 415, or 422. Next, an unknown ID gets its 404. Only then does a closed ticket get its 409.
Watch where the closed-ticket check runs. Your store’s .update() finds a ticket and changes it with no await in between, so no other request can run in the middle. A route could instead read the ticket with store.get(), check it, and then call store.update().