diff --git a/app/server/lib/DocApi.ts b/app/server/lib/DocApi.ts index 03fed7137c..cad31abfdf 100644 --- a/app/server/lib/DocApi.ts +++ b/app/server/lib/DocApi.ts @@ -406,6 +406,23 @@ export class DocWorkerApi { }) ); + // Get the specified table information of specified document in recordish format + this._app.get('/api/docs/:docId/tables/:tableId', canView, + withDoc(async (activeDoc, req, res) => { + const tableId = await getRealTableId(req.params.tableId, {activeDoc, req}); + const records = await getTableRecords(activeDoc, req, { optTableId: "_grist_Tables" }); + const table = records.find((record) => record.fields.tableId === tableId); + if (!table) { + throw new ApiError(`Table not found "${tableId}"`, 404); + } + res.json({id: table.fields.tableId, + fields: { + ..._.omit(table.fields, "tableId"), + tableRef: table.id, + }}); + }) + ); + // The upload should be a multipart post with an 'upload' field containing one or more files. // Returns the list of rowIds for the rows created in the _grist_Attachments table. this._app.post('/api/docs/:docId/attachments', canEdit, withDoc(async (activeDoc, req, res) => { diff --git a/test/server/lib/DocApi.ts b/test/server/lib/DocApi.ts index 0779834577..30176ced0e 100644 --- a/test/server/lib/DocApi.ts +++ b/test/server/lib/DocApi.ts @@ -838,6 +838,26 @@ function testDocApi() { }); }); + it('GET /docs/{did}/tables/{tid} retrieve specific table information', async function () { + const data = { + "id": "Table1", + "fields": { + "rawViewSectionRef": 2, + "primaryViewId": 1, + "onDemand": false, + "summarySourceTable": 0, + "tableRef": 1 + } + }; + const respWithTableId = await axios.get(`${serverUrl}/api/docs/${docIds.Timesheets}/tables/Table1`); + assert.equal(respWithTableId.status, 200); + assert.deepEqual(respWithTableId.data, data); + const respWithTableRef = await axios.get(`${serverUrl}/api/docs/${docIds.Timesheets}/tables/Table1`); + assert.equal(respWithTableRef.status, 200); + assert.deepEqual(respWithTableRef.data, data); + + }); + it("GET/POST/PATCH /docs/{did}/tables and /columns", async function () { // POST /tables: Create new tables let resp = await axios.post(`${serverUrl}/api/docs/${docIds.Timesheets}/tables`, {