- Form at #/mine/new and #/mine/<id>/edit: coordinates pasted and encoded to a precision-6 geohash in the browser (about 1 km, OSM link to check, no map tiles), euro price parsing, optional exact address saved on the node only - Region guard: refuses places the node does not follow; region fixed on edit - Owner view: days left with a warning under 5 days, manual Renew (30 days), Edit, Delete with confirmation - Tests (jsdom and pure logic), docs, rebuilt web/dist Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
// What the owner sends to publish or change a listing (POST/PUT /api/v1/listings).
|
|
// The node adds identity, time, proof-of-work and signature.
|
|
|
|
import type { Listing } from "./verify.ts";
|
|
|
|
/** Listings expire after at most this many days (the protocol's limit). */
|
|
export const MAX_LIFETIME_DAYS = 30;
|
|
|
|
export interface Draft {
|
|
kind: string;
|
|
category: string;
|
|
geohash: string;
|
|
price: { amount_cents: number; currency: "EUR"; period: "month" | "once" };
|
|
area_m2: number;
|
|
rooms_x2: number;
|
|
features: string[];
|
|
title: string;
|
|
description: string;
|
|
delegate?: string;
|
|
expires_in_days: number;
|
|
}
|
|
|
|
/** The draft that reproduces a published listing, valid for a fresh term of `days`. */
|
|
export function draftFromListing(l: Listing, days = MAX_LIFETIME_DAYS): Draft {
|
|
const period = l.price?.period === "once" ? "once" : "month";
|
|
const d: Draft = {
|
|
kind: l.kind ?? "",
|
|
category: l.category ?? "",
|
|
geohash: l.geohash,
|
|
price: { amount_cents: l.price?.amount_cents ?? 0, currency: "EUR", period },
|
|
area_m2: l.area_m2 ?? 0,
|
|
rooms_x2: l.rooms_x2 ?? 0,
|
|
features: l.features ?? [],
|
|
title: l.title ?? "",
|
|
description: l.description ?? "",
|
|
expires_in_days: days,
|
|
};
|
|
if (l.delegate) d.delegate = l.delegate;
|
|
return d;
|
|
}
|