1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { StolenCar, ApiResponse } from "../../shared/types.ts";
3import {
4createStolenCarReport,
29const cars = await getStolenCars(Object.keys(cleanFilters).length > 0 ? cleanFilters : undefined);
30
31const response: ApiResponse<StolenCar[]> = {
32success: true,
33data: cars
36return c.json(response);
37} catch (error) {
38const response: ApiResponse<null> = {
39success: false,
40error: error instanceof Error ? error.message : "Unknown error occurred"
49const id = parseInt(c.req.param("id"));
50if (isNaN(id)) {
51const response: ApiResponse<null> = {
52success: false,
53error: "Invalid car ID"
58const car = await getStolenCarById(id);
59if (!car) {
60const response: ApiResponse<null> = {
61success: false,
62error: "Stolen car not found"
65}
6667const response: ApiResponse<StolenCar> = {
68success: true,
69data: car
72return c.json(response);
73} catch (error) {
74const response: ApiResponse<null> = {
75success: false,
76error: error instanceof Error ? error.message : "Unknown error occurred"
90
91if (missingFields.length > 0) {
92const response: ApiResponse<null> = {
93success: false,
94error: `Missing required fields: ${missingFields.join(', ')}`
105const createdCar = await getStolenCarById(carId);
106
107const response: ApiResponse<StolenCar> = {
108success: true,
109data: createdCar!,
113return c.json(response, 201);
114} catch (error) {
115const response: ApiResponse<null> = {
116success: false,
117error: error instanceof Error ? error.message : "Unknown error occurred"
126const id = parseInt(c.req.param("id"));
127if (isNaN(id)) {
128const response: ApiResponse<null> = {
129success: false,
130error: "Invalid car ID"
135const { status } = await c.req.json();
136if (!['active', 'found', 'resolved'].includes(status)) {
137const response: ApiResponse<null> = {
138success: false,
139error: "Invalid status. Must be 'active', 'found', or 'resolved'"
145const existingCar = await getStolenCarById(id);
146if (!existingCar) {
147const response: ApiResponse<null> = {
148success: false,
149error: "Stolen car not found"
155const updatedCar = await getStolenCarById(id);
156
157const response: ApiResponse<StolenCar> = {
158success: true,
159data: updatedCar!,
163return c.json(response);
164} catch (error) {
165const response: ApiResponse<null> = {
166success: false,
167error: error instanceof Error ? error.message : "Unknown error occurred"
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { SearchFilters, ApiResponse } from "../../shared/types.ts";
3import { searchAllCars } from "../database/queries.ts";
426const results = await searchAllCars(cleanFilters);
27
28const response: ApiResponse<any> = {
29success: true,
30data: {
38return c.json(response);
39} catch (error) {
40const response: ApiResponse<null> = {
41success: false,
42error: error instanceof Error ? error.message : "Unknown error occurred"
5354if (!field || !['make', 'model', 'color'].includes(field)) {
55const response: ApiResponse<null> = {
56success: false,
57error: "Invalid field. Must be 'make', 'model', or 'color'"
83).slice(0, 10);
84
85const response: ApiResponse<string[]> = {
86success: true,
87data: filtered
90return c.json(response);
91} catch (error) {
92const response: ApiResponse<null> = {
93success: false,
94error: error instanceof Error ? error.message : "Unknown error occurred"
FindMyCarReportStolen.tsx1 match
2122try {
23const response = await fetch('/api/stolen', {
24method: 'POST',
25headers: {
FindMyCarReportFound.tsx1 match
2122try {
23const response = await fetch('/api/found', {
24method: 'POST',
25headers: {
FindMyCarmatches.ts14 matches
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { CarMatch, ApiResponse } from "../../shared/types.ts";
3import {
4getMatches,
39);
40
41const response: ApiResponse<any[]> = {
42success: true,
43data: enrichedMatches
46return c.json(response);
47} catch (error) {
48const response: ApiResponse<null> = {
49success: false,
50error: error instanceof Error ? error.message : "Unknown error occurred"
59const id = parseInt(c.req.param("id"));
60if (isNaN(id)) {
61const response: ApiResponse<null> = {
62success: false,
63error: "Invalid match ID"
68const { status } = await c.req.json();
69if (!['pending', 'confirmed', 'rejected'].includes(status)) {
70const response: ApiResponse<null> = {
71success: false,
72error: "Invalid status. Must be 'pending', 'confirmed', or 'rejected'"
80
81if (!match) {
82const response: ApiResponse<null> = {
83success: false,
84error: "Match not found"
95}
96
97const response: ApiResponse<null> = {
98success: true,
99message: `Match status updated to ${status}${status === 'confirmed' ? '. Car owners have been notified.' : ''}`
102return c.json(response);
103} catch (error) {
104const response: ApiResponse<null> = {
105success: false,
106error: error instanceof Error ? error.message : "Unknown error occurred"
115const stolenCarId = parseInt(c.req.param("stolenCarId"));
116if (isNaN(stolenCarId)) {
117const response: ApiResponse<null> = {
118success: false,
119error: "Invalid stolen car ID"
135);
136
137const response: ApiResponse<any[]> = {
138success: true,
139data: enrichedMatches
142return c.json(response);
143} catch (error) {
144const response: ApiResponse<null> = {
145success: false,
146error: error instanceof Error ? error.message : "Unknown error occurred"
155const foundCarId = parseInt(c.req.param("foundCarId"));
156if (isNaN(foundCarId)) {
157const response: ApiResponse<null> = {
158success: false,
159error: "Invalid found car ID"
175);
176
177const response: ApiResponse<any[]> = {
178success: true,
179data: enrichedMatches
182return c.json(response);
183} catch (error) {
184const response: ApiResponse<null> = {
185success: false,
186error: error instanceof Error ? error.message : "Unknown error occurred"
19await createTables();
2021// API Routes
22app.route("/api/stolen", stolenRoutes);
23app.route("/api/found", foundRoutes);
24app.route("/api/matches", matchRoutes);
25app.route("/api/search", searchRoutes);
2627// Health check endpoint
28app.get("/api/health", (c) => {
29return c.json({
30status: "healthy",
31timestamp: new Date().toISOString(),
32service: "Lost Cars Finder API"
33});
34});
46const initialData = {
47timestamp: new Date().toISOString(),
48apiBase: "/api"
49};
5076<div class="bg-blue-50 p-4 rounded-lg">
77<p class="text-sm text-blue-800">
78API is running at <code>/api</code> -
79<a href="/api/health" class="underline">Check health</a>
80</p>
81</div>
94error: "Endpoint not found",
95available_endpoints: [
96"GET /api/health",
97"GET /api/stolen",
98"POST /api/stolen",
99"GET /api/found",
100"POST /api/found",
101"GET /api/matches",
102"GET /api/search"
103]
104}, 404);
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { FoundCar, ApiResponse } from "../../shared/types.ts";
3import {
4createFoundCarReport,
31const cars = await getFoundCars(Object.keys(cleanFilters).length > 0 ? cleanFilters : undefined);
32
33const response: ApiResponse<FoundCar[]> = {
34success: true,
35data: cars
38return c.json(response);
39} catch (error) {
40const response: ApiResponse<null> = {
41success: false,
42error: error instanceof Error ? error.message : "Unknown error occurred"
51const id = parseInt(c.req.param("id"));
52if (isNaN(id)) {
53const response: ApiResponse<null> = {
54success: false,
55error: "Invalid car ID"
60const car = await getFoundCarById(id);
61if (!car) {
62const response: ApiResponse<null> = {
63success: false,
64error: "Found car not found"
67}
6869const response: ApiResponse<FoundCar> = {
70success: true,
71data: car
74return c.json(response);
75} catch (error) {
76const response: ApiResponse<null> = {
77success: false,
78error: error instanceof Error ? error.message : "Unknown error occurred"
92
93if (missingFields.length > 0) {
94const response: ApiResponse<null> = {
95success: false,
96error: `Missing required fields: ${missingFields.join(', ')}`
152}
153
154const response: ApiResponse<FoundCar> = {
155success: true,
156data: createdCar!,
160return c.json(response, 201);
161} catch (error) {
162const response: ApiResponse<null> = {
163success: false,
164error: error instanceof Error ? error.message : "Unknown error occurred"
173const id = parseInt(c.req.param("id"));
174if (isNaN(id)) {
175const response: ApiResponse<null> = {
176success: false,
177error: "Invalid car ID"
182const { status } = await c.req.json();
183if (!['active', 'matched', 'resolved'].includes(status)) {
184const response: ApiResponse<null> = {
185success: false,
186error: "Invalid status. Must be 'active', 'matched', or 'resolved'"
192const existingCar = await getFoundCarById(id);
193if (!existingCar) {
194const response: ApiResponse<null> = {
195success: false,
196error: "Found car not found"
202const updatedCar = await getFoundCarById(id);
203
204const response: ApiResponse<FoundCar> = {
205success: true,
206data: updatedCar!,
210return c.json(response);
211} catch (error) {
212const response: ApiResponse<null> = {
213success: false,
214error: error instanceof Error ? error.message : "Unknown error occurred"
223const id = parseInt(c.req.param("id"));
224if (isNaN(id)) {
225const response: ApiResponse<null> = {
226success: false,
227error: "Invalid car ID"
232const matches = await findPotentialMatches(id);
233
234const response: ApiResponse<any[]> = {
235success: true,
236data: matches
239return c.json(response);
240} catch (error) {
241const response: ApiResponse<null> = {
242success: false,
243error: error instanceof Error ? error.message : "Unknown error occurred"
34});
3536const response = await fetch(`/api/search?${params}`);
37const data = await response.json();
38
Advertappadvertisements.ts5 matches
10User,
11CreateAdvertisementRequest,
12ApiResponse,
13Advertisement,
14AdvertisementWithLeads
23const ads = await getAdvertisementsByUser(user.id);
24
25const response: ApiResponse<Advertisement[]> = {
26success: true,
27data: ads
84};
85
86const response: ApiResponse<Advertisement> = {
87success: true,
88data: responseAd
123};
124
125const response: ApiResponse<AdvertisementWithLeads> = {
126success: true,
127data: responseAd
158};
159
160const response: ApiResponse<typeof responseStats> = {
161success: true,
162data: responseStats