Public: anyone can read this; the crew can change it.

This week shows each inspection and walkthrough's time and place, and orders a day's dates by time, so the agent sees where to be hour by hour #193

opened this

Merged 27d 2h ago, live in production

mason/deal-clock:mason/189-this-week-shows-each-inspection-and-walk → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/189-this-week-shows-each-inspection-and-walk was merged into main as a0b9465.

Review

Sign in to review this change.
5 files changed +119 −4
contract/openapi.json +30
@@ -1147,6 +1147,21 @@
11471147 ],
11481148 "description": "Who recorded the waiver."
11491149 },
1150 "time": {
1151 "type": [
1152 "string",
1153 "null"
1154 ],
1155 "description": "An inspection's or walkthrough's time, HH:MM on a quarter hour; null while unset and for any other kind. This week shows it and lists a day's timed dates first, earliest first."
1156 },
1157 "place": {
1158 "type": [
1159 "string",
1160 "null"
1161 ],
1162 "maxLength": 200,
1163 "description": "An inspection's or walkthrough's place; null while unset and for any other kind."
1164 },
11501165 "note": {
11511166 "type": "string",
11521167 "maxLength": 200,
@@ -3343,6 +3358,21 @@
33433358 ],
33443359 "description": "Who recorded the waiver."
33453360 },
3361 "time": {
3362 "type": [
3363 "string",
3364 "null"
3365 ],
3366 "description": "An inspection's or walkthrough's time, HH:MM on a quarter hour; null while unset and for any other kind. This week shows it and lists a day's timed dates first, earliest first."
3367 },
3368 "place": {
3369 "type": [
3370 "string",
3371 "null"
3372 ],
3373 "maxLength": 200,
3374 "description": "An inspection's or walkthrough's place; null while unset and for any other kind."
3375 },
33463376 "note": {
33473377 "type": "string",
33483378 "maxLength": 200,
src/pages/week.ts +4 −2
@@ -12,7 +12,7 @@ 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 { byDay, closingNote, owner, thisWeek } from "../week.ts";
15 import { appointmentNote, byDay, closingNote, owner, thisWeek } from "../week.ts";
1616 import { clashLine } from "../overlap.ts";
1717 import { layout } from "./layout.ts";
1818 import { sideLabel } from "./side.ts";
@@ -20,7 +20,9 @@ import type { SideFilter } from "../side.ts";
2020
2121 const closingAt = (deal: DealView, d: DealView["deadlines"][number]): string => {
2222 const where = closingNote(deal, d);
23 return where === "" ? "" : ` · ${escape(where)}`;
23 const appt = appointmentNote(d);
24 const text = where === "" ? appt : where;
25 return text === "" ? "" : ` · ${escape(text)}`;
2426 };
2527
2628 export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: readonly DealView[]; on: string; q?: string; side?: SideFilter }): string {
src/routes.ts +2
@@ -331,6 +331,8 @@ export const DEAL: Schema = {
331331 done_on: { type: ["string", "null"], description: "The day it was marked done, YYYY-MM-DD in the app's local calendar; null while open. Reopening clears it." },
332332 waived_at: { type: ["string", "null"], description: "When the buyer waived this date on purpose; null while it stands. A waived date is settled: no reminders, flags or conflicts." },
333333 waived_by: { type: ["string", "null"], description: "Who recorded the waiver." },
334 time: { type: ["string", "null"], description: "An inspection's or walkthrough's time, HH:MM on a quarter hour; null while unset and for any other kind. This week shows it and lists a day's timed dates first, earliest first." },
335 place: { type: ["string", "null"], maxLength: 200, description: "An inspection's or walkthrough's place; null while unset and for any other kind." },
334336 note: { type: "string", maxLength: 200, description: "The agent's working note on this date; empty when none. Internal, never sent to a client." },
335337 owes_changed: {
336338 type: ["object", "null"],
src/week.appointment.test.ts added +73
@@ -0,0 +1,73 @@
1 /** This week shows an inspection's or walkthrough's time and place, and orders a day's timed dates by time. */
2 import { afterAll, beforeEach, 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 { addDays, DEFAULT_ZONE, today } from "./dates.ts";
7 import { openDb } from "./db.ts";
8 import { createDeal, listDeals, setAppointment } from "./deals.ts";
9 import { thisWeek } from "./week.ts";
10 import { weekPage } from "./pages/week.ts";
11 import { forgetRationing } from "./security.ts";
12 import { serve } from "./server.ts";
13 import { sign, type Who } from "./who.ts";
14
15 const KEY = "a-key-only-the-forge-holds";
16 const dir = mkdtempSync(join(tmpdir(), "app-week-appt-"));
17 const db = openDb(dir);
18 const alice: Who = { role: "user", id: "u1", name: "alice" };
19 const server = serve({ port: 0, dataDir: dir, identityKey: KEY });
20 const base = `http://${server.hostname}:${server.port}`;
21 afterAll(() => server.stop(true));
22 beforeEach(forgetRationing);
23 const identity = `u1|alice|user|${Date.now() + 600_000}`;
24 const user = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
25
26 const on = today(DEFAULT_ZONE);
27 let n = 0;
28 /** A deal whose walkthrough is due tomorrow and whose inspection is due the same day. */
29 const open = () => {
30 const made = createDeal(db, alice, { address: `${++n} Week Appointment Way`, buyer: "A B", seller: "C D", contractDate: addDays(on, -20), closingDate: addDays(on, 1), openAnyway: true });
31 if (!made.ok) throw new Error(made.message);
32 return made.value;
33 };
34 const dateOf = (deal: { deadlines: readonly { id: number; kind: string }[] }, kind: string) => deal.deadlines.find((d) => d.kind === kind)!;
35 const render = () => {
36 const deals = listDeals(db, alice);
37 if (!deals.ok) throw new Error(deals.message);
38 return weekPage({ who: alice, deals: deals.value, on });
39 };
40 const page = async () => (await fetch(base + "/week", { headers: user })).text();
41
42 test("a timed walkthrough shows its time and place, escaped; an untimed one renders as before", async () => {
43 const deal = open();
44 const before = await page();
45 const walk = dateOf(deal, "walkthrough");
46 const set = setAppointment(db, alice, { id: walk.id, time: "10:00", place: "<script>x</script> Lobby" });
47 expect(set.ok).toBe(true);
48 const html = await page();
49 expect(html).toContain("10:00 am · &lt;script&gt;x&lt;/script&gt; Lobby");
50 expect(html).not.toContain("<script>x</script>");
51 setAppointment(db, alice, { id: walk.id, time: "", place: "" });
52 expect(await page()).toBe(before);
53 });
54
55 test("a day's timed dates come first, earliest first, then the untimed in today's order", () => {
56 const a = open();
57 const b = open();
58 const c = open();
59 for (const d of [a, b, c]) {
60 const w = dateOf(d, "walkthrough");
61 // all three walkthroughs fall on the same day
62 db.query("UPDATE deadline SET due = ?1 WHERE id = ?2").run(addDays(on, 2), w.id);
63 }
64 setAppointment(db, alice, { id: dateOf(c, "walkthrough").id, time: "09:00" });
65 setAppointment(db, alice, { id: dateOf(b, "walkthrough").id, time: "15:30" });
66 const deals = listDeals(db, alice);
67 if (!deals.ok) throw new Error(deals.message);
68 const day = thisWeek(deals.value, on).filter(({ deadline }) => deadline.kind === "walkthrough" && deadline.due === addDays(on, 2));
69 expect(day.map(({ deal }) => deal.address)).toEqual([c.address, b.address, a.address]);
70 expect(day.map(({ deadline }) => deadline.time)).toEqual(["09:00", "15:30", null]);
71 const html = render();
72 expect(html.indexOf("9:00 am")).toBeLessThan(html.indexOf("3:30 pm"));
73 });
src/week.ts +10 −2
@@ -4,6 +4,7 @@
44 */
55
66 import { addDays, spoken } from "./dates.ts";
7 import { appointmentLine, isAppointment } from "./appointment.ts";
78 import { closingWhere } from "./closing.ts";
89 import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
910
@@ -28,8 +29,10 @@ export interface WeekItem<Deal, D> {
2829 }
2930
3031 /** Within a day, timed closings come first by time; everything else keeps its place after them. */
31 const closingTime = (item: { deal: WeekDeal<unknown>; deadline: unknown }): string | undefined =>
32 (item.deadline as { kind?: string }).kind === "closing" ? (item.deal.closing_time ?? undefined) : undefined;
32 const closingTime = (item: { deal: WeekDeal<unknown>; deadline: unknown }): string | undefined => {
33 const d = item.deadline as { kind?: string; time?: string | null };
34 return d.kind === "closing" ? (item.deal.closing_time ?? undefined) : isAppointment(d.kind ?? "") ? (d.time ?? undefined) : undefined;
35 };
3336
3437 /** "2:00 pm at Lakeside Title" for a closing row that has a time or place; "" for any other row. */
3538 export function closingNote(deal: WeekDeal<unknown>, d: { kind?: string }): string {
@@ -55,6 +58,11 @@ export function thisWeek<D extends { due: string; done_at: string | null; waived
5558 );
5659 }
5760
61 /** "10:00 am · 12 Elm St" for an inspection or walkthrough row with a time or place; "" for any other row. */
62 export function appointmentNote(d: { kind: string; time?: string | null; place?: string | null }): string {
63 return appointmentLine({ kind: d.kind, time: d.time ?? null, place: d.place ?? null });
64 }
65
5866 /** Who owes a date: the deal's party in that role by name, if it has one, and the role either way. */
5967 export function owner(
6068 deal: { readonly parties: readonly { role: PartyRole; name: string }[] },

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs