Public: anyone can read this; the crew can change it.
An inspection or walkthrough less than two hours from another of the agent's appointments or closings on the same day is flagged, so the agent never double-books the day #196
mason/deal-clock:mason/192-an-inspection-or-walkthrough-less-than-t → main 4 commits fork
13 files
changed +297
−19
README.md +1 −1
| @@ -104,7 +104,7 @@ you already have), fix a typo with Edit, add a date the contract added (an HOA | ||
| 104 | 104 | review), waive a contingency the buyer gave up, change who owes a date, correct |
| 105 | 105 | the address, and set the closing time and place. If two of your open deals close the same day less than two hours apart, |
| 106 | 106 | an amber "Also closing at 2:30 pm" line names the other deal on This week, on |
| 107 | both deals' pages and in the terminal's deal view. An Inspection or Final | |
| 107 | both deals' pages and in the terminal's deal view; an inspection, walkthrough or closing less than two hours from another of your timed appointments that day gets an "Also at 10:00 am: Inspection, 12 Elm St" line the same way. An Inspection or Final | |
| 108 | 108 | walkthrough row has **Set time and place** too (a time on a quarter hour and |
| 109 | 109 | one line for where, either optional; clear both to remove them): the buyer |
| 110 | 110 | sees them beside the date on the client timeline, your calendar file gives |
contract/openapi.json +64
| @@ -1211,6 +1211,38 @@ | ||
| 1211 | 1211 | "format": "date" |
| 1212 | 1212 | } |
| 1213 | 1213 | } |
| 1214 | }, | |
| 1215 | "clashes": { | |
| 1216 | "type": "array", | |
| 1217 | "description": "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.", | |
| 1218 | "items": { | |
| 1219 | "type": "object", | |
| 1220 | "properties": { | |
| 1221 | "dealId": { | |
| 1222 | "type": "integer" | |
| 1223 | }, | |
| 1224 | "address": { | |
| 1225 | "type": "string" | |
| 1226 | }, | |
| 1227 | "label": { | |
| 1228 | "type": "string" | |
| 1229 | }, | |
| 1230 | "time": { | |
| 1231 | "type": [ | |
| 1232 | "string", | |
| 1233 | "null" | |
| 1234 | ], | |
| 1235 | "pattern": "^(0[7-9]|1[0-9]):(00|15|30|45)$|^20:00$", | |
| 1236 | "description": "When it closes, HH:MM on a quarter hour from 07:00 to 20:00, local time; null while none is set." | |
| 1237 | } | |
| 1238 | }, | |
| 1239 | "required": [ | |
| 1240 | "dealId", | |
| 1241 | "address", | |
| 1242 | "label", | |
| 1243 | "time" | |
| 1244 | ] | |
| 1245 | } | |
| 1214 | 1246 | } |
| 1215 | 1247 | } |
| 1216 | 1248 | } |
| @@ -3422,6 +3454,38 @@ | ||
| 3422 | 3454 | "format": "date" |
| 3423 | 3455 | } |
| 3424 | 3456 | } |
| 3457 | }, | |
| 3458 | "clashes": { | |
| 3459 | "type": "array", | |
| 3460 | "description": "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.", | |
| 3461 | "items": { | |
| 3462 | "type": "object", | |
| 3463 | "properties": { | |
| 3464 | "dealId": { | |
| 3465 | "type": "integer" | |
| 3466 | }, | |
| 3467 | "address": { | |
| 3468 | "type": "string" | |
| 3469 | }, | |
| 3470 | "label": { | |
| 3471 | "type": "string" | |
| 3472 | }, | |
| 3473 | "time": { | |
| 3474 | "type": [ | |
| 3475 | "string", | |
| 3476 | "null" | |
| 3477 | ], | |
| 3478 | "pattern": "^(0[7-9]|1[0-9]):(00|15|30|45)$|^20:00$", | |
| 3479 | "description": "When it closes, HH:MM on a quarter hour from 07:00 to 20:00, local time; null while none is set." | |
| 3480 | } | |
| 3481 | }, | |
| 3482 | "required": [ | |
| 3483 | "dealId", | |
| 3484 | "address", | |
| 3485 | "label", | |
| 3486 | "time" | |
| 3487 | ] | |
| 3488 | } | |
| 3425 | 3489 | } |
| 3426 | 3490 | } |
| 3427 | 3491 | } |
docs/TECHNICAL.md +2
| @@ -365,6 +365,8 @@ The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or | ||
| 365 | 365 | |
| 366 | 366 | `closingConflicts` on a deal (`GET /api/deals/:id` and the list) lists the agent's other open deals closing the same day, both with a time set, less than two hours apart: `{dealId, address, closing_time}`. `src/overlap.ts` computes it in memory over the deals already loaded; it is empty for a closed or fallen-through deal, a deal with no time, and deals of another agent. |
| 367 | 367 | |
| 368 | Each date in a deal's `deadlines` carries `clashes`: the agent's other open, timed inspections, walkthroughs and closings the same day, less than two hours from this date's own time (`{dealId, address, label, time}`, label being Inspection, Walkthrough or Closing). Only pairs with at least one inspection or walkthrough appear here; two closings stay in `closingConflicts`. `appointmentClashes` in `src/overlap.ts` computes it over the deals already loaded. | |
| 369 | ||
| 368 | 370 | `deal.closing_time` (`HH:MM`, a quarter hour, 07:00 to 20:00) and `deal.closing_place` (1 to 200 |
| 369 | 371 | characters) are nullable columns, read and written as `closing_time` and `closing_place` by |
| 370 | 372 | `GET`/`PATCH /api/deals/:id`, the `update_closing` tool and `POST /deals/:id/closing`; `src/closing.ts` |
src/clash.test.ts added +102
| @@ -0,0 +1,102 @@ | ||
| 1 | /** An inspection or walkthrough less than two hours from another timed appointment or closing of the agent's: flagged, escaped, linked. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { openDb } from "./db.ts"; | |
| 7 | import { createDeal, getDeal, listDeals, markDone, setAppointment } from "./deals.ts"; | |
| 8 | import { appointmentClashes } from "./overlap.ts"; | |
| 9 | import { dealPage } from "./pages/deal.ts"; | |
| 10 | import { weekCard } from "./pages/clock.ts"; | |
| 11 | import { weekPage } from "./pages/week.ts"; | |
| 12 | import type { Who } from "./who.ts"; | |
| 13 | ||
| 14 | type D = { id: number; kind: string; label: string; due: string; time: string | null; done_at: string | null; waived_at: string | null }; | |
| 15 | const date = (id: number, kind: string, time: string | null, over: Partial<D> = {}): D => ({ id, kind, label: "Inspection period ends", due: "2026-11-20", time, done_at: null, waived_at: null, ...over }); | |
| 16 | const deal = (id: number, deadlines: D[], over: Record<string, unknown> = {}) => ({ | |
| 17 | id, address: `${id} Way`, author_id: "u1", closing: "2026-11-30", closing_time: null, closed: false, fell_through: false, deadlines, ...over, | |
| 18 | }); | |
| 19 | const ids = (m: Map<number, { dealId: number }[]>, k: number) => m.get(k)?.map((c) => c.dealId); | |
| 20 | ||
| 21 | test("inspection vs inspection: 90 minutes flagged, two hours not", () => { | |
| 22 | const got = appointmentClashes([deal(1, [date(11, "inspection", "10:00")]), deal(2, [date(21, "inspection", "11:30")])]); | |
| 23 | expect(ids(got, 11)).toEqual([2]); | |
| 24 | expect(ids(got, 21)).toEqual([1]); | |
| 25 | expect(appointmentClashes([deal(1, [date(11, "inspection", "10:00")]), deal(2, [date(21, "inspection", "12:00")])]).size).toBe(0); | |
| 26 | }); | |
| 27 | ||
| 28 | test("an inspection against a closing the same day is flagged both ways; two closings are left to closingConflicts", () => { | |
| 29 | const closing = date(31, "closing", null, { label: "Closing", due: "2026-11-20" }); | |
| 30 | const got = appointmentClashes([deal(1, [date(11, "walkthrough", "09:00")]), deal(3, [closing], { closing: "2026-11-20", closing_time: "10:00" })]); | |
| 31 | expect(ids(got, 11)).toEqual([3]); | |
| 32 | expect(got.get(11)?.[0]).toMatchObject({ label: "Closing", time: "10:00" }); | |
| 33 | expect(ids(got, 31)).toEqual([1]); | |
| 34 | const two = appointmentClashes([deal(3, [closing], { closing: "2026-11-20", closing_time: "10:00" }), deal(4, [{ ...closing, id: 41 }], { closing: "2026-11-20", closing_time: "10:30" })]); | |
| 35 | expect(two.size).toBe(0); | |
| 36 | }); | |
| 37 | ||
| 38 | test("done, waived, untimed, other-day, closed, fallen and another agent's dates are not compared", () => { | |
| 39 | const base = deal(1, [date(11, "inspection", "10:00")]); | |
| 40 | const against = (d: D, over: Record<string, unknown> = {}) => appointmentClashes([base, deal(2, [d], over)]).size; | |
| 41 | expect(against(date(21, "inspection", "10:30"))).toBe(2); | |
| 42 | expect(against(date(21, "inspection", "10:30", { done_at: "2026-11-20T10:00:00Z" }))).toBe(0); | |
| 43 | expect(against(date(21, "inspection", "10:30", { waived_at: "2026-11-19T10:00:00Z" }))).toBe(0); | |
| 44 | expect(against(date(21, "inspection", null))).toBe(0); | |
| 45 | expect(against(date(21, "inspection", "10:30", { due: "2026-11-21" }))).toBe(0); | |
| 46 | expect(against(date(21, "inspection", "10:30"), { closed: true })).toBe(0); | |
| 47 | expect(against(date(21, "inspection", "10:30"), { fell_through: true })).toBe(0); | |
| 48 | expect(against(date(21, "inspection", "10:30"), { author_id: "u2" })).toBe(0); | |
| 49 | }); | |
| 50 | ||
| 51 | const db = openDb(mkdtempSync(join(tmpdir(), "app-clash-"))); | |
| 52 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 53 | const bob: Who = { role: "user", id: "u2", name: "bob" }; | |
| 54 | const agent = { name: "Dana", brokerage: "Harbor", phone: "555", email: "[email protected]" }; | |
| 55 | const open = (who: Who, address: string) => { | |
| 56 | const made = createDeal(db, who, { address, buyer: "Ann Buyer", seller: "Sam Seller", contractDate: "2026-10-01", closingDate: "2026-11-30", openAnyway: true }); | |
| 57 | if (!made.ok) throw new Error(made.message); | |
| 58 | return made.value; | |
| 59 | }; | |
| 60 | const all = (who: Who) => { const l = listDeals(db, who); if (!l.ok) throw new Error(l.message); return l.value; }; | |
| 61 | const inspection = (d: { deadlines: readonly { id: number; kind: string }[] }) => d.deadlines.find((x) => x.kind === "inspection")!; | |
| 62 | ||
| 63 | test("the week, the deal page and the read show the clash, escaped and linked, and another agent's never", () => { | |
| 64 | const a = open(alice, "1 <script>x</script> Way"); | |
| 65 | const b = open(alice, "2 Quiet Way"); | |
| 66 | const c = open(bob, "3 Bob Way"); | |
| 67 | const set = (who: Who, deal: { id: number; deadlines: readonly { id: number; kind: string }[] }, time: string) => { | |
| 68 | const r = setAppointment(db, who, { id: inspection(deal).id, time, place: "" }); | |
| 69 | if (!r.ok) throw new Error(r.message); | |
| 70 | }; | |
| 71 | const dueA = all(alice).find((d) => d.id === a.id)!.deadlines.find((d) => d.kind === "inspection")!.due; | |
| 72 | // Align the two inspections on one day, as the standard schedule may differ. | |
| 73 | for (const d of [b, c]) { | |
| 74 | const x = all(d === c ? bob : alice).find((v) => v.id === d.id)!; | |
| 75 | db.query("UPDATE deadline SET due = ?1 WHERE id = ?2").run(dueA, inspection(x).id); | |
| 76 | } | |
| 77 | set(alice, a, "10:00"); | |
| 78 | set(alice, b, "11:30"); | |
| 79 | set(bob, c, "10:30"); | |
| 80 | ||
| 81 | const mine = all(alice); | |
| 82 | const first = mine.find((d) => d.id === a.id)!; | |
| 83 | expect(inspection(first)).toMatchObject({ clashes: [{ dealId: b.id, address: "2 Quiet Way", label: "Inspection", time: "11:30" }] }); | |
| 84 | expect(inspection(mine.find((d) => d.id === c.id)!)).toMatchObject({ clashes: [] }); | |
| 85 | ||
| 86 | const sheet = weekPage({ who: alice, agent, deals: mine, on: dueA }); | |
| 87 | expect(sheet).toContain(`Also at 11:30 am: Inspection, <a href="/deals/${b.id}">2 Quiet Way</a>`); | |
| 88 | expect(weekCard(mine, dueA)).toContain("Also at 10:00 am: Inspection, 1 <script>x</script> Way"); | |
| 89 | expect(weekCard(mine, dueA)).not.toContain("<script>x"); | |
| 90 | ||
| 91 | const got = getDeal(db, alice, { id: b.id }); | |
| 92 | if (!got.ok) throw new Error(got.message); | |
| 93 | const page = dealPage({ who: alice, deal: got.value, agent, on: dueA } as never); | |
| 94 | expect(page).toContain(`Also at 10:00 am: Inspection, <a href="/deals/${a.id}">1 <script>x</script> Way</a>`); | |
| 95 | expect(page).not.toContain("<script>x"); | |
| 96 | ||
| 97 | // Done or waived clears it. | |
| 98 | const done = markDone(db, alice, { id: inspection(first).id, done: true }); | |
| 99 | expect(done.ok).toBe(true); | |
| 100 | const after = getDeal(db, alice, { id: b.id }); | |
| 101 | expect(after.ok && inspection(after.value)).toMatchObject({ clashes: [] }); | |
| 102 | }); |
src/deals.ts +18 −6
| @@ -40,7 +40,7 @@ import { outboxes } from "./outbox.ts"; | ||
| 40 | 40 | import { conflictLine, conflicts, type Conflict } from "./order.ts"; |
| 41 | 41 | import { SEND_SPAN, draftOfMoment, statusDrafts, type Agent, type Draft } from "./reminders.ts"; |
| 42 | 42 | import { audited, conflict, fail, ok, refuse, type Result } from "./result.ts"; |
| 43 | import { closingConflicts, type ClosingConflict } from "./overlap.ts"; | |
| 43 | import { appointmentClashes, closingConflicts, type Clash, type ClosingConflict } from "./overlap.ts"; | |
| 44 | 44 | import type { Who } from "./who.ts"; |
| 45 | 45 | |
| 46 | 46 | export interface Deal { |
| @@ -188,6 +188,8 @@ export interface DeadlineView extends Omit<Deadline, "owes_from" | "owes_by" | " | ||
| 188 | 188 | readonly moves: readonly Move[]; |
| 189 | 189 | /** An open date due on a weekend or US federal holiday: the business day it rolls to. Null otherwise. */ |
| 190 | 190 | readonly nonBusinessDay: { readonly next: string } | null; |
| 191 | /** Other timed appointments or closings of this agent the same day, less than two hours from this timed one; empty when none. */ | |
| 192 | readonly clashes: readonly Clash[]; | |
| 191 | 193 | } |
| 192 | 194 | /** The day the Closing date was marked done, by the app's own calendar (the one `today()` keeps). */ |
| 193 | 195 | export const closedOn = (deal: { zone: string; deadlines: readonly { kind: Kind; done_at: string | null }[]; closing: string }): string => { |
| @@ -308,6 +310,7 @@ function assemble(deal: Deal, rows: Children, zone: string): DealView { | ||
| 308 | 310 | owes_changed: owes_from === null || owes_by === null || owes_on === null ? null : { from: owes_from, by: owes_by, on: owes_on }, |
| 309 | 311 | moves: moves.filter((m) => m.deadline_id === d.id), |
| 310 | 312 | nonBusinessDay: isOpen(d) && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null, |
| 313 | clashes: [], | |
| 311 | 314 | })), |
| 312 | 315 | sent: rows.sent.map((m) => withHref(m, rows.parties, zone)), |
| 313 | 316 | declined: rows.declined, |
| @@ -319,9 +322,19 @@ function assemble(deal: Deal, rows: Children, zone: string): DealView { | ||
| 319 | 322 | |
| 320 | 323 | /** The deal with the closings of its agent's other deals it overlaps; one read, and only for a timed, open closing. */ |
| 321 | 324 | function withClosingConflicts(db: Database, deal: DealView): DealView { |
| 322 | if (deal.closing_time === null || deal.closed || deal.fell_through) return deal; | |
| 325 | if (deal.closed || deal.fell_through) return deal; | |
| 326 | if (deal.closing_time === null && !deal.deadlines.some((d) => d.time !== null)) return deal; | |
| 323 | 327 | const peers = viewMany(db, " WHERE author_id = ?1", [deal.author_id]); |
| 324 | return { ...deal, closingConflicts: closingConflicts(peers).get(deal.id) ?? [] }; | |
| 328 | return withClashes([deal], closingConflicts(peers), appointmentClashes(peers))[0]!; | |
| 329 | } | |
| 330 | ||
| 331 | /** The deals with the closing conflicts and the appointment clashes read off the loaded set. */ | |
| 332 | function withClashes(deals: readonly DealView[], closings: Map<number, ClosingConflict[]>, clashes: Map<number, Clash[]>): DealView[] { | |
| 333 | return deals.map((d) => ({ | |
| 334 | ...d, | |
| 335 | closingConflicts: closings.get(d.id) ?? [], | |
| 336 | deadlines: d.deadlines.map((x) => (clashes.has(x.id) ? { ...x, clashes: clashes.get(x.id)! } : x)), | |
| 337 | })); | |
| 325 | 338 | } |
| 326 | 339 | |
| 327 | 340 | function view(db: Database, deal: Deal): DealView { |
| @@ -447,10 +460,9 @@ export function listDeals(db: Database, who: Who): Result<DealView[]> { | ||
| 447 | 460 | ` WHERE ${may.where.map((c) => `${c} = ?1`).join(" OR ")}`, |
| 448 | 461 | [who.role === "anon" ? "" : who.id], |
| 449 | 462 | ); |
| 450 | const clashes = closingConflicts(deals); | |
| 451 | 463 | return ok( |
| 452 | deals | |
| 453 | .map((d) => shown(who, { ...d, closingConflicts: clashes.get(d.id) ?? [] })) | |
| 464 | withClashes(deals, closingConflicts(deals), appointmentClashes(deals)) | |
| 465 | .map((d) => shown(who, d)) | |
| 454 | 466 | .sort((a, b) => a.closing.localeCompare(b.closing) || a.id - b.id), |
| 455 | 467 | ); |
| 456 | 468 | } |
src/overlap.ts +83
| @@ -6,7 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { clock12 } from "./closing.ts"; |
| 9 | import { isOpen } from "./deadlines.ts"; | |
| 9 | 10 | import { escape } from "./http.ts"; |
| 11 | import { isAppointment } from "./appointment.ts"; | |
| 10 | 12 | |
| 11 | 13 | /** Two closings closer than this many minutes cannot both be kept. */ |
| 12 | 14 | export const APART = 120; |
| @@ -62,3 +64,84 @@ export function clashLine(conflicts: readonly ClosingConflict[], tag: "p" | "sma | ||
| 62 | 64 | const links = conflicts.map((c) => (linked ? `<a href="/deals/${c.dealId}">${escape(c.address)}</a>` : escape(c.address))).join(", "); |
| 63 | 65 | return `<${tag} class="closing-clash">Also closing at ${escape(clock12(first.closing_time))}: ${links}</${tag}>`; |
| 64 | 66 | } |
| 67 | ||
| 68 | /** Another timed date of the same agent (label is the kind: Inspection, Walkthrough or Closing), the same day, less than `APART` minutes from this one. */ | |
| 69 | export interface Clash { | |
| 70 | readonly dealId: number; | |
| 71 | readonly address: string; | |
| 72 | readonly label: string; | |
| 73 | readonly time: string; | |
| 74 | } | |
| 75 | ||
| 76 | interface Booked { | |
| 77 | readonly id: number; | |
| 78 | readonly address: string; | |
| 79 | readonly author_id: string; | |
| 80 | readonly closing: string; | |
| 81 | readonly closing_time: string | null; | |
| 82 | readonly closed: boolean; | |
| 83 | readonly fell_through: boolean; | |
| 84 | readonly deadlines: readonly { | |
| 85 | readonly id: number; | |
| 86 | readonly kind: string; | |
| 87 | readonly label: string; | |
| 88 | readonly due: string; | |
| 89 | readonly time: string | null; | |
| 90 | readonly done_at: string | null; | |
| 91 | readonly waived_at: string | null; | |
| 92 | }[]; | |
| 93 | } | |
| 94 | ||
| 95 | interface Slot { | |
| 96 | readonly deadlineId: number; | |
| 97 | readonly dealId: number; | |
| 98 | readonly address: string; | |
| 99 | readonly label: string; | |
| 100 | readonly kind: string; | |
| 101 | readonly day: string; | |
| 102 | readonly time: string; | |
| 103 | readonly author: string; | |
| 104 | } | |
| 105 | ||
| 106 | /** | |
| 107 | * For each deadline id that has one, the other timed appointments or closings of the | |
| 108 | * same agent the same day, less than `APART` minutes away. Only pairs with at least | |
| 109 | * one inspection or walkthrough: two closings are `closingConflicts`. Done, waived, | |
| 110 | * untimed dates and closed or fallen-through deals are never compared. | |
| 111 | */ | |
| 112 | export function appointmentClashes(deals: readonly Booked[]): Map<number, Clash[]> { | |
| 113 | const byDay = new Map<string, Slot[]>(); | |
| 114 | for (const deal of deals) { | |
| 115 | if (deal.closed || deal.fell_through) continue; | |
| 116 | for (const d of deal.deadlines) { | |
| 117 | const closing = d.kind === "closing"; | |
| 118 | const time = closing ? deal.closing_time : d.time; | |
| 119 | if (time === null || !(closing || isAppointment(d.kind)) || !isOpen(d)) continue; | |
| 120 | const day = closing ? deal.closing : d.due; | |
| 121 | const key = `${deal.author_id}|${day}`; | |
| 122 | const slot: Slot = { deadlineId: d.id, dealId: deal.id, address: deal.address, label: d.kind[0]!.toUpperCase() + d.kind.slice(1), kind: d.kind, day, time, author: deal.author_id }; | |
| 123 | byDay.set(key, [...(byDay.get(key) ?? []), slot]); | |
| 124 | } | |
| 125 | } | |
| 126 | const out = new Map<number, Clash[]>(); | |
| 127 | for (const slots of byDay.values()) { | |
| 128 | for (const a of slots) { | |
| 129 | const near = slots | |
| 130 | .filter((b) => b.deadlineId !== a.deadlineId && (a.kind !== "closing" || b.kind !== "closing") && Math.abs(minutes(b.time) - minutes(a.time)) < APART) | |
| 131 | .sort((x, y) => x.time.localeCompare(y.time) || x.deadlineId - y.deadlineId) | |
| 132 | .map((b) => ({ dealId: b.dealId, address: b.address, label: b.label, time: b.time })); | |
| 133 | if (near.length > 0) out.set(a.deadlineId, near); | |
| 134 | } | |
| 135 | } | |
| 136 | return out; | |
| 137 | } | |
| 138 | ||
| 139 | /** "Also at 10:00 am: Inspection, 12 Elm St", each address linked to its deal; "" for none. */ | |
| 140 | export function clashesLine(clashes: readonly Clash[], tag: "p" | "small" = "p", linked = true): string { | |
| 141 | if (clashes.length === 0) return ""; | |
| 142 | const items = clashes.map((c, i) => { | |
| 143 | const where = linked ? `<a href="/deals/${c.dealId}">${escape(c.address)}</a>` : escape(c.address); | |
| 144 | return `${i === 0 ? "Also" : "also"} at ${escape(clock12(c.time))}: ${escape(c.label)}, ${where}`; | |
| 145 | }); | |
| 146 | return `<${tag} class="closing-clash">${items.join("; ")}</${tag}>`; | |
| 147 | } |
src/pages/appointment.ts +2 −1
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | * that says them and the small form that sets them. Escaped here, once. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | import { clashesLine } from "../overlap.ts"; | |
| 6 | 7 | import { appointmentLine, isAppointment } from "../appointment.ts"; |
| 7 | 8 | import type { DeadlineView } from "../deals.ts"; |
| 8 | 9 | import { escape } from "../http.ts"; |
| @@ -17,7 +18,7 @@ export interface AppointmentProblem { | ||
| 17 | 18 | |
| 18 | 19 | /** "10:00 am · 12 Elm St" under the date; nothing when unset or when the date is no appointment. */ |
| 19 | 20 | export const appointmentText = (d: DeadlineView): string => |
| 20 | appointmentLine(d) === "" ? "" : `<p class="small appointment"><b>${escape(appointmentLine(d))}</b></p>`; | |
| 21 | (appointmentLine(d) === "" ? "" : `<p class="small appointment"><b>${escape(appointmentLine(d))}</b></p>`) + clashesLine(d.clashes); | |
| 21 | 22 | |
| 22 | 23 | /** "Set time and place" for an inspection or a walkthrough; the form stays open, with the agent's text, when it was refused. */ |
| 23 | 24 | export function appointmentForm(d: DeadlineView, to: string, problem: AppointmentProblem | undefined): string { |
src/pages/clock.ts +3 −3
| @@ -12,8 +12,8 @@ import { escape } from "../http.ts"; | ||
| 12 | 12 | import { agent as defaults } from "../env.ts"; |
| 13 | 13 | import { todaysDrafts, unsent, type Agent } from "../reminders.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { clashLine } from "../overlap.ts"; | |
| 16 | import { byDay, closingNote, thisWeek } from "../week.ts"; | |
| 15 | import { clashLine, clashesLine } from "../overlap.ts"; | |
| 16 | import { byDay, thisWeek, whereNote } from "../week.ts"; | |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | import { mayRestore } from "../actions.ts"; |
| 19 | 19 | import { badge, draftLink, opens, owedBy, URGENCY_LABEL } from "./sheet.ts"; |
| @@ -111,7 +111,7 @@ export function weekCard(deals: readonly DealView[], on: string, q = "", side: S | ||
| 111 | 111 | (g) => `<h3 class="week-day">${escape(g.heading)}</h3> |
| 112 | 112 | <ul class="week-list">${g.items |
| 113 | 113 | .map(({ deal, deadline: d }) => |
| 114 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${closingNote(deal, d) === "" ? "" : ` · ${escape(closingNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`), | |
| 114 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${whereNote(deal, d) === "" ? "" : ` · ${escape(whereNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${clashesLine(d.clashes, "small", false)}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`), | |
| 115 | 115 | ) |
| 116 | 116 | .join("")}</ul>`, |
| 117 | 117 | ) |
src/pages/deal.ts +2 −2
| @@ -11,7 +11,7 @@ import { agent as defaults, standard } from "../env.ts"; | ||
| 11 | 11 | import { CONTACT_ROLES, DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, suggestedFor } from "../deadlines.ts"; |
| 12 | 12 | import { escape } from "../http.ts"; |
| 13 | 13 | import { coming, comingLine, type Coming } from "../coming.ts"; |
| 14 | import { clashLine } from "../overlap.ts"; | |
| 14 | import { clashLine, clashesLine } from "../overlap.ts"; | |
| 15 | 15 | import { closingLine } from "../closing.ts"; |
| 16 | 16 | import { commission, dollars, percent } from "../money.ts"; |
| 17 | 17 | import { anniversaryDrafts, checkinDrafts, drafts, pending, sentLabel, statusDrafts, type Agent } from "../reminders.ts"; |
| @@ -206,7 +206,7 @@ export interface ClosingProblem { | ||
| 206 | 206 | |
| 207 | 207 | /** The closing line, said in the one way: "Closing Nov 21 · 2:00 pm · Lakeside Title"; nothing for a time and place unset beyond the day the page already says. */ |
| 208 | 208 | function closingWhenLine(deal: DealView): string { |
| 209 | return (deal.closing_time === null && deal.closing_place === null ? "" : `<p class="summary" id="closing-when"><b>${escape(closingLine(deal))}</b></p>`) + clashLine(deal.closingConflicts); | |
| 209 | return (deal.closing_time === null && deal.closing_place === null ? "" : `<p class="summary" id="closing-when"><b>${escape(closingLine(deal))}</b></p>`) + clashLine(deal.closingConflicts) + clashesLine(deal.deadlines.find((d) => d.kind === "closing")?.clashes ?? []); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function closingForm(deal: DealView, path: string, problem: ClosingProblem | undefined): string { |
src/pages/week.ts +4 −6
| @@ -12,16 +12,14 @@ import { agent as defaults } from "../env.ts"; | ||
| 12 | 12 | import { asset, escape } from "../http.ts"; |
| 13 | 13 | import { STATUS } from "../timeline.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { appointmentNote, byDay, closingNote, owner, thisWeek } from "../week.ts"; | |
| 16 | import { clashLine } from "../overlap.ts"; | |
| 15 | import { byDay, owner, whereNote, thisWeek } from "../week.ts"; | |
| 16 | import { clashLine, clashesLine } from "../overlap.ts"; | |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | import { sideLabel } from "./side.ts"; |
| 19 | 19 | import type { SideFilter } from "../side.ts"; |
| 20 | 20 | |
| 21 | 21 | const closingAt = (deal: DealView, d: DealView["deadlines"][number]): string => { |
| 22 | const where = closingNote(deal, d); | |
| 23 | const appt = appointmentNote(d); | |
| 24 | const text = where === "" ? appt : where; | |
| 22 | const text = whereNote(deal, d); | |
| 25 | 23 | return text === "" ? "" : ` · ${escape(text)}`; |
| 26 | 24 | }; |
| 27 | 25 | |
| @@ -47,7 +45,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re | ||
| 47 | 45 | <p class="timeline-date">${escape(deal.address)} · ${sideLabel(deal.side)}</p> |
| 48 | 46 | <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p> |
| 49 | 47 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p> |
| 50 | ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""} | |
| 48 | ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""}${clashesLine(d.clashes)} | |
| 51 | 49 | ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`} |
| 52 | 50 | <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p> |
| 53 | 51 | </li>`; |
src/routes.ts +9
| @@ -345,6 +345,15 @@ export const DEAL: Schema = { | ||
| 345 | 345 | description: "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.", |
| 346 | 346 | properties: { next: DATE }, |
| 347 | 347 | }, |
| 348 | clashes: { | |
| 349 | type: "array", | |
| 350 | description: "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.", | |
| 351 | items: { | |
| 352 | type: "object", | |
| 353 | properties: { dealId: { type: "integer" }, address: { type: "string" }, label: { type: "string" }, time: CLOSING_TIME }, | |
| 354 | required: ["dealId", "address", "label", "time"], | |
| 355 | }, | |
| 356 | }, | |
| 348 | 357 | }, |
| 349 | 358 | }, |
| 350 | 359 | }, |
src/upgrade.test.ts +1
| @@ -110,6 +110,7 @@ async function boots(list: string[], n: number, name: string) { | ||
| 110 | 110 | } |
| 111 | 111 | expect(shape(check), `schema at version ${n} differs from a fresh database`).toEqual(wanted); |
| 112 | 112 | check.close(); |
| 113 | expect((await get("/healthz")).status, `/healthz at version ${n}`).toBe(200); | |
| 113 | 114 | const pages = ["/", "/people"]; |
| 114 | 115 | if (hadDeal) pages.push("/deals/1", "/deals/1/timeline"); |
| 115 | 116 | for (const path of pages) { |
src/week.ts +6
| @@ -39,6 +39,12 @@ export function closingNote(deal: WeekDeal<unknown>, d: { kind?: string }): stri | ||
| 39 | 39 | return d.kind === "closing" ? closingWhere({ closing_time: deal.closing_time ?? null, closing_place: deal.closing_place ?? null }) : ""; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | /** The time and place after a row's label: the closing's, or an inspection's or walkthrough's; "" when there is none. */ | |
| 43 | export function whereNote(deal: WeekDeal<unknown>, d: { kind: string; time?: string | null; place?: string | null }): string { | |
| 44 | const where = closingNote(deal, d); | |
| 45 | return where === "" ? appointmentNote(d) : where; | |
| 46 | } | |
| 47 | ||
| 42 | 48 | export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>( |
| 43 | 49 | deals: readonly Deal[], |
| 44 | 50 | on: string, |
new above
offline