From ada0776d4ed4784e086406e635f7d230b54f1959 Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Fri, 13 Jun 2025 21:03:36 -0300 Subject: [PATCH] feat: add vite env and bulk delete --- src/appwrite.ts | 10 +++++----- src/index.ts | 24 +++++++++++------------- vite-env.d.ts | 11 +++++++++++ vite.config.js | 3 ++- 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 vite-env.d.ts diff --git a/src/appwrite.ts b/src/appwrite.ts index 75361ff..9b342fc 100644 --- a/src/appwrite.ts +++ b/src/appwrite.ts @@ -5,17 +5,17 @@ import { FoodStorage, UserSettings } from './types'; const client = new Client(); client - .setEndpoint('https://cloud.appwrite.io/v1') // Your Appwrite endpoint - .setProject("684ac3bf000ee8950f5a"); // Replace with your project ID + .setEndpoint(import.meta.env.VITE_APPWRITE_ENDPOINT) + .setProject("684ac3bf000ee8950f5a"); // Initialize services export const account = new Account(client); export const databases = new Databases(client); // Configuration constants -export const DATABASE_ID = '684b38db000fac8c781c'; // Replace with your database ID -export const FOOD_ENTRIES_COLLECTION_ID = '684b38e300336fc605dc'; // Replace with your collection ID -export const USER_SETTINGS_COLLECTION_ID = '684c75140026689fe603'; // Replace with your collection ID +export const DATABASE_ID = import.meta.env.VITE_APPWRITE_DBID +export const FOOD_ENTRIES_COLLECTION_ID = import.meta.env.VITE_APPWRITE_FOODENTRIESID +export const USER_SETTINGS_COLLECTION_ID = import.meta.env.VITE_APPWRITE_USERSETTINGSID // Auth helper functions export class AppwriteAuth { diff --git a/src/index.ts b/src/index.ts index 766dfee..b365b6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -129,23 +129,17 @@ async function processResponseItems( return results; } -// Example usage with API calls -interface ResponseItem { - id: string; - data: string; -} -async function fetchItemDetails(item: ResponseItem): Promise { - const response = await fetch(`/api/items/${item.id}`); - return response.json(); +async function fetchUserSettings(documentId: string): Promise { + return AppwriteDB.deleteUserSettings(documentId); } // Main function that processes the response -async function handleResponse(response: ResponseItem[]): Promise { +async function handleBulkDelete(idsToDelete: string[]): Promise { try { // This creates and executes all promises concurrently - const results = await processResponseItems(response, fetchItemDetails); + const results = await processResponseItems(idsToDelete, fetchUserSettings); - console.log('All requests completed:', results); + console.debug('All requests completed:', results); } catch (error) { console.error('One or more requests failed:', error); } @@ -163,9 +157,13 @@ async function handleSaveSettings(e: SubmitEvent) { // Delete existing settings - keep only the new one const documents = await AppwriteDB.getUserSettings(); - const promises = []; + const documentsToDelete: string[] = []; for (let i=0; i