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

Parked opened this
Closed without merging

mason/deal-clock:mason/192-an-inspection-or-walkthrough-less-than-t → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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
104104 review), waive a contingency the buyer gave up, change who owes a date, correct
105105 the address, and set the closing time and place. If two of your open deals close the same day less than two hours apart,
106106 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
108108 walkthrough row has **Set time and place** too (a time on a quarter hour and
109109 one line for where, either optional; clear both to remove them): the buyer
110110 sees them beside the date on the client timeline, your calendar file gives
contract/openapi.json +64
@@ -1211,6 +1211,38 @@
12111211 "format": "date"
12121212 }
12131213 }
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 }
12141246 }
12151247 }
12161248 }
@@ -3422,6 +3454,38 @@
34223454 "format": "date"
34233455 }
34243456 }
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 }
34253489 }
34263490 }
34273491 }
docs/TECHNICAL.md +2
@@ -365,6 +365,8 @@ The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or
365365
366366 `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.
367367
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
368370 `deal.closing_time` (`HH:MM`, a quarter hour, 07:00 to 20:00) and `deal.closing_place` (1 to 200
369371 characters) are nullable columns, read and written as `closing_time` and `closing_place` by
370372 `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 &lt;script&gt;x&lt;/script&gt; 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 &lt;script&gt;x&lt;/script&gt; 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";
4040 import { conflictLine, conflicts, type Conflict } from "./order.ts";
4141 import { SEND_SPAN, draftOfMoment, statusDrafts, type Agent, type Draft } from "./reminders.ts";
4242 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";
4444 import type { Who } from "./who.ts";
4545
4646 export interface Deal {
@@ -188,6 +188,8 @@ export interface DeadlineView extends Omit<Deadline, "owes_from" | "owes_by" | "
188188 readonly moves: readonly Move[];
189189 /** An open date due on a weekend or US federal holiday: the business day it rolls to. Null otherwise. */
190190 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[];
191193 }
192194 /** The day the Closing date was marked done, by the app's own calendar (the one `today()` keeps). */
193195 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 {
308310 owes_changed: owes_from === null || owes_by === null || owes_on === null ? null : { from: owes_from, by: owes_by, on: owes_on },
309311 moves: moves.filter((m) => m.deadline_id === d.id),
310312 nonBusinessDay: isOpen(d) && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null,
313 clashes: [],
311314 })),
312315 sent: rows.sent.map((m) => withHref(m, rows.parties, zone)),
313316 declined: rows.declined,
@@ -319,9 +322,19 @@ function assemble(deal: Deal, rows: Children, zone: string): DealView {
319322
320323 /** The deal with the closings of its agent's other deals it overlaps; one read, and only for a timed, open closing. */
321324 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;
323327 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 }));
325338 }
326339
327340 function view(db: Database, deal: Deal): DealView {
@@ -447,10 +460,9 @@ export function listDeals(db: Database, who: Who): Result<DealView[]> {
447460 ` WHERE ${may.where.map((c) => `${c} = ?1`).join(" OR ")}`,
448461 [who.role === "anon" ? "" : who.id],
449462 );
450 const clashes = closingConflicts(deals);
451463 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))
454466 .sort((a, b) => a.closing.localeCompare(b.closing) || a.id - b.id),
455467 );
456468 }
src/overlap.ts +83
@@ -6,7 +6,9 @@
66 */
77
88 import { clock12 } from "./closing.ts";
9 import { isOpen } from "./deadlines.ts";
910 import { escape } from "./http.ts";
11 import { isAppointment } from "./appointment.ts";
1012
1113 /** Two closings closer than this many minutes cannot both be kept. */
1214 export const APART = 120;
@@ -62,3 +64,84 @@ export function clashLine(conflicts: readonly ClosingConflict[], tag: "p" | "sma
6264 const links = conflicts.map((c) => (linked ? `<a href="/deals/${c.dealId}">${escape(c.address)}</a>` : escape(c.address))).join(", ");
6365 return `<${tag} class="closing-clash">Also closing at ${escape(clock12(first.closing_time))}: ${links}</${tag}>`;
6466 }
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 @@
33 * that says them and the small form that sets them. Escaped here, once.
44 */
55
6 import { clashesLine } from "../overlap.ts";
67 import { appointmentLine, isAppointment } from "../appointment.ts";
78 import type { DeadlineView } from "../deals.ts";
89 import { escape } from "../http.ts";
@@ -17,7 +18,7 @@ export interface AppointmentProblem {
1718
1819 /** "10:00 am · 12 Elm St" under the date; nothing when unset or when the date is no appointment. */
1920 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);
2122
2223 /** "Set time and place" for an inspection or a walkthrough; the form stays open, with the agent's text, when it was refused. */
2324 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";
1212 import { agent as defaults } from "../env.ts";
1313 import { todaysDrafts, unsent, type Agent } from "../reminders.ts";
1414 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";
1717 import { layout } from "./layout.ts";
1818 import { mayRestore } from "../actions.ts";
1919 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
111111 (g) => `<h3 class="week-day">${escape(g.heading)}</h3>
112112 <ul class="week-list">${g.items
113113 .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>`),
115115 )
116116 .join("")}</ul>`,
117117 )
src/pages/deal.ts +2 −2
@@ -11,7 +11,7 @@ import { agent as defaults, standard } from "../env.ts";
1111 import { CONTACT_ROLES, DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, suggestedFor } from "../deadlines.ts";
1212 import { escape } from "../http.ts";
1313 import { coming, comingLine, type Coming } from "../coming.ts";
14 import { clashLine } from "../overlap.ts";
14 import { clashLine, clashesLine } from "../overlap.ts";
1515 import { closingLine } from "../closing.ts";
1616 import { commission, dollars, percent } from "../money.ts";
1717 import { anniversaryDrafts, checkinDrafts, drafts, pending, sentLabel, statusDrafts, type Agent } from "../reminders.ts";
@@ -206,7 +206,7 @@ export interface ClosingProblem {
206206
207207 /** 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. */
208208 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 ?? []);
210210 }
211211
212212 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";
1212 import { asset, escape } from "../http.ts";
1313 import { STATUS } from "../timeline.ts";
1414 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";
1717 import { layout } from "./layout.ts";
1818 import { sideLabel } from "./side.ts";
1919 import type { SideFilter } from "../side.ts";
2020
2121 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);
2523 return text === "" ? "" : ` · ${escape(text)}`;
2624 };
2725
@@ -47,7 +45,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re
4745 <p class="timeline-date">${escape(deal.address)} · ${sideLabel(deal.side)}</p>
4846 <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p>
4947 <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)}
5149 ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`}
5250 <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p>
5351 </li>`;
src/routes.ts +9
@@ -345,6 +345,15 @@ export const DEAL: Schema = {
345345 description: "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.",
346346 properties: { next: DATE },
347347 },
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 },
348357 },
349358 },
350359 },
src/upgrade.test.ts +1
@@ -110,6 +110,7 @@ async function boots(list: string[], n: number, name: string) {
110110 }
111111 expect(shape(check), `schema at version ${n} differs from a fresh database`).toEqual(wanted);
112112 check.close();
113 expect((await get("/healthz")).status, `/healthz at version ${n}`).toBe(200);
113114 const pages = ["/", "/people"];
114115 if (hadDeal) pages.push("/deals/1", "/deals/1/timeline");
115116 for (const path of pages) {
src/week.ts +6
@@ -39,6 +39,12 @@ export function closingNote(deal: WeekDeal<unknown>, d: { kind?: string }): stri
3939 return d.kind === "closing" ? closingWhere({ closing_time: deal.closing_time ?? null, closing_place: deal.closing_place ?? null }) : "";
4040 }
4141
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
4248 export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>(
4349 deals: readonly Deal[],
4450 on: string,

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs