aliyorulmazdevOriginal post
Rank 1: Thread
Hello, create and delete functions works well with custom domain appwrite database with the code above. but updating doesnt work.
JavaScript
import client from "@/app/appwrite";import { Databases, ID, Query } from "appwrite";
class AddressService { static instance; static databases = new Databases(client); static databaseId = ""; static collectionId = "";
static getInstance() { if (!AddressService.instance) { AddressService.instance = new AddressService(); } return AddressService.instance; } createAddress = async (userId, addressName, fullAddress) => { try { return await AddressService.databases.createDocument( AddressService.databaseId, AddressService.collectionId, ID.unique(), { user_id: userId, address_name: addressName, full_address: fullAddress, } ); } catch (error) { throw error; } }; updateAddress = async (documentId, addressName, fullAddress) => { try { const result = await AddressService.databases.updateDocument( AddressService.databaseId, AddressService.collectionId, documentId, { address_name: addressName, full_address: fullAddress, } ); console.log("Document updated successfully:", result); return result; } catch (error) { console.error("Error updating address:", error); throw error; } }; deleteAddress = async (documentId) => { try { await AddressService.databases.deleteDocument( AddressService.databaseId, AddressService.collectionId, documentId ); console.log("Document deleted successfully"); } catch (error) { console.error("Error deleting document:", error); throw error; } };export default AddressService;Summary
The developer found a temporary solution for updating a document by creating an API route instead of calling the service directly. They shared code snippets demonstrating the creation, update, and delete functions, with the issue specifically with updating not working as expected. The solution involves reviewing and potentially revising the updateAddress function in the AddressService class.