M2: the full job lifecycle — chat, hiring, geocoding, quotes, bookings, reviews
Closes the funnel. Before this the product could match two people and then stopped: `quotes`, `bookings` and `reviews` had tables and state machines and nothing that wrote a row, the entry deck's right swipe was wired to an empty handler, and every address resolved to the city centre. Jobs tab and chat - message router: thread, send, markRead, unreadTotal. A thread is a MATCH, not a job — one job with three interested pros is three private conversations. - Current/Past segments derived from ACTIVE_JOB_STATUSES, job detail listing the pros who accepted, and the conversation itself with attachments. Hiring from the deck - A right swipe on the entry deck opened nothing. It now resolves "which job?" through a sheet — sign in, pick an open job, or post one — and calls the same deck.swipe the per-job deck does, so the open-request cap and row lock apply exactly once. Swipes are vetoable so closing the sheet returns the card. Geocoding - ST_Distance and ST_DWithin rank and filter every deck, and both operands were placeholders. Addresses now resolve through Mapbox (permanent=true, which is what licenses storing the coordinates), the server resolves points rather than trusting client-supplied lat/lng, and every stored point records how it was obtained. A `city`-precision base cannot reach the verification queue. Quote -> booking -> review - The commercial chain, minus payments. Accepting a quote is the only place a booking is created; confirming completion is what unlocks reviews and moves the pro's completed_jobs. - Reviews publish double-blind with no sweeper: each is written with published_at already set to its embargo deadline and every read filters published_at <= now(), so it publishes itself. The second review pulls both forward. A silent counterparty cannot bury a bad review by never replying. State machine changes, both deliberate - booked -> matched: a cancelled booking is not a cancelled job. - scheduled -> awaiting_confirmation: in_progress is optional, so a pro who never tapped Start can still say the work is done. Test suite - api tests ran files in parallel against one database and failed roughly one run in three on whichever file lost the race. Serialised, and three fixtures that grabbed "the first client" pinned to the seeded accounts. Also includes work from a parallel session: admin verification queue, pro public profile and reviews read path, notification sending, denormalised stats recompute, search, and observability. 318 tests passing; typecheck and lint clean across 7 packages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,35 @@ type Graph<T extends string> = Readonly<Record<T, readonly T[]>>;
|
||||
export const JOB_STATUSES = ['open', 'matched', 'booked', 'completed', 'cancelled'] as const;
|
||||
export type JobStatus = (typeof JOB_STATUSES)[number];
|
||||
|
||||
/**
|
||||
* The live half of the job lifecycle.
|
||||
*
|
||||
* "Is this job happening or is it history?" is asked by the jobs list, the
|
||||
* counts on it and the chat composer, so the answer is defined once here rather
|
||||
* than as three copies of the same status array.
|
||||
*/
|
||||
export const ACTIVE_JOB_STATUSES: readonly JobStatus[] = ['open', 'matched', 'booked'];
|
||||
export const PAST_JOB_STATUSES: readonly JobStatus[] = ['completed', 'cancelled'];
|
||||
|
||||
/**
|
||||
* How a stored coordinate was obtained.
|
||||
*
|
||||
* Not a status — nothing transitions between these — but it lives here with the
|
||||
* other unions because the DB enum is generated from it (schema/enums.ts) and a
|
||||
* value that exists in one place and not the other is the bug this file exists
|
||||
* to prevent.
|
||||
*
|
||||
* `exact` a geocoded street address. Safe to rank on.
|
||||
* `approximate` a street, postcode or device GPS fix. Real, but not a rooftop.
|
||||
* `city` nothing resolved; the point is the city centre. A placeholder,
|
||||
* and labelled as one so no surface can mistake it for a location.
|
||||
*/
|
||||
export const LOCATION_PRECISIONS = ['exact', 'approximate', 'city'] as const;
|
||||
export type LocationPrecision = (typeof LOCATION_PRECISIONS)[number];
|
||||
|
||||
/** Points good enough to measure distance from. */
|
||||
export const LOCATABLE_PRECISIONS: readonly LocationPrecision[] = ['exact', 'approximate'];
|
||||
|
||||
export const REQUEST_STATUSES = ['pending', 'accepted', 'declined', 'expired'] as const;
|
||||
export type RequestStatus = (typeof REQUEST_STATUSES)[number];
|
||||
|
||||
@@ -58,7 +87,11 @@ export type VerificationStatus = (typeof VERIFICATION_STATUSES)[number];
|
||||
const JOB_GRAPH: Graph<JobStatus> = {
|
||||
open: ['matched', 'cancelled'],
|
||||
matched: ['booked', 'open', 'cancelled'], // back to `open` when every match falls through
|
||||
booked: ['completed', 'cancelled'],
|
||||
// 'matched' because a cancelled booking is not a cancelled job: the customer
|
||||
// still wants the work and their other conversations are untouched, so the job
|
||||
// goes back to the market rather than dying with the slot. Same spirit as
|
||||
// 'matched -> open' above.
|
||||
booked: ['completed', 'cancelled', 'matched'],
|
||||
completed: [],
|
||||
cancelled: [],
|
||||
};
|
||||
@@ -79,7 +112,11 @@ const QUOTE_GRAPH: Graph<QuoteStatus> = {
|
||||
};
|
||||
|
||||
const BOOKING_GRAPH: Graph<BookingStatus> = {
|
||||
scheduled: ['in_progress', 'cancelled'],
|
||||
// 'awaiting_confirmation' directly, because `in_progress` is optional.
|
||||
// Marking a job started is useful to a customer waiting for someone to turn
|
||||
// up, but a twenty-minute job finished by a pro who never tapped Start is the
|
||||
// common case, and being unable to say it is done would be absurd.
|
||||
scheduled: ['in_progress', 'awaiting_confirmation', 'cancelled'],
|
||||
in_progress: ['awaiting_confirmation', 'cancelled', 'disputed'],
|
||||
awaiting_confirmation: ['completed', 'disputed'],
|
||||
completed: ['disputed'], // a dispute can still be raised inside the window
|
||||
|
||||
Reference in New Issue
Block a user