diff --git a/server/endpoints/api/workspace/index.js b/server/endpoints/api/workspace/index.js index e7ea17d0..7cd2dd47 100644 --- a/server/endpoints/api/workspace/index.js +++ b/server/endpoints/api/workspace/index.js @@ -447,6 +447,73 @@ function apiWorkspaceEndpoints(app) { } ); + app.post( + "/v1/workspace/:slug/update-pin", + [validApiKey], + async (request, response) => { + /* + #swagger.tags = ['Workspaces'] + #swagger.description = 'Add or remove pin from a document in a workspace by its unique slug.' + #swagger.path = '/workspace/{slug}/update-pin' + #swagger.parameters['slug'] = { + in: 'path', + description: 'Unique slug of workspace to find', + required: true, + type: 'string' + } + #swagger.requestBody = { + description: 'JSON object with the document path and pin status to update.', + required: true, + type: 'object', + content: { + "application/json": { + example: { + docPath: "custom-documents/my-pdf.pdf-hash.json", + pinStatus: true + } + } + } + } + #swagger.responses[200] = { + description: 'OK', + content: { + "application/json": { + schema: { + type: 'object', + example: { + message: 'Pin status updated successfully' + } + } + } + } + } + #swagger.responses[404] = { + description: 'Document not found' + } + #swagger.responses[500] = { + description: 'Internal Server Error' + } + */ + try { + const { slug = null } = request.params; + const { docPath, pinStatus = false } = reqBody(request); + const workspace = await Workspace.get({ slug }); + + const document = await Document.get({ + workspaceId: workspace.id, + docpath: docPath, + }); + if (!document) return response.sendStatus(404).end(); + + await Document.update(document.id, { pinned: pinStatus }); + return response.status(200).json({ message: 'Pin status updated successfully' }).end(); + } catch (error) { + console.error("Error processing the pin status update:", error); + return response.status(500).end(); + } + } + ); + app.post( "/v1/workspace/:slug/chat", [validApiKey], diff --git a/server/swagger/openapi.json b/server/swagger/openapi.json index e0ee35a5..b98891c9 100644 --- a/server/swagger/openapi.json +++ b/server/swagger/openapi.json @@ -1999,6 +1999,73 @@ } } } + },"/v1/workspace/{slug}/update-pin": { + "post": { + "tags": [ + "Workspaces" + ], + "description": "Add or remove pin from a document in a workspace by its unique slug.", + "parameters": [ + { + "name": "slug", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Unique slug of workspace to find" + }, + { + "name": "Authorization", + "in": "header", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "example": { + "message": "Pin status updated successfully" + } + } + } + } + }, + "404": { + "description": "Document not found" + }, + "500": { + "description": "Internal Server Error" + } + }, + "requestBody": { + "description": "JSON object with the document path and pin status to update.", + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "docPath": { + "type": "string", + "example": "custom-documents/my-pdf.pdf-hash.json" + }, + "pinStatus": { + "type": "boolean", + "example": true + } + } + } + } + } + } + } }, "/v1/workspace/{slug}/chat": { "post": {