feat(berths): website auto-promote toggle + manual-override soft-pin priority
- website_berth_autopromote_enabled (default OFF): a website registration for a specific, currently-available berth auto-creates a prospect (client + optional yacht + interest) and links the berth is_specific_interest=true, flipping the public map to Under Offer; general/residence/contact submissions stay capture-only. Marks the submission converted so a rep never double-creates it. - derivePublicStatus now honours a manual pin (soft pin): a manually-set status wins over the interest-derived Under Offer, but a real permanent tenancy or an explicit sold still override it. - berth rules engine respects a manual pin EXCEPT for sale triggers (-> sold), so a confirmed sale still wins but soft auto-changes never stomp a pin. - Reset-to-automatic action (service + API POST /berths/[id]/status/reset + UI) to drop a manual pin; lock badge on every manual override (list + detail); divergence banner prompting reset when a pinned-Available berth has a deal. - migration stage map updated to the §4b signed-off mapping: GQI -> enquiry unless it named a berth/size marker (-> qualified); SQI -> qualified. Tests: +public-berths soft-pin cases, +website-intake-promote helpers, +migration GQI marker rule. 1582 unit/integration green; tsc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,10 @@ import {
|
||||
notifyWebsiteSubmissionInApp,
|
||||
sendWebsiteSubmissionEmails,
|
||||
} from '@/lib/services/website-intake-email.service';
|
||||
import {
|
||||
autoPromoteWebsiteBerthInquiry,
|
||||
isWebsiteBerthAutopromoteEnabled,
|
||||
} from '@/lib/services/website-intake-promote.service';
|
||||
|
||||
/**
|
||||
* POST /api/public/website-inquiries
|
||||
@@ -190,6 +194,39 @@ export async function POST(req: NextRequest) {
|
||||
),
|
||||
);
|
||||
|
||||
// Flag-gated berth auto-promote (Option 2). On a fresh capture, a
|
||||
// registration for a specific currently-available berth becomes a prospect
|
||||
// immediately and flips the public map to "Under Offer". Default OFF, so
|
||||
// by default captures wait in triage for a rep (Option 1). Fire-and-forget
|
||||
// after the insert: a promote failure must not 500 the capture POST.
|
||||
if (await isWebsiteBerthAutopromoteEnabled(port.id)) {
|
||||
void autoPromoteWebsiteBerthInquiry({
|
||||
portId: port.id,
|
||||
submissionId: parsed.submission_id,
|
||||
kind: parsed.kind,
|
||||
payload: parsed.payload,
|
||||
})
|
||||
.then((r) => {
|
||||
if (r.promoted) {
|
||||
logger.info(
|
||||
{ submissionId: parsed.submission_id, interestId: r.interestId, berthId: r.berthId },
|
||||
'website inquiry auto-promoted to interest (berth marked under offer)',
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
{ submissionId: parsed.submission_id, reason: r.reason },
|
||||
'website inquiry auto-promote skipped',
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((err) =>
|
||||
logger.error(
|
||||
{ err, submissionId: parsed.submission_id },
|
||||
'Failed to auto-promote website inquiry',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Flag-gated CRM-owned emails (registrant confirmation + staff alert).
|
||||
// Fire only on this fresh-insert branch so a redelivery never re-sends.
|
||||
// Inline fire-and-forget: a send failure must not 500 the capture POST.
|
||||
|
||||
26
src/app/api/v1/berths/[id]/status/reset/route.ts
Normal file
26
src/app/api/v1/berths/[id]/status/reset/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { parseBody } from '@/lib/api/route-helpers';
|
||||
import { resetBerthOverrideSchema } from '@/lib/validators/berths';
|
||||
import { resetBerthStatusOverride } from '@/lib/services/berths.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
// POST /api/v1/berths/[id]/status/reset
|
||||
// Clears a manual status pin so the berth resumes derived/automatic status.
|
||||
export const POST = withAuth(
|
||||
withPermission('berths', 'edit', async (req, ctx, params) => {
|
||||
try {
|
||||
const { reason } = await parseBody(req, resetBerthOverrideSchema);
|
||||
const updated = await resetBerthStatusOverride(params.id!, ctx.portId, reason, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data: updated });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user