feat: add vite env and bulk delete
This commit is contained in:
+5
-5
@@ -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 {
|
||||
|
||||
+11
-13
@@ -129,23 +129,17 @@ async function processResponseItems<T, R>(
|
||||
return results;
|
||||
}
|
||||
|
||||
// Example usage with API calls
|
||||
interface ResponseItem {
|
||||
id: string;
|
||||
data: string;
|
||||
}
|
||||
async function fetchItemDetails(item: ResponseItem): Promise<any> {
|
||||
const response = await fetch(`/api/items/${item.id}`);
|
||||
return response.json();
|
||||
async function fetchUserSettings(documentId: string): Promise<any> {
|
||||
return AppwriteDB.deleteUserSettings(documentId);
|
||||
}
|
||||
|
||||
// Main function that processes the response
|
||||
async function handleResponse(response: ResponseItem[]): Promise<void> {
|
||||
async function handleBulkDelete(idsToDelete: string[]): Promise<void> {
|
||||
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<documents.length; i++) {
|
||||
// keep going from here, the promises
|
||||
documentsToDelete.push(documents[i].$id);
|
||||
}
|
||||
|
||||
if (documentsToDelete) {
|
||||
await handleBulkDelete(documentsToDelete);
|
||||
}
|
||||
|
||||
// Save to Appwrite
|
||||
|
||||
Reference in New Issue
Block a user