Browse Source

refactor: new api design

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1668/head
Pranav C 3 years ago
parent
commit
bf048ce294
  1. 16
      packages/nc-gui/components/project/spreadsheet/components/columnFilter.vue
  2. 4
      packages/nc-gui/components/project/spreadsheet/components/sortListMenu.vue
  3. 11
      packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue
  4. 4
      packages/nc-gui/mixins/device.js
  5. 8
      packages/nc-gui/store/project.js
  6. 2018
      packages/nocodb-sdk/src/lib/Api.ts
  7. 2
      packages/nocodb/package.json
  8. 7
      packages/nocodb/src/lib/noco-models/User.ts
  9. 6
      packages/nocodb/src/lib/noco/meta/api/apiTokenApis.ts
  10. 24
      packages/nocodb/src/lib/noco/meta/api/auditApis.ts
  11. 4
      packages/nocodb/src/lib/noco/meta/api/cacheApis.ts
  12. 29
      packages/nocodb/src/lib/noco/meta/api/columnApis.ts
  13. 28
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts
  14. 308
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasNestedApis.ts
  15. 4
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataApis.ts
  16. 2
      packages/nocodb/src/lib/noco/meta/api/dataApis/oldDataApis.ts
  17. 52
      packages/nocodb/src/lib/noco/meta/api/filterApis.ts
  18. 14
      packages/nocodb/src/lib/noco/meta/api/formViewApis.ts
  19. 4
      packages/nocodb/src/lib/noco/meta/api/formViewColumnApis.ts
  20. 33
      packages/nocodb/src/lib/noco/meta/api/galleryViewApis.ts
  21. 2
      packages/nocodb/src/lib/noco/meta/api/gridViewApis.ts
  22. 6
      packages/nocodb/src/lib/noco/meta/api/gridViewColumnApis.ts
  23. 27
      packages/nocodb/src/lib/noco/meta/api/hookApis.ts
  24. 2
      packages/nocodb/src/lib/noco/meta/api/hookFilterApis.ts
  25. 7
      packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts
  26. 2
      packages/nocodb/src/lib/noco/meta/api/modelVisibilityApis.ts
  27. 22
      packages/nocodb/src/lib/noco/meta/api/pluginApis.ts
  28. 19
      packages/nocodb/src/lib/noco/meta/api/projectApis.ts
  29. 2
      packages/nocodb/src/lib/noco/meta/api/projectUserApis.ts
  30. 2
      packages/nocodb/src/lib/noco/meta/api/publicApis/publicDataApis.ts
  31. 22
      packages/nocodb/src/lib/noco/meta/api/publicApis/publicMetaApis.ts
  32. 22
      packages/nocodb/src/lib/noco/meta/api/sharedBaseApis.ts
  33. 24
      packages/nocodb/src/lib/noco/meta/api/sortApis.ts
  34. 21
      packages/nocodb/src/lib/noco/meta/api/tableApis.ts
  35. 7
      packages/nocodb/src/lib/noco/meta/api/userApi/initStrategies.ts
  36. 51
      packages/nocodb/src/lib/noco/meta/api/userApi/userApis.ts
  37. 7
      packages/nocodb/src/lib/noco/meta/api/utilApis.ts
  38. 32
      packages/nocodb/src/lib/noco/meta/api/viewApis.ts
  39. 14
      packages/nocodb/src/lib/noco/meta/api/viewColumnApis.ts
  40. 2186
      scripts/sdk/swagger.json

16
packages/nc-gui/components/project/spreadsheet/components/columnFilter.vue

@ -321,19 +321,19 @@ export default {
for (const [i, filter] of Object.entries(this.filters)) {
if (filter.status === 'delete') {
if (this.hookId || hookId) {
await this.$api.dbTableFilter.delete(this.hookId || hookId, filter.id)
await this.$api.dbTableFilter.delete(filter.id)
} else {
await this.$api.dbTableFilter.delete(this.viewId, filter.id)
await this.$api.dbTableFilter.delete(filter.id)
}
} else if (filter.status === 'update') {
if (filter.id) {
if (this.hookId || hookId) {
await this.$api.dbTableFilter.update(this.hookId || hookId, filter.id, {
await this.$api.dbTableFilter.update(filter.id, {
...filter,
fk_parent_id: this.parentId
})
} else {
await this.$api.dbTableFilter.update(this.viewId, filter.id, {
await this.$api.dbTableFilter.update(filter.id, {
...filter,
fk_parent_id: this.parentId
})
@ -363,12 +363,12 @@ export default {
let filters = []
if (this.viewId && this._isUIAllowed('filterSync')) {
filters = this.parentId
? (await this.$api.dbTableFilter.childrenRead(this.viewId, this.parentId))
? (await this.$api.dbTableFilter.childrenRead(this.parentId))
: (await this.$api.dbTableFilter.read(this.viewId))
}
if (this.hookId && this._isUIAllowed('filterSync')) {
filters = this.parentId
? (await this.$api.dbTableWebhookFilter.childrenRead(this.hookId, this.parentId))
? (await this.$api.dbTableFilter.childrenRead(this.parentId))
: (await this.$api.dbTableWebhookFilter.read(this.hookId))
}
@ -406,7 +406,7 @@ export default {
} else if (!this.autoApply) {
filter.status = 'update'
} else if (filter.id) {
await this.$api.dbTableFilter.update(this.viewId, filter.id, {
await this.$api.dbTableFilter.update(filter.id, {
...filter,
fk_parent_id: this.parentId
})
@ -430,7 +430,7 @@ export default {
if (!this.autoApply) {
this.$set(filter, 'status', 'delete')
} else {
await this.$api.dbTableFilter.delete(this.viewId, filter.id)
await this.$api.dbTableFilter.delete(filter.id)
await this.loadFilter()
this.$emit('updated')
}

4
packages/nc-gui/components/project/spreadsheet/components/sortListMenu.vue

@ -148,7 +148,7 @@ export default {
async saveOrUpdate(sort, i) {
if (!this.shared && this._isUIAllowed('sortSync')) {
if (sort.id) {
await this.$api.dbTableSort.update(this.viewId, sort.id, sort)
await this.$api.dbTableSort.update(sort.id, sort)
} else {
this.$set(this.sortList, i, (await this.$api.dbTableSort.create(this.viewId, sort)))
}
@ -161,7 +161,7 @@ export default {
},
async deleteSort(sort, i) {
if (!this.shared && sort.id && this._isUIAllowed('sortSync')) {
await this.$api.dbTableSort.delete(this.viewId, sort.id)
await this.$api.dbTableSort.delete(sort.id)
await this.loadSortList()
} else {
this.sortList.splice(i, 1)

11
packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue

@ -973,8 +973,7 @@ export default {
if (this.nodes.newTable && !this.nodes.tableCreated) {
const columns = this.sqlUi.getNewTableColumns().filter(col => this.nodes.newTable.columns.includes(col.column_name))
await this.$api.dbTable.create(
this.$store.state.project.projectId,
this.$store.state.project.project.bases[0].id,
this.projectId,
{
table_name: this.nodes.table_name,
title: this.nodes.title,
@ -1050,7 +1049,11 @@ export default {
}, {})
// const insertedData = await this.api.insert(insertObj)
const insertedData = (await this.$api.data.create(this.meta.id, insertObj))
const insertedData = (await this.$api.dbTableRow.create(
'noco',
this.projectName,
this.meta.title, insertObj
))
this.data.splice(row, 1, {
row: insertedData,
@ -1309,7 +1312,7 @@ export default {
const {
list,
pageInfo
} = (await this.$api.dbViewRow.list('noco', this.$store.getters['project/GtrProjectName'], this.meta.title, this.selectedView.title,
} = (await this.$api.dbViewRow.list('noco', this.projectName, this.meta.title, this.selectedView.title,
{
...this.queryParams,
...(this._isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(this.sortList) }),

4
packages/nc-gui/mixins/device.js

@ -52,7 +52,9 @@ export default {
return zhLan.some(l => browserLan.includes(l))
},
...mapGetters({
_isUIAllowed: 'users/GtrIsUIAllowed'
_isUIAllowed: 'users/GtrIsUIAllowed',
projectName: 'project/GtrProjectName',
projectId: 'project/GtrProjectId'
})
},
mounted() {

8
packages/nc-gui/store/project.js

@ -192,10 +192,13 @@ export const getters = {
return data
},
GtrProjectName(state) {
return state.project && state.project.title// state.unserializedList && state.unserializedList[0] ? state.unserializedList[0].projectJson.title : "__project__";
return state.project && state.project.title
},
GtrProjectId(state) {
return state.project && state.project.id
},
GtrProjectPrefix(state) {
return state.project && state.project.prefix//state.unserializedList && state.unserializedList[0] ? state.unserializedList[0].projectJson.prefix : null;
return state.project && state.project.prefix
},
GtrApiEnvironment(state) {
@ -368,7 +371,6 @@ export const actions = {
const tables = (await this.$api.dbTable.list(
state.projectId,
state.project.bases[0].id,
{
includeM2M: rootState.windows.includeM2M || ''
})).list

2018
packages/nocodb-sdk/src/lib/Api.ts

File diff suppressed because it is too large Load Diff

2
packages/nocodb/package.json

@ -154,7 +154,7 @@
"nc-lib-gui": "0.84.15",
"nc-plugin": "^0.1.1",
"ncp": "^2.0.0",
"nocodb-sdk": "0.0.9",
"nocodb-sdk": "file:../nocodb-sdk",
"nodemailer": "^6.4.10",
"ora": "^4.0.4",
"os-locale": "^5.0.0",

7
packages/nocodb/src/lib/noco-models/User.ts

@ -136,4 +136,11 @@ export default class User implements UserType {
}
return user;
}
static async getByRefreshToken(refresh_token, ncMeta = Noco.ncMeta) {
const user = await ncMeta.metaGet2(null, null, MetaTable.USERS, {
refresh_token
});
return user;
}
}

6
packages/nocodb/src/lib/noco/meta/api/apiTokenApis.ts

@ -18,15 +18,15 @@ export async function apiTokenDelete(req: Request, res: Response) {
const router = Router({ mergeParams: true });
router.get(
'/projects/:projectId/apiTokens',
'/api/v1/db/meta/projects/:projectId/apiTokens',
ncMetaAclMw(apiTokenList, 'apiTokenList')
);
router.post(
'/projects/:projectId/apiTokens',
'/api/v1/db/meta/projects/:projectId/apiTokens',
ncMetaAclMw(apiTokenCreate, 'apiTokenCreate')
);
router.delete(
'/projects/:projectId/apiTokens/:token',
'/api/v1/db/meta/projects/:projectId/apiTokens/:token',
ncMetaAclMw(apiTokenDelete, 'apiTokenDelete')
);

24
packages/nocodb/src/lib/noco/meta/api/auditApis.ts

@ -20,7 +20,7 @@ export async function auditRowUpdate(req: Request<any, any>, res) {
res.json(
await Audit.insert({
fk_model_id: req.body.fk_model_id,
row_id: req.body.row_id,
row_id: req.params.rowId,
op_type: AuditOperationTypes.DATA,
op_sub_type: AuditOperationSubTypes.UPDATE,
description: `Table ${model.table_name} : field ${req.body.column_name} got changed from ${req.body.prev_value} to ${req.body.value}`,
@ -58,12 +58,24 @@ export async function commentsCount(req: Request<any, any, any>, res) {
}
const router = Router({ mergeParams: true });
router.get('/audits/comments', ncMetaAclMw(commentList, 'commentList'));
router.post('/audits/rowUpdate', ncMetaAclMw(auditRowUpdate, 'auditRowUpdate'));
router.post('/audits/comments', ncMetaAclMw(commentRow, 'commentRow'));
router.get(
'/audits/comments/count',
'/api/v1/db/meta/audits/comments',
ncMetaAclMw(commentList, 'commentList')
);
router.post(
'/api/v1/db/meta/audits/comments',
ncMetaAclMw(commentRow, 'commentRow')
);
router.post(
'/api/v1/db/meta/audits/rows/:rowId/update',
ncMetaAclMw(auditRowUpdate, 'auditRowUpdate')
);
router.get(
'/api/v1/db/meta/audits/comments/count',
ncMetaAclMw(commentsCount, 'commentsCount')
);
router.get('/project/:projectId/audits', ncMetaAclMw(auditList, 'auditList'));
router.get(
'/api/v1/db/meta/project/:projectId/audits',
ncMetaAclMw(auditList, 'auditList')
);
export default router;

4
packages/nocodb/src/lib/noco/meta/api/cacheApis.ts

@ -16,6 +16,6 @@ export async function cacheDelete(_, res) {
}
const router = Router();
router.get('/cache', catchError(cacheGet));
router.delete('/cache', catchError(cacheDelete));
router.get('/api/v1/db/meta/cache', catchError(cacheGet));
router.delete('/api/v1/db/meta/cache', catchError(cacheDelete));
export default router;

29
packages/nocodb/src/lib/noco/meta/api/columnApis.ts

@ -498,14 +498,15 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
}
export async function columnSetAsPrimary(req: Request, res: Response) {
res.json(
await Model.updatePrimaryColumn(req.params.tableId, req.params.columnId)
);
const column = await Column.get({ colId: req.params.columnId });
res.json(await Model.updatePrimaryColumn(column.fk_model_id, column.id));
}
export async function columnUpdate(req: Request, res: Response<TableType>) {
const column = await Column.get({ colId: req.params.columnId });
const table = await Model.getWithInfo({
id: req.params.tableId
id: column.fk_model_id
});
const base = await Base.get(table.base_id);
@ -529,7 +530,6 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
NcError.badRequest('Duplicate column alias');
}
const column = table.columns.find(c => c.id === req.params.columnId);
let colBody = req.body;
if (
[
@ -622,8 +622,9 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
export async function columnDelete(req: Request, res: Response<TableType>) {
const column = await Column.get({ colId: req.params.columnId });
const table = await Model.getWithInfo({
id: req.params.tableId
id: column.fk_model_id
});
const base = await Base.get(table.base_id);
@ -636,9 +637,6 @@ export async function columnDelete(req: Request, res: Response<TableType>) {
const sqlMgr = await ProjectMgrv2.getSqlMgr({ id: base.project_id });
// try {
const column: Column = table.columns.find(c => c.id === req.params.columnId);
switch (column.uidt) {
case UITypes.Lookup:
case UITypes.Rollup:
@ -900,17 +898,20 @@ const deleteHmOrBtRelation = async (
};
const router = Router({ mergeParams: true });
router.post('/tables/:tableId/columns/', ncMetaAclMw(columnAdd, 'columnAdd'));
router.put(
'/tables/:tableId/columns/:columnId',
router.post(
'/api/v1/db/meta/tables/:tableId/columns/',
ncMetaAclMw(columnAdd, 'columnAdd')
);
router.patch(
'/api/v1/db/meta/columns/:columnId',
ncMetaAclMw(columnUpdate, 'columnUpdate')
);
router.delete(
'/tables/:tableId/columns/:columnId',
'/api/v1/db/meta/columns/:columnId',
ncMetaAclMw(columnDelete, 'columnDelete')
);
router.post(
'/tables/:tableId/columns/:columnId/primary',
'/api/v1/db/meta/columns/:columnId/primary',
ncMetaAclMw(columnSetAsPrimary, 'columnSetAsPrimary')
);
export default router;

28
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts

@ -8,7 +8,7 @@ import View from '../../../../noco-models/View';
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import { getViewAndModelFromRequestByAliasOrId } from './helpers';
export async function dataList(req: Request, res: Response) {
async function dataList(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
res.json(await getDataList(model, view, req));
}
@ -108,20 +108,44 @@ async function dataRead(req: Request, res: Response) {
const router = Router({ mergeParams: true });
// table data crud apis
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName',
ncMetaAclMw(dataList, 'dataList')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId',
ncMetaAclMw(dataRead, 'dataRead')
);
router.patch(
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId',
ncMetaAclMw(dataUpdate, 'dataUpdate')
);
router.patch(
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId',
ncMetaAclMw(dataUpdate, 'dataUpdate')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName',
ncMetaAclMw(dataList, 'dataList')
);
// table view data crud apis
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName',
ncMetaAclMw(dataList, 'dataList')
);
router.post(
'/api/v1/db/data/:orgs/:projectName/:tableName',
ncMetaAclMw(dataInsert, 'dataInsert')
);
router.post(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName',
ncMetaAclMw(dataInsert, 'dataInsert')
);
router.put(
router.patch(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId',
ncMetaAclMw(dataUpdate, 'dataUpdate')
);

308
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasNestedApis.ts

@ -0,0 +1,308 @@
import { Request, Response, Router } from 'express';
import Model from '../../../../noco-models/Model';
import Base from '../../../../noco-models/Base';
import NcConnectionMgrv2 from '../../../common/NcConnectionMgrv2';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import View from '../../../../noco-models/View';
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import { getViewAndModelFromRequestByAliasOrId } from './helpers';
import { NcError } from '../../helpers/catchError';
export async function mmList(req: Request, res: Response, next) {
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
if (!model) return next(new Error('Table not found'));
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
const data = await baseModel.mmList(
{
colId: column.id,
parentId: req.params.rowId
},
req.query as any
);
const count: any = await baseModel.mmListCount({
colId: column.id,
parentId: req.params.rowId
});
res.json(
new PagedResponseImpl(data, {
count,
...req.query
})
);
}
export async function mmExcludedList(req: Request, res: Response, next) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) return next(new Error('Table not found'));
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
const data = await baseModel.getMmChildrenExcludedList(
{
colId: column.id,
pid: req.params.rowId
},
req.query
);
const count = await baseModel.getMmChildrenExcludedListCount(
{
colId: column.id,
pid: req.params.rowId
},
req.query
);
res.json(
new PagedResponseImpl(data, {
count,
...req.query
})
);
}
export async function hmExcludedList(req: Request, res: Response, next) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) return next(new Error('Table not found'));
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
const data = await baseModel.getHmChildrenExcludedList(
{
colId: column.id,
pid: req.params.rowId
},
req.query
);
const count = await baseModel.getHmChildrenExcludedListCount(
{
colId: column.id,
pid: req.params.rowId
},
req.query
);
res.json(
new PagedResponseImpl(data, {
count,
...req.query
})
);
}
export async function btExcludedList(req: Request, res: Response, next) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) return next(new Error('Table not found'));
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
const data = await baseModel.getBtChildrenExcludedList(
{
colId: column.id,
cid: req.params.rowId
},
req.query
);
const count = await baseModel.getBtChildrenExcludedListCount(
{
colId: column.id,
cid: req.params.rowId
},
req.query
);
res.json(
new PagedResponseImpl(data, {
count,
...req.query
})
);
}
export async function hmList(req: Request, res: Response, next) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) return next(new Error('Table not found'));
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
const data = await baseModel.hmList(
{
colId: column.id,
id: req.params.rowId
},
req.query
);
const count = await baseModel.hmListCount({
colId: column.id,
id: req.params.rowId
});
res.json(
new PagedResponseImpl(data, {
totalRows: count
} as any)
);
}
//@ts-ignore
async function relationDataDelete(req, res) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) NcError.notFound('Table not found');
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
await baseModel.removeChild({
colId: column.id,
childId: req.params.childId,
rowId: req.params.rowId
});
res.json({ msg: 'success' });
}
//@ts-ignore
async function relationDataAdd(req, res) {
const view = await View.get(req.params.viewId);
const model = await Model.getByIdOrName({
id: view?.fk_model_id || req.params.viewId
});
if (!model) NcError.notFound('Table not found');
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
const column = await getColumnByIdOrName(req.params.columnName, model);
await baseModel.addChild({
colId: column.id,
childId: req.params.childId,
rowId: req.params.rowId
});
res.json({ msg: 'success' });
}
async function getColumnByIdOrName(columnNameOrId: string, model: Model) {
const column = (await model.getColumns()).find(
c =>
column.title === columnNameOrId ||
c.id === columnNameOrId ||
column.column_name === columnNameOrId
);
if (!column)
NcError.notFound(`Column with id/name '${columnNameOrId}' is not found`);
return column;
}
const router = Router({ mergeParams: true });
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/mm/:columnName/exclude',
ncMetaAclMw(mmExcludedList, 'mmExcludedList')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/hm/:columnName/exclude',
ncMetaAclMw(hmExcludedList, 'hmExcludedList')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/bt/:columnName/exclude',
ncMetaAclMw(btExcludedList, 'btExcludedList')
);
router.post(
'/api/v1/db/data/:orgs/:projectName/:tableName/:relationType/:columnName/:refRowId',
ncMetaAclMw(relationDataAdd, 'relationDataAdd')
);
router.delete(
'/api/v1/db/data/:orgs/:projectName/:tableName/:relationType/:columnName/:refRowId',
ncMetaAclMw(relationDataDelete, 'relationDataDelete')
);
export default router;

4
packages/nocodb/src/lib/noco/meta/api/dataApis/dataApis.ts

@ -554,7 +554,7 @@ const router = Router({ mergeParams: true });
// '/data/:orgs/:projectName/:tableName/views/:viewName',
// ncMetaAclMw(dataInsertNew)
// );
// router.put(
// router.patch(
// '/data/:orgs/:projectName/:tableName/views/:viewName/:rowId',
// ncMetaAclMw(dataUpdateNew)
// );
@ -566,7 +566,7 @@ const router = Router({ mergeParams: true });
router.get('/data/:viewId/', ncMetaAclMw(dataList, 'dataList'));
router.post('/data/:viewId/', ncMetaAclMw(dataInsert, 'dataInsert'));
router.get('/data/:viewId/:rowId', ncMetaAclMw(dataRead, 'dataRead'));
router.put('/data/:viewId/:rowId', ncMetaAclMw(dataUpdate, 'dataUpdate'));
router.patch('/data/:viewId/:rowId', ncMetaAclMw(dataUpdate, 'dataUpdate'));
router.delete('/data/:viewId/:rowId', ncMetaAclMw(dataDelete, 'dataDelete'));
router.get('/data/:viewId/:rowId/mm/:colId', ncMetaAclMw(mmList, 'mmList'));

2
packages/nocodb/src/lib/noco/meta/api/dataApis/oldDataApis.ts

@ -138,7 +138,7 @@ router.get(
'/nc/:projectId/api/v2/:tableName/:rowId',
ncMetaAclMw(dataRead, 'dataRead')
);
router.put(
router.patch(
'/nc/:projectId/api/v2/:tableName/:rowId',
ncMetaAclMw(dataUpdate, 'dataUpdate')
);

52
packages/nocodb/src/lib/noco/meta/api/filterApis.ts

@ -85,7 +85,7 @@ export async function filterUpdate(req, res, next) {
...req.body,
fk_view_id: req.params.viewId
});
Tele.emit('evt', { evt_type: 'table:updated' });
Tele.emit('evt', { evt_type: 'filter:updated' });
res.json(filter);
} catch (e) {
console.log(e);
@ -97,7 +97,7 @@ export async function filterUpdate(req, res, next) {
export async function filterDelete(req: Request, res: Response, next) {
try {
const filter = await Filter.delete(req.params.filterId);
Tele.emit('evt', { evt_type: 'table:deleted' });
Tele.emit('evt', { evt_type: 'filter:deleted' });
res.json(filter);
} catch (e) {
console.log(e);
@ -105,26 +105,60 @@ export async function filterDelete(req: Request, res: Response, next) {
}
}
export async function hookFilterList(
req: Request<any, any, any, TableListParams>,
res: Response
) {
const filter = await Filter.rootFilterListByHook({
hookId: req.params.hookId
});
res.json(filter);
}
export async function hookFilterCreate(req: Request<any, any, TableReq>, res) {
const filter = await Filter.insert({
...req.body,
fk_hook_id: req.params.hookId
});
Tele.emit('evt', { evt_type: 'hookFilter:created' });
res.json(filter);
}
const router = Router({ mergeParams: true });
router.get('/views/:viewId/filters/', ncMetaAclMw(filterList, 'filterList'));
router.get(
'/api/v1/db/meta/views/:viewId/filters',
ncMetaAclMw(filterList, 'filterList')
);
router.post(
'/views/:viewId/filters/',
'/api/v1/db/meta/views/:viewId/filters',
ncMetaAclMw(filterCreate, 'filterCreate')
);
router.get(
'/api/v1/db/meta/hooks/:hookId/filters',
ncMetaAclMw(hookFilterList, 'filterList')
);
router.post(
'/api/v1/db/meta/hooks/:hookId/filters',
ncMetaAclMw(hookFilterCreate, 'filterCreate')
);
router.get(
'/views/:viewId/filters/:filterId',
'/api/v1/db/meta/filters/:filterId',
ncMetaAclMw(filterGet, 'filterGet')
);
router.put(
'/views/:viewId/filters/:filterId',
router.patch(
'/api/v1/db/meta/filters/:filterId',
ncMetaAclMw(filterUpdate, 'filterUpdate')
);
router.delete(
'/views/:viewId/filters/:filterId',
'/api/v1/db/meta/filters/:filterId',
ncMetaAclMw(filterDelete, 'filterDelete')
);
router.get(
'/views/:viewId/filters/:filterParentId/children',
'/api/v1/db/meta/filters/:filterParentId/children',
ncMetaAclMw(filterChildrenRead, 'filterChildrenRead')
);
export default router;

14
packages/nocodb/src/lib/noco/meta/api/formViewApis.ts

@ -40,13 +40,19 @@ export async function formViewDelete(req: Request, res: Response, next) {}
const router = Router({ mergeParams: true });
router.post(
'/tables/:tableId/forms',
'/api/v1/db/meta/tables/:tableId/forms',
ncMetaAclMw(formViewCreate, 'formViewCreate')
);
router.get('/forms/:formViewId', ncMetaAclMw(formViewGet, 'formViewGet'));
router.put('/forms/:formViewId', ncMetaAclMw(formViewUpdate, 'formViewUpdate'));
router.get(
'/api/v1/db/meta/forms/:formViewId',
ncMetaAclMw(formViewGet, 'formViewGet')
);
router.patch(
'/api/v1/db/meta/forms/:formViewId',
ncMetaAclMw(formViewUpdate, 'formViewUpdate')
);
router.delete(
'/forms/:formViewId',
'/api/v1/db/meta/forms/:formViewId',
ncMetaAclMw(formViewDelete, 'formViewDelete')
);
export default router;

4
packages/nocodb/src/lib/noco/meta/api/formViewColumnApis.ts

@ -9,8 +9,8 @@ export async function columnUpdate(req: Request, res: Response) {
}
const router = Router({ mergeParams: true });
router.put(
'/formColumns/:formViewColumnId',
router.patch(
'/api/v1/db/meta/forms/columns/:formViewColumnId',
ncMetaAclMw(columnUpdate, 'columnUpdate')
);
export default router;

33
packages/nocodb/src/lib/noco/meta/api/galleryViewApis.ts

@ -1,29 +1,13 @@
import { Request, Response, Router } from 'express';
// @ts-ignore
import Model from '../../../noco-models/Model';
// @ts-ignore
import { PagedResponseImpl } from '../helpers/PagedResponse';
import { GalleryType, TableListType, ViewTypes } from 'nocodb-sdk';
// @ts-ignore
import ProjectMgrv2 from '../../../sqlMgr/v2/ProjectMgrv2';
// @ts-ignore
import Project from '../../../noco-models/Project';
import { GalleryType, ViewTypes } from 'nocodb-sdk';
import View from '../../../noco-models/View';
import GalleryView from '../../../noco-models/GalleryView';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { Tele } from 'nc-help';
// @ts-ignore
export async function galleryViewGet(req: Request, res: Response<GalleryType>) {
res.json(await GalleryView.get(req.params.galleryViewId));
}
// @ts-ignore
export async function galleyViewList(
_req: Request<any, any, any>,
_res: Response<TableListType>
) {}
// @ts-ignore
export async function galleryViewCreate(req: Request<any, any>, res) {
Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'gallery' });
const view = await View.insert({
@ -35,29 +19,22 @@ export async function galleryViewCreate(req: Request<any, any>, res) {
res.json(view);
}
// @ts-ignore
export async function galleryViewUpdate(req, res) {
Tele.emit('evt', { evt_type: 'view:updated', type: 'gallery' });
res.json(await GalleryView.update(req.params.galleryViewId, req.body));
}
// @ts-ignore
export async function galleyViewDelete(req: Request, res: Response, next) {}
const router = Router({ mergeParams: true });
// router.get('/', galleyViewList);
router.post(
'/tables/:tableId/galleries',
'/api/v1/db/meta/tables/:tableId/galleries',
ncMetaAclMw(galleryViewCreate, 'galleryViewCreate')
);
// router.get('/:galleryViewId', galleyViewGet);
router.put(
'/galleries/:galleryViewId',
router.patch(
'/api/v1/db/meta/galleries/:galleryViewId',
ncMetaAclMw(galleryViewUpdate, 'galleryViewUpdate')
);
router.get(
'/galleries/:galleryViewId',
'/api/v1/db/meta/galleries/:galleryViewId',
ncMetaAclMw(galleryViewGet, 'galleryViewGet')
);
// router.delete('/:galleryViewId', galleyViewDelete);
export default router;

2
packages/nocodb/src/lib/noco/meta/api/gridViewApis.ts

@ -26,7 +26,7 @@ export async function gridViewCreate(req: Request<any, any>, res) {
const router = Router({ mergeParams: true });
router.post(
'/tables/:tableId/grids/',
'/api/v1/db/meta/tables/:tableId/grids/',
ncMetaAclMw(gridViewCreate, 'gridViewCreate')
);
export default router;

6
packages/nocodb/src/lib/noco/meta/api/gridViewColumnApis.ts

@ -14,11 +14,11 @@ export async function gridColumnUpdate(req: Request, res: Response) {
const router = Router({ mergeParams: true });
router.get(
'/grid/:gridViewId/gridColumns',
'/api/v1/db/meta/grids/:gridViewId/grid/columns',
ncMetaAclMw(columnList, 'columnList')
);
router.put(
'/gridColumns/:gridViewColumnId',
router.patch(
'/api/v1/db/meta/grid/columns/:gridViewColumnId',
ncMetaAclMw(gridColumnUpdate, 'gridColumnUpdate')
);
export default router;

27
packages/nocodb/src/lib/noco/meta/api/hookApis.ts

@ -75,13 +75,28 @@ export async function tableSampleData(req: Request, res: Response) {
}
const router = Router({ mergeParams: true });
router.get('/tables/:tableId/hooks', ncMetaAclMw(hookList, 'hookList'));
router.post('/tables/:tableId/hooks/test', ncMetaAclMw(hookTest, 'hookTest'));
router.post('/tables/:tableId/hooks', ncMetaAclMw(hookCreate, 'hookCreate'));
router.delete('/hooks/:hookId', ncMetaAclMw(hookDelete, 'hookDelete'));
router.put('/hooks/:hookId', ncMetaAclMw(hookUpdate, 'hookUpdate'));
router.get(
'/tables/:tableId/hooks/samplePayload/:operation',
'/api/v1/db/meta/tables/:tableId/hooks',
ncMetaAclMw(hookList, 'hookList')
);
router.post(
'/api/v1/db/meta/tables/:tableId/hooks/test',
ncMetaAclMw(hookTest, 'hookTest')
);
router.post(
'/api/v1/db/meta/tables/:tableId/hooks',
ncMetaAclMw(hookCreate, 'hookCreate')
);
router.delete(
'/api/v1/db/meta/hooks/:hookId',
ncMetaAclMw(hookDelete, 'hookDelete')
);
router.patch(
'/api/v1/db/meta/hooks/:hookId',
ncMetaAclMw(hookUpdate, 'hookUpdate')
);
router.get(
'/api/v1/db/meta/tables/:tableId/hooks/samplePayload/:operation',
catchError(tableSampleData)
);
export default router;

2
packages/nocodb/src/lib/noco/meta/api/hookFilterApis.ts

@ -117,7 +117,7 @@ router.get(
'/hooks/:hookId/filters/:filterId',
ncMetaAclMw(filterGet, 'filterGet')
);
router.put(
router.patch(
'/hooks/:hookId/filters/:filterId',
ncMetaAclMw(filterUpdate, 'filterUpdate')
);

7
packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts

@ -826,9 +826,12 @@ export async function extractAndGenerateManyToManyRelations(
}
const router = Router();
router.get('/projects/:projectId/metaDiff', ncMetaAclMw(metaDiff, 'metaDiff'));
router.get(
'/api/v1/db/meta/projects/:projectId/metaDiff',
ncMetaAclMw(metaDiff, 'metaDiff')
);
router.post(
'/projects/:projectId/metaDiff',
'/api/v1/db/meta/projects/:projectId/metaDiff',
ncMetaAclMw(metaDiffSync, 'metaDiffSync')
);
export default router;

2
packages/nocodb/src/lib/noco/meta/api/modelVisibilityApis.ts

@ -119,7 +119,7 @@ router.get(
}, 'modelVisibilityList')
);
router.post(
'/projects/:projectId/modelVisibility',
'/api/v1/db/meta/projects/:projectId/visibility-rules',
ncMetaAclMw(xcVisibilityMetaSetAll, 'modelVisibilitySet')
);
export default router;

22
packages/nocodb/src/lib/noco/meta/api/pluginApis.ts

@ -34,9 +34,21 @@ export async function isPluginActive(req: Request, res: Response) {
}
const router = Router({ mergeParams: true });
router.get('/plugins', ncMetaAclMw(pluginList, 'pluginList'));
router.post('/plugins/test', ncMetaAclMw(pluginTest, 'pluginTest'));
router.get('/plugins/:pluginId', ncMetaAclMw(pluginRead, 'pluginRead'));
router.put('/plugins/:pluginId', ncMetaAclMw(pluginUpdate, 'pluginUpdate'));
router.get('/plugins/:pluginTitle/status', ncMetaAclMw(isPluginActive, 'isPluginActive'));
router.get('/api/v1/db/meta/plugins', ncMetaAclMw(pluginList, 'pluginList'));
router.post(
'/api/v1/db/meta/plugins/test',
ncMetaAclMw(pluginTest, 'pluginTest')
);
router.get(
'/api/v1/db/meta/plugins/:pluginId',
ncMetaAclMw(pluginRead, 'pluginRead')
);
router.patch(
'/api/v1/db/meta/plugins/:pluginId',
ncMetaAclMw(pluginUpdate, 'pluginUpdate')
);
router.get(
'/api/v1/db/meta/plugins/:pluginTitle/status',
ncMetaAclMw(isPluginActive, 'isPluginActive')
);
export default router;

19
packages/nocodb/src/lib/noco/meta/api/projectApis.ts

@ -392,14 +392,23 @@ export async function projectInfoGet(req, res) {
export default router => {
router.get(
'/projects/:projectId/info',
'/api/v1/db/meta/projects/:projectId/info',
ncMetaAclMw(projectInfoGet, 'projectInfoGet')
);
router.get('/projects/:projectId', ncMetaAclMw(projectGet, 'projectGet'));
router.get(
'/api/v1/db/meta/projects/:projectId',
ncMetaAclMw(projectGet, 'projectGet')
);
router.delete(
'/projects/:projectId',
'/api/v1/db/meta/projects/:projectId',
ncMetaAclMw(projectDelete, 'projectDelete')
);
router.post('/projects', ncMetaAclMw(projectCreate, 'projectCreate'));
router.get('/projects', ncMetaAclMw(projectList, 'projectList'));
router.post(
'/api/v1/db/meta/projects',
ncMetaAclMw(projectCreate, 'projectCreate')
);
router.get(
'/api/v1/db/meta/projects',
ncMetaAclMw(projectList, 'projectList')
);
};

2
packages/nocodb/src/lib/noco/meta/api/projectUserApis.ts

@ -254,7 +254,7 @@ router.post(
'/projects/:projectId/users',
ncMetaAclMw(userInvite, 'userInvite')
);
router.put(
router.patch(
'/projects/:projectId/users/:userId',
ncMetaAclMw(projectUserUpdate, 'projectUserUpdate')
);

2
packages/nocodb/src/lib/noco/meta/api/publicApis/publicDataApis.ts

@ -332,7 +332,7 @@ export async function publicHmList(req: Request, res: Response) {
const router = Router({ mergeParams: true });
router.post('/public/data/:publicDataUuid/list', catchError(dataList));
router.post(
'/public/data/:publicDataUuid/relationTable/:columnId',
'/public/data/:publicDataUuid/nested/:columnId',
catchError(relDataList)
);
router.post(

22
packages/nocodb/src/lib/noco/meta/api/publicApis/publicMetaApis.ts

@ -6,12 +6,13 @@ import UITypes from '../../../../sqlUi/UITypes';
import { ErrorMessages, LinkToAnotherRecordType } from 'nocodb-sdk';
import Column from '../../../../noco-models/Column';
import Base from '../../../../noco-models/Base';
import Project from '../../../../noco-models/Project';
export async function viewMetaGet(req: Request, res: Response) {
const view: View & {
relatedMetas?: { [ket: string]: Model };
client?: string;
} = await View.getByUUID(req.params.publicDataUuid);
} = await View.getByUUID(req.params.sharedViewUuids);
if (!view) NcError.notFound('Not found');
@ -66,7 +67,24 @@ export async function viewMetaGet(req: Request, res: Response) {
res.json(view);
}
async function publicSharedBaseGet(req, res): Promise<any> {
const project = await Project.getByUuid(req.params.sharedBaseUuid);
if (!project) {
NcError.notFound();
}
res.json({ project_id: project.id });
}
const router = Router({ mergeParams: true });
router.post('/public/meta/:publicDataUuid/', catchError(viewMetaGet));
router.post(
'/api/v1/db/meta/public/shared-view/:sharedViewUuid/meta',
catchError(viewMetaGet)
);
router.get(
'/api/v1/db/meta/public/shared-base/:sharedBaseUuid/meta',
catchError(publicSharedBaseGet)
);
export default router;

22
packages/nocodb/src/lib/noco/meta/api/sharedBaseApis.ts

@ -3,7 +3,7 @@ import ncMetaAclMw from '../helpers/ncMetaAclMw';
import { v4 as uuidv4 } from 'uuid';
import { Tele } from 'nc-help';
import Project from '../../../noco-models/Project';
import catchError, { NcError } from '../helpers/catchError';
import { NcError } from '../helpers/catchError';
// todo: load from config
const config = {
dashboardPath: '/nc'
@ -88,32 +88,22 @@ async function getSharedBaseLink(req, res): Promise<any> {
res.json(data);
}
async function publicSharedBaseGet(req, res): Promise<any> {
const project = await Project.getByUuid(req.params.uuid);
if (!project) {
NcError.notFound();
}
res.json({ project_id: project.id });
}
const router = Router({ mergeParams: true });
router.get(
'/projects/:projectId/sharedBase',
'/api/v1/db/meta/projects/:projectId/shared',
ncMetaAclMw(getSharedBaseLink, 'getSharedBaseLink')
);
router.post(
'/projects/:projectId/sharedBase',
'/api/v1/db/meta/projects/:projectId/shared',
ncMetaAclMw(createSharedBaseLink, 'createSharedBaseLink')
);
router.put(
'/projects/:projectId/sharedBase',
router.patch(
'/api/v1/db/meta/projects/:projectId/shared',
ncMetaAclMw(updateSharedBaseLink, 'updateSharedBaseLink')
);
router.delete(
'/projects/:projectId/sharedBase',
'/api/v1/db/meta/projects/:projectId/shared',
ncMetaAclMw(disableSharedBaseLink, 'disableSharedBaseLink')
);
router.get('/public/sharedBase/:uuid', catchError(publicSharedBaseGet));
export default router;

24
packages/nocodb/src/lib/noco/meta/api/sortApis.ts

@ -36,30 +36,34 @@ export async function sortCreate(req: Request<any, any, TableReqType>, res) {
res.json(sort);
}
// @ts-ignore
export async function sortUpdate(req, res, next) {
export async function sortUpdate(req, res) {
const sort = await Sort.update(req.params.sortId, req.body);
Tele.emit('evt', { evt_type: 'sort:updated' });
res.json(sort);
}
// @ts-ignore
export async function sortDelete(req: Request, res: Response, next) {
export async function sortDelete(req: Request, res: Response) {
Tele.emit('evt', { evt_type: 'sort:deleted' });
const sort = await Sort.delete(req.params.sortId);
res.json(sort);
}
const router = Router({ mergeParams: true });
router.get('/views/:viewId/sorts/', ncMetaAclMw(sortList, 'sortList'));
router.post('/views/:viewId/sorts/', ncMetaAclMw(sortCreate, 'sortCreate'));
router.get('/views/:viewId/sorts/:sortId', ncMetaAclMw(sortGet, 'sortGet'));
router.put(
'/views/:viewId/sorts/:sortId',
router.get(
'/api/v1/db/meta/views/:viewId/sorts/',
ncMetaAclMw(sortList, 'sortList')
);
router.post(
'/api/v1/db/meta/views/:viewId/sorts/',
ncMetaAclMw(sortCreate, 'sortCreate')
);
router.get('/api/v1/db/meta/sorts/:sortId', ncMetaAclMw(sortGet, 'sortGet'));
router.patch(
'/api/v1/db/meta/sorts/:sortId',
ncMetaAclMw(sortUpdate, 'sortUpdate')
);
router.delete(
'/views/:viewId/sorts/:sortId',
'/api/v1/db/meta/sorts/:sortId',
ncMetaAclMw(sortDelete, 'sortDelete')
);
export default router;

21
packages/nocodb/src/lib/noco/meta/api/tableApis.ts

@ -223,18 +223,27 @@ export async function tableDelete(req: Request, res: Response, next) {
const router = Router({ mergeParams: true });
router.get(
'/projects/:projectId/:baseId/tables',
'/api/v1/db/meta/projects/:projectId/tables',
ncMetaAclMw(tableList, 'tableList')
);
router.post(
'/projects/:projectId/:baseId/tables',
'/api/v1/db/meta/projects/:projectId/tables',
ncMetaAclMw(tableCreate, 'tableCreate')
);
router.get('/tables/:tableId', ncMetaAclMw(tableGet, 'tableGet'));
router.put('/tables/:tableId', ncMetaAclMw(tableUpdate, 'tableUpdate'));
router.delete('/tables/:tableId', ncMetaAclMw(tableDelete, 'tableDelete'));
router.get(
'/api/v1/db/meta/tables/:tableId',
ncMetaAclMw(tableGet, 'tableGet')
);
router.patch(
'/api/v1/db/meta/tables/:tableId',
ncMetaAclMw(tableUpdate, 'tableUpdate')
);
router.delete(
'/api/v1/db/meta/tables/:tableId',
ncMetaAclMw(tableDelete, 'tableDelete')
);
router.post(
'/tables/:tableId/reorder',
'/api/v1/db/meta/tables/:tableId/reorder',
ncMetaAclMw(tableReorder, 'tableReorder')
);
export default router;

7
packages/nocodb/src/lib/noco/meta/api/userApi/initStrategies.ts

@ -10,9 +10,7 @@ import { Strategy as AuthTokenStrategy } from 'passport-auth-token';
const PassportLocalStrategy = require('passport-local').Strategy;
// todo: read from database
const jwtOptions = {
secretOrKey: 'dkjfkdjfkjdfjdfjdkfjdkfjkdfkjdkfjdkjfkdk',
expiresIn: process.env.NC_JWT_EXPIRES_IN ?? '10h',
jwtFromRequest: ExtractJwt.fromHeader('xc-auth')
};
@ -22,6 +20,7 @@ import Project from '../../../../noco-models/Project';
import NocoCache from '../../../../noco-cache/NocoCache';
import { CacheGetType, CacheScope } from '../../../../utils/globals';
import ApiToken from '../../../../noco-models/ApiToken';
import Noco from '../../../Noco';
export function initStrategies(router): void {
passport.use(
@ -82,8 +81,10 @@ export function initStrategies(router): void {
passport.use(
new Strategy(
{
secretOrKey: Noco.getConfig().auth.jwt.secret,
...jwtOptions,
passReqToCallback: true
passReqToCallback: true,
...Noco.getConfig().auth.jwt.options
},
async (req, jwtPayload, done) => {
const keyVals = [jwtPayload?.email];

51
packages/nocodb/src/lib/noco/meta/api/userApi/userApis.ts

@ -15,10 +15,6 @@ import Audit from '../../../../noco-models/Audit';
import crypto from 'crypto';
import NcPluginMgrv2 from '../../helpers/NcPluginMgrv2';
// todo: read from database
const secret = 'dkjfkdjfkjdfjdfjdkfjdkfjkdfkjdkfjdkjfkdk';
const jwtConfig = {};
import passport from 'passport';
import extractProjectIdAndAuthenticate from '../../helpers/extractProjectIdAndAuthenticate';
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
@ -154,7 +150,8 @@ export async function signup(req: Request, res: Response<TableType>) {
id: user.id,
roles: user.roles
},
secret
Noco.getConfig().auth.jwt.secret,
Noco.getConfig().auth.jwt.options
)
} as any);
}
@ -200,8 +197,9 @@ async function signin(req, res, next) {
id: user.id,
roles: user.roles
},
secret,
jwtConfig
Noco.getConfig().auth.jwt.secret,
Noco.getConfig().auth.jwt.options
)
} as any);
} catch (e) {
@ -392,6 +390,44 @@ async function emailVerification(req, res): Promise<any> {
res.json({ msg: 'Email verified successfully' });
}
async function refreshToken(req, res): Promise<any> {
try {
if (!req?.cookies?.refresh_token) {
return res.status(400).json({ msg: 'Missing refresh token' });
}
const user = await User.getByRefreshToken(req.cookies.refresh_token);
if (!user) {
return res.status(400).json({ msg: 'Invalid refresh token' });
}
const refreshToken = randomTokenString();
await User.update(user.id, {
refresh_token: refreshToken
});
setTokenCookie(res, refreshToken);
res.json({
token: jwt.sign(
{
email: user.email,
firstname: user.firstname,
lastname: user.lastname,
id: user.id,
roles: user.roles
},
Noco.getConfig().auth.jwt.secret,
Noco.getConfig().auth.jwt.options
)
} as any);
} catch (e) {
return res.status(400).json({ msg: e.message });
}
}
const mapRoutes = router => {
// todo: old api - /auth/signup?tool=1
router.post('/auth/user/signup', catchError(signup));
@ -405,5 +441,6 @@ const mapRoutes = router => {
'/user/password/change',
ncMetaAclMw(passwordChange, 'passwordChange')
);
router.post('/auth/token/refresh', ncMetaAclMw(refreshToken, 'refreshToken'));
};
export { mapRoutes as userApis };

7
packages/nocodb/src/lib/noco/meta/api/utilApis.ts

@ -44,6 +44,9 @@ export async function appInfo(_req: Request, res: Response) {
}
export default router => {
router.post('/testConnection', ncMetaAclMw(testConnection, 'testConnection'));
router.get('/appInfo', catchError(appInfo));
router.post(
'/api/v1/db/meta/connection/test',
ncMetaAclMw(testConnection, 'testConnection')
);
router.get('/api/v1/db/meta/nocodb/info', catchError(appInfo));
};

32
packages/nocodb/src/lib/noco/meta/api/viewApis.ts

@ -101,29 +101,41 @@ async function shareViewList(req: Request<any, any>, res) {
}
const router = Router({ mergeParams: true });
router.get('/tables/:tableId/views', ncMetaAclMw(viewList, 'viewList'));
router.put('/views/:viewId', ncMetaAclMw(viewUpdate, 'viewUpdate'));
router.delete('/views/:viewId', ncMetaAclMw(viewDelete, 'viewDelete'));
router.get(
'/api/v1/db/meta/tables/:tableId/views',
ncMetaAclMw(viewList, 'viewList')
);
router.patch(
'/api/v1/db/meta/views/:viewId',
ncMetaAclMw(viewUpdate, 'viewUpdate')
);
router.delete(
'/api/v1/db/meta/views/:viewId',
ncMetaAclMw(viewDelete, 'viewDelete')
);
router.post(
'/views/:viewId/showAll',
'/api/v1/db/meta/views/:viewId/showAll',
ncMetaAclMw(showAllColumns, 'showAllColumns')
);
router.post(
'/views/:viewId/hideAll',
'/api/v1/db/meta/views/:viewId/hideAll',
ncMetaAclMw(hideAllColumns, 'hideAllColumns')
);
router.get(
'/tables/:tableId/share',
'/api/v1/db/meta/tables/:tableId/share',
ncMetaAclMw(shareViewList, 'shareViewList')
);
router.post('/views/:viewId/share', ncMetaAclMw(shareView, 'shareView'));
router.put(
'/views/:viewId/share',
router.post(
'/api/v1/db/meta/views/:viewId/share',
ncMetaAclMw(shareView, 'shareView')
);
router.patch(
'/api/v1/db/meta/views/:viewId/share',
ncMetaAclMw(shareViewPasswordUpdate, 'shareViewPasswordUpdate')
);
router.delete(
'/views/:viewId/share',
'/api/v1/db/meta/views/:viewId/share',
ncMetaAclMw(shareViewDelete, 'shareViewDelete')
);

14
packages/nocodb/src/lib/noco/meta/api/viewColumnApis.ts

@ -31,10 +31,16 @@ export async function columnUpdate(req: Request, res: Response) {
}
const router = Router({ mergeParams: true });
router.get('/views/:viewId/columns/', ncMetaAclMw(columnList, 'columnList'));
router.post('/views/:viewId/columns/', ncMetaAclMw(columnAdd, 'columnAdd'));
router.put(
'/views/:viewId/columns/:columnId',
router.get(
'/api/v1/db/meta/views/:viewId/columns/',
ncMetaAclMw(columnList, 'columnList')
);
router.post(
'/api/v1/db/meta/views/:viewId/columns/',
ncMetaAclMw(columnAdd, 'columnAdd')
);
router.patch(
'/api/v1/db/meta/views/:viewId/columns/:columnId',
ncMetaAclMw(columnUpdate, 'viewColumnUpdate')
);
export default router;

2186
scripts/sdk/swagger.json

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save