Skip to content

Commit

Permalink
feat: add call api for specific tableId
Browse files Browse the repository at this point in the history
  • Loading branch information
CamilleLegeron committed Oct 31, 2023
1 parent 07bb90b commit 0673694
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/server/lib/DocApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
20 changes: 20 additions & 0 deletions test/server/lib/DocApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`, {
Expand Down

0 comments on commit 0673694

Please sign in to comment.