2be10ce42c
Code (code/): - TypeScript MCP server with 5 tools (business info, hours, services, booking, related) - PostgreSQL schema with pilot business seed data - /.well-known/mcp-server manifest generator - Railway deployment config (Dockerfile, railway.json) - Multi-tenant gateway placeholder GTM (docs/gtm/): - Partner One-Pager: agency sales asset with economics, onboarding, competitive comparison Legal (docs/legal/): - Data Flow & Privacy: data collection, storage, sharing, GDPR/CCPA commitments - Partnership Agreement Skeleton: template for agency/CoC partnerships - IP Notes: well-known convention positioning, telemetry ownership, open-source strategy
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { pool } from '../db/schema.js';
|
|
|
|
export async function getRelatedBusinesses(params: { slug: string }): Promise<Record<string, any>> {
|
|
const result = await pool.query(
|
|
`SELECT id, slug, name, category, city, state, story, related_business_ids
|
|
FROM businesses
|
|
WHERE slug = $1`,
|
|
[params.slug]
|
|
);
|
|
|
|
if (result.rows.length === 0) {
|
|
return { error: `Business '${params.slug}' not found` };
|
|
}
|
|
|
|
const business = result.rows[0];
|
|
const relatedIds = JSON.parse(business.related_business_ids || '[]');
|
|
|
|
if (relatedIds.length === 0) {
|
|
// Fallback: same category, same city
|
|
const fallback = await pool.query(
|
|
`SELECT slug, name, category, city, state, story
|
|
FROM businesses
|
|
WHERE category = $1 AND city = $2 AND slug != $3
|
|
LIMIT 5`,
|
|
[business.category, business.city, params.slug]
|
|
);
|
|
|
|
return {
|
|
source_business: business.name,
|
|
related: fallback.rows.map((r: any) => ({
|
|
slug: r.slug,
|
|
name: r.name,
|
|
category: r.category,
|
|
location: `${r.city}, ${r.state}`,
|
|
story: r.story,
|
|
})),
|
|
};
|
|
}
|
|
|
|
// Resolve related business IDs
|
|
const relatedResult = await pool.query(
|
|
`SELECT slug, name, category, city, state, story
|
|
FROM businesses
|
|
WHERE id = ANY($1)`,
|
|
[relatedIds]
|
|
);
|
|
|
|
return {
|
|
source_business: business.name,
|
|
related: relatedResult.rows.map((r: any) => ({
|
|
slug: r.slug,
|
|
name: r.name,
|
|
category: r.category,
|
|
location: `${r.city}, ${r.state}`,
|
|
story: r.story,
|
|
})),
|
|
};
|
|
}
|