5## Structure
67- `index.ts` - Main entry point for the HTTP API
8- `cron.ts` - Scheduled job to check for floods and send alerts
9- `database/` - Database schema and queries
10- `routes/` - API route handlers
11- `services/` - Business logic services
1213## API Endpoints
1415### Authentication
1617- `POST /api/auth/signup` - Create a new user account
18- `POST /api/auth/login` - Log in to an existing account
19- `GET /api/auth/me` - Get current user information
2021### Locations
2223- `GET /api/locations` - Get all locations for the current user
24- `POST /api/locations` - Add a new location
25- `GET /api/locations/:id` - Get a specific location
26- `DELETE /api/locations/:id` - Delete a location
2728### Flood Checking
2930- `POST /api/check-floods` - Check for potential floods for a user's locations
3132## Cron Job
11};
1213// API base URL
14const API_BASE_URL = '';
1516// DOM Elements
150
151try {
152const response = await fetch(`${API_BASE_URL}/api/auth/login`, {
153method: 'POST',
154headers: {
191
192try {
193const response = await fetch(`${API_BASE_URL}/api/auth/signup`, {
194method: 'POST',
195headers: {
247async function loadLocations() {
248try {
249const response = await fetch(`${API_BASE_URL}/api/locations`, {
250headers: {
251'Authorization': `Bearer ${state.token}`
304
305try {
306const response = await fetch(`${API_BASE_URL}/api/locations/${locationId}`, {
307method: 'DELETE',
308headers: {
326// Load alerts
327async function loadAlerts() {
328// This would be an API call to get alerts
329// For now, we'll just use a placeholder
330state.alerts = [];
455
456try {
457const response = await fetch(`${API_BASE_URL}/api/locations`, {
458method: 'POST',
459headers: {
500elements.checkFloodsBtn.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Checking...';
501
502const response = await fetch(`${API_BASE_URL}/api/check-floods`, {
503method: 'POST',
504headers: {
29});
3031// API routes
32app.route("/api/auth", auth);
33app.route("/api/locations", locations);
3435// Check for floods for a specific user
36app.post("/api/check-floods", async (c) => {
37try {
38const { userId } = await c.req.json();
FloodAppfloodPredictor.ts4 matches
5const RAINFALL_THRESHOLD = 50; // Adjust based on local conditions
67// Open-Meteo API for weather forecasts
8const WEATHER_API_URL = "https://api.open-meteo.com/v1/forecast";
910interface WeatherForecast {
17// Get weather forecast for a location
18async function getWeatherForecast(latitude: number, longitude: number): Promise<WeatherForecast> {
19const url = new URL(WEATHER_API_URL);
20url.searchParams.append("latitude", latitude.toString());
21url.searchParams.append("longitude", longitude.toString());
27
28if (!response.ok) {
29throw new Error(`Weather API error: ${response.statusText}`);
30}
31
12## Project Structure
1314- `/backend` - Server-side code and API endpoints
15- `/frontend` - User interface and client-side code
16- `/shared` - Shared types and utilities
21- Database: SQLite
22- Frontend: HTML, JavaScript, Tailwind CSS
23- Weather Data: Open-Meteo API
24- Notifications: Email
25
56setupDatabase().catch(console.error);
5758// API Routes
5960// Get all job postings
61app.get("/api/jobs", async (c) => {
62const jobs = await sqlite.execute(`SELECT * FROM ${JOBS_TABLE} ORDER BY created_at DESC`);
63return c.json(jobs);
6566// Create a new job posting
67app.post("/api/jobs", async (c) => {
68const body = await c.req.json();
69const { title, description, company, location, salary, contact } = body;
8586// Get chat messages
87app.get("/api/chat", async (c) => {
88const messages = await sqlite.execute(
89`SELECT * FROM ${CHAT_TABLE} ORDER BY created_at DESC LIMIT 100`
9394// Post a chat message
95app.post("/api/chat", async (c) => {
96const body = await c.req.json();
97const { username, message } = body;
GodinoMawabankAuthContext.tsx11 matches
2import React, { createContext, useContext, useState, useEffect } from "https://esm.sh/react@18.2.0";
3import { useNavigate } from "https://esm.sh/react-router-dom@6.16.0?deps=react@18.2.0";
4import { User, AuthResponse, ApiResponse } from "../../../shared/types";
56interface AuthContextType {
8isAuthenticated: boolean;
9isLoading: boolean;
10login: (email: string, password: string) => Promise<ApiResponse<AuthResponse>>;
11register: (formData: any) => Promise<ApiResponse<AuthResponse>>;
12logout: () => void;
13checkAuth: () => Promise<boolean>;
42
43try {
44const response = await fetch("/api/auth/me", {
45headers: {
46Authorization: `Bearer ${token}`
52}
53
54const data: ApiResponse<User> = await response.json();
55
56if (data.success && data.data) {
70};
7172const login = async (email: string, password: string): Promise<ApiResponse<AuthResponse>> => {
73try {
74const response = await fetch("/api/auth/login", {
75method: "POST",
76headers: {
80});
81
82const data: ApiResponse<AuthResponse> = await response.json();
83
84if (data.success && data.data) {
98};
99100const register = async (formData: any): Promise<ApiResponse<AuthResponse>> => {
101try {
102const response = await fetch("/api/auth/register", {
103method: "POST",
104headers: {
108});
109
110const data: ApiResponse<AuthResponse> = await response.json();
111
112if (data.success && data.data) {
GodinoMawabankindex.ts4 matches
21app.use("*", cors());
2223// Mount API routes
24app.route("/api/auth", authRoutes);
25app.route("/api/kyc", kycRoutes);
26app.route("/api/accounts", accountRoutes);
2728// Mount static routes (should be last)
GodinoMawabankstatic.ts1 match
3738// Serve KYC document images
39staticRoutes.get("/api/images/:key", async (c) => {
40try {
41const key = c.req.param("key");
GodinoMawabankaccounts.ts13 matches
7getUserById
8} from "../database/queries";
9import { createApiResponse, generateAccountNumber } from "../../shared/utils";
10import {
11Account,
34const user = await getUserById(userId);
35if (!user) {
36return c.json(createApiResponse(false, undefined, "User not found"), 404);
37}
38
39if (user.kycStatus !== KYCStatus.APPROVED) {
40return c.json(
41createApiResponse(
42false,
43undefined,
52if (existingAccounts.length > 0) {
53return c.json(
54createApiResponse<AccountGenerationResponse>(
55true,
56{ accounts: existingAccounts },
114// Return the generated accounts
115return c.json(
116createApiResponse<AccountGenerationResponse>(
117true,
118{ accounts: generatedAccounts }
122} catch (error) {
123console.error("Account generation error:", error);
124return c.json(createApiResponse(false, undefined, "Account generation failed"), 500);
125}
126});
135const accounts = await getAccountsByUserId(userId);
136
137return c.json(createApiResponse(true, { accounts }));
138} catch (error) {
139console.error("Get accounts error:", error);
140return c.json(createApiResponse(false, undefined, "Failed to get accounts"), 500);
141}
142});
150
151if (isNaN(accountId)) {
152return c.json(createApiResponse(false, undefined, "Invalid account ID"), 400);
153}
154
157
158if (!account) {
159return c.json(createApiResponse(false, undefined, "Account not found"), 404);
160}
161
162// Check if account belongs to user
163if (account.userId !== userId) {
164return c.json(createApiResponse(false, undefined, "Unauthorized"), 403);
165}
166
167return c.json(createApiResponse(true, { account }));
168} catch (error) {
169console.error("Get account error:", error);
170return c.json(createApiResponse(false, undefined, "Failed to get account"), 500);
171}
172});