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

The sample deals carry inspection and walkthrough times and places, so the sales-meeting tour shows where the buyer has to be #194

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/190-the-sample-deals-carry-inspection-and-wa → main 4 commits fork 3 threads · 3 unresolved

  • Merged. mason/190-the-sample-deals-carry-inspection-and-wa was merged into main as 6140d93.

Review

Sign in to review this change.
3 files changed +45 −1
README.md +3 −1
@@ -34,7 +34,9 @@ looks like today.
3434 3. **Open a deal.** Tap the red inspection marker on 77 Harbor View Dr. A
3535 sheet opens with the date, who owes it (the buyer), what is owed, and the
3636 reminders for each party. Tap the address to open the deal's page: every
outdated

Sentence is wedged into the middle of the paragraph, with an overlong line. Give it its own sentence and name the time and place the reader will see.

37 date, every party, the messages you have sent.
37 date, every party, the messages you have sent. The inspection there reads
38 "10:30 am · 77 Harbor View Dr, Unit 4B", the time and place the buyer has
39 to be at.
3840 4. **Mark a date done.** On 1418 Alder Lane, open a coming date such as
3941 Financing and tap **Mark done**. The marker turns grey and its reminders
4042 stop. **Reopen** puts it back.
src/sample.test.ts +29
@@ -202,3 +202,32 @@ test("refresh keeps the closed samples in the past and in this year, across a Ne
202202 refresh(db, "2027-01-10");
203203 for (const c of closings("2027-01-10")) expect(c <= "2027-01-10" && c.startsWith("2027")).toBe(true);
204204 });
205
206 test("every open sample inspection and walkthrough has a quarter-hour time and a place; nothing else does", () => {
207 const db = openDb(mkdtempSync(join(tmpdir(), "deal-clock-")));
208 const check = () => {
209 const rows = db.query<{ kind: string; time: string | null; place: string | null; done_at: string | null; waived_at: string | null; address: string }, []>(
210 "SELECT k.kind, k.time, k.place, k.done_at, k.waived_at, d.address FROM deadline k JOIN deal d ON d.id = k.deal_id WHERE d.author_id = 'sample'",
211 ).all();
212 let open = 0;
213 for (const r of rows) {
214 const appt = r.kind === "inspection" || r.kind === "walkthrough";
215 if (appt && r.done_at === null && r.waived_at === null) {
216 open++;
217 expect(r.time).toMatch(/^(0[89]|1[0-6]):(00|15|30|45)$/);
218 expect(r.place).toBe(r.address);
219 } else if (!appt) {
220 expect(r.time).toBeNull();
221 expect(r.place).toBeNull();
222 }
223 }
224 expect(open).toBeGreaterThanOrEqual(5);
225 };
226 check();
227 // The README's tour quotes this one.
228 expect(db.query("SELECT k.time FROM deadline k JOIN deal d ON d.id = k.deal_id WHERE d.address = '77 Harbor View Dr, Unit 4B' AND k.kind = 'inspection'").get()).toEqual({ time: "10:30" });
229 restore(db);
230 check();
231 refresh(db, addDays(today(DEFAULT_ZONE), 3));
232 check();
233 });
src/sample.ts +13
@@ -13,6 +13,7 @@ import { addDays, daysBetween, today } from "./dates.ts";
1313 import { zoneOf } from "./profile.ts";
1414 import { type PartyRole } from "./deadlines.ts";
1515 import { BRIEF_LENGTHS, validEmail } from "./env.ts";
16 import { APPOINTMENT_KINDS } from "./appointment.ts";
1617 import { insertDeal } from "./deals.ts";
1718 import type { Side } from "./side.ts";
1819
@@ -353,6 +354,14 @@ export function refresh(db: Database, on = today(zoneOf(db))): void {
353354 }).immediate();
354355 }
355356
357 /** A quarter hour from 08:00 to 16:45 for a sample's appointment, the same every time the samples are written. */
358 function appointmentSlot(address: string, kind: string): string {
359 let n = 0;
360 for (const c of `${address}/${kind}`) n = (n * 31 + c.charCodeAt(0)) % 36;
361 const minutes = 8 * 60 + n * 15;
362 return `${String(Math.floor(minutes / 60)).padStart(2, "0")}:${String(minutes % 60).padStart(2, "0")}`;
363 }
364
356365 /** Write the samples, anchored to `on`. The caller holds the write transaction. */
357366 function writeSamples(db: Database, on: string): void {
358367 for (const s of SAMPLES) {
@@ -372,6 +381,10 @@ function writeSamples(db: Database, on: string): void {
372381 });
373382 if (s.closingAt !== undefined)
374383 db.query("UPDATE deal SET closing_time = ?1, closing_place = ?2 WHERE id = ?3").run(s.closingAt[0], s.closingAt[1], deal.id);
384 for (const kind of APPOINTMENT_KINDS) {
385 if (s.done?.includes(kind) || s.waived?.includes(kind)) continue;
386 db.query("UPDATE deadline SET time = ?1, place = ?2 WHERE deal_id = ?3 AND kind = ?4").run(appointmentSlot(s.address, kind), s.address, deal.id, kind);
387 }
375388 db.query("INSERT INTO sample_deal (deal_id, sample) VALUES (?1, ?2)").run(deal.id, s.address);
376389 if (s.anniversary !== undefined)
377390 db.query("UPDATE party SET email = ?1, contact = ?1 WHERE deal_id = ?2 AND role = 'buyer'").run(s.anniversary, deal.id);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs