From e83c37263d0f828f7dd94927ba1e1aca0270ac5c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 3 Jul 2024 16:59:31 +0100 Subject: [PATCH] Further simplification. --- packages/server/src/integrations/couchdb.ts | 36 ++++----------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/packages/server/src/integrations/couchdb.ts b/packages/server/src/integrations/couchdb.ts index 823e5023ea..4004bc47c6 100644 --- a/packages/server/src/integrations/couchdb.ts +++ b/packages/server/src/integrations/couchdb.ts @@ -82,32 +82,20 @@ class CouchDBIntegration implements IntegrationBase { connected: false, } try { - response.connected = await this.query( - () => this.client.exists(), - "validation error" - ) + response.connected = await this.client.exists() } catch (e: any) { response.error = e.message as string } return response } - async query(operation: () => Promise, errorMsg: string) { - try { - return await operation() - } catch (err) { - console.error(errorMsg, err) - throw err - } - } - private parse(query: { json: string | object }) { return typeof query.json === "string" ? JSON.parse(query.json) : query.json } async create(query: { json: string | object }) { const parsed = this.parse(query) - return this.query(() => this.client.put(parsed), "Error writing to couchDB") + return await this.client.put(parsed) } async read(query: { json: string | object }) { @@ -116,10 +104,7 @@ class CouchDBIntegration implements IntegrationBase { include_docs: true, ...parsed, } - const result = await this.query( - () => this.client.allDocs(params), - "Error querying couchDB" - ) + const result = await this.client.allDocs(params) return result.rows.map(row => row.doc) } @@ -129,24 +114,15 @@ class CouchDBIntegration implements IntegrationBase { const oldDoc = await this.get({ id: parsed._id }) parsed._rev = oldDoc._rev } - return this.query( - () => this.client.put(parsed), - "Error updating couchDB document" - ) + return await this.client.put(parsed) } async get(query: { id: string }) { - return this.query( - () => this.client.get(query.id), - "Error retrieving couchDB document by ID" - ) + return await this.client.get(query.id) } async delete(query: { id: string }) { - return this.query( - () => this.client.remove(query.id), - "Error deleting couchDB document" - ) + return await this.client.remove(query.id) } }