Booking backend project · Chapter 6 of 12

Admin: showtimes

By the end of this chapter you can let Asha schedule showtimes safely: work with moments in time (timestamptz, offsets, Date), check a showtime's prices against its screen's seat classes, find a clash with the one condition that catches every overlap, and cancel a showtime without stranding people who paid. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Running Parda
  • 3 tasks
  • TypeScript
  • In the all labs plan

The first 2 chapters of Booking backend project are free. This one comes with the all labs plan.

Why you need this

A showtime is what Parda actually sells: one show, on one screen, at one moment, with a price for every seat class. Asha plans each week's showtimes in a grid, and the grid has gone wrong in two ways. In September a play at Natya Ghar was put at 7:30 pm when a film still ran on that stage until 8:10 pm, and 140 people waited in the lobby. And a showtime at Rangdeep went on sale with a price for "Balcony", a class Rangdeep does not have, and none for its Back rows, so the site showed those seats for ₹0.

Chapter 5 gave Asha venues and shows. The admin routes for showtimes are there now too, given, and they call two services that do not exist yet. Both rules, "every class has a price" and "no two showtimes share a screen at once", are yours to write.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    prices.ts: every seat class priced, no stray class

    Write priceProblems(classes, prices) in prices.ts. classes is the screen's seat classes (a list of text, like Balcony, Front, Middle); prices is an object of class to rupees, as Asha sent it.

    Return a list of sentences, empty when the prices are right: first, for each class in classes that has no price, in the order of classes, "No price for Balcony"; then, for each key of prices that is not one of the classes, in the order of the keys, "The screen has no Gold seats".

    A price of 0 still counts as a price for its class (the amount is not this function's business). Do not change the list or the object you are given. The Check tries six cases, from right prices to two missing classes and two stray ones.

  2. Task 2 · interview question

    Interview: showtimes.service.ts, schedule a showtime in a free slot

    Write createShowtime(input) in showtimes.service.ts. input is { showId, screenId, startsAt, prices }, startsAt being a date and time with its offset, such as 2026-11-08T10:00:00+05:30.

    No show with that id, or no screen with that id: throw notFound with a sentence (404). Read the distinct seat classes of the screen's seats and ask priceProblems; when it finds problems, throw unprocessable('bad_prices', the problems joined with a semicolon and a space), a 422.

    The new showtime takes the screen from startsAt until endsAt, which is startsAt plus the show's minutes plus config.turnaroundMinutes (15). When another showtime on that screen, whose status is not cancelled, has a slot that overlaps this one, throw conflict('screen_busy', a sentence), a 409. Two slots overlap when each starts before the other ends; one that ends exactly when the next starts does not overlap it.

    Otherwise insert it and return the whole new row (endsAt included, status scheduled). The Check schedules The Last Show at Moti Mahal (109 minutes) on Kala Talkies' screen 1 at Sun 8 Nov 10:00 am and wants endsAt 12:04 pm, then tries a start inside Ghar Wapsi Express's slot (Fri 9:30 pm to 12:07 am), a slot around a show at The Attic, slots that touch others exactly, another screen, and the place of a cancelled showtime.

    Nikhil will ask: why is "each starts before the other ends" enough, and why not just check whether the new start falls inside an old slot?

  3. Task 3

    showtimes.service.ts: cancel a showtime

    Write cancelShowtime(id) in showtimes.service.ts. When the showtime has bookings whose status is confirmed (paid), throw conflict('showtime_has_bookings', a sentence), a 409, and leave it scheduled: those people are refunded first. Pending bookings do not stop it.

    Otherwise set its status to cancelled and return the whole updated row. No such showtime: throw notFound with a sentence (404). Only that showtime changes.

    The Check gives showtime 2 a confirmed booking and showtime 3 a pending one, then cancels both, then 999, then calls POST /admin/showtimes/5/cancel as Neha (403) and as Asha (200).

What you will learn

  • Moments in time: timestamptz in Postgres, offsets in requests, Date in TypeScript, and why text comparison of times is wrong.
  • Distinct values: Drizzle's selectDistinct.
  • Overlapping intervals: the one condition that finds every clash, and the tempting one that misses some.
  • Rules from the business: the cleaning turnaround, cancelled showtimes that no longer block, paid bookings that stop a cancel.

More in Running Parda

Build "Admin: showtimes" yourself

Parda sells tickets for Pune's own cinemas and stages. You build its booking API, one module a chapter, and take the whole codebase home. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Booking backend project are free. This one comes with the all labs plan.