diff --git a/backend/endpoints/v1/organizations/index.js b/backend/endpoints/v1/organizations/index.js index acdb7be..94170d3 100644 --- a/backend/endpoints/v1/organizations/index.js +++ b/backend/endpoints/v1/organizations/index.js @@ -135,6 +135,41 @@ function organizationEndpoints(app) { } ); + app.post( + "/v1/org/:slug", + [validSessionForUser], + async function (request, response) { + try { + const { slug } = request.params; + const { updates = {} } = reqBody(request); + const user = await userFromSession(request); + if (!user) { + response.sendStatus(403).end(); + return; + } + const organization = await Organization.getWithOwner( + user.id, + `slug = '${slug}'` + ); + if (!organization) { + response + .status(200) + .json({ success: false, error: "No org by that slug." }); + return; + } + + const updateResponse = await Organization.update( + organization.id, + updates + ); + response.status(200).json(updateResponse); + } catch (e) { + console.log(e.message, e); + response.sendStatus(500).end(); + } + } + ); + app.get( "/v1/org/:slug/api-key", [validSessionForUser], diff --git a/backend/models/organization.js b/backend/models/organization.js index 82801a7..7140ad5 100644 --- a/backend/models/organization.js +++ b/backend/models/organization.js @@ -6,6 +6,7 @@ const { OrganizationApiKey } = require("./organizationApiKey"); const Organization = { tablename: "organizations", + writable: ["name"], colsInit: ` id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, @@ -81,6 +82,32 @@ const Organization = { await OrganizationApiKey.create(organization.id); return { organization, message: null }; }, + update: async function (orgId = null, updates = {}) { + if (!orgId) throw new Error("No workspace id provided for update"); + + const validKeys = Object.keys(updates).filter((key) => + this.writable.includes(key) + ); + const values = Object.values(updates); + if (validKeys.length === 0 || validKeys.length !== values.length) + return { success: false, error: "No valid fields to update!" }; + + const template = `UPDATE ${this.tablename} SET ${validKeys.map((key) => { + return `${key}=?`; + })} WHERE id = ?`; + const db = await this.db(); + const { success, error } = await db + .run(template, [...values, orgId]) + .then(() => { + return { success: true, error: null }; + }) + .catch((error) => { + return { success: false, error: error.message }; + }); + + await db.close(); + return { success, error }; + }, get: async function (clause = "") { const db = await this.db(); const result = await db diff --git a/frontend/src/models/organization.ts b/frontend/src/models/organization.ts index 9871882..6237326 100644 --- a/frontend/src/models/organization.ts +++ b/frontend/src/models/organization.ts @@ -26,6 +26,19 @@ const Organization = { if (!organization) return { organization: null, error }; return { organization, error: null }; }, + update: async (slug: string, updates: object = {}) => { + return await fetch(`${API_BASE}/v1/org/${slug}`, { + method: 'POST', + cache: 'no-cache', + body: JSON.stringify({ updates }), + headers: baseHeaders(), + }) + .then((res) => res.json()) + .catch((e) => { + console.error(e); + return { success: false, error: e.message }; + }); + }, bySlug: async (slug: string) => { const organization = await fetch(`${API_BASE}/v1/org/${slug}`, { method: 'GET', diff --git a/frontend/src/pages/DocumentView/FragmentList/index.tsx b/frontend/src/pages/DocumentView/FragmentList/index.tsx index c3ca4c2..ac280da 100644 --- a/frontend/src/pages/DocumentView/FragmentList/index.tsx +++ b/frontend/src/pages/DocumentView/FragmentList/index.tsx @@ -224,7 +224,8 @@ const FullTextWindow = memo(
-            {data?.metadata?.text || '[ERROR] Could not parse text key from embedding'}
+            {data?.metadata?.text ||
+              '[ERROR] Could not parse text key from embedding'}
           
+
+
+ +