mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
5 changed files with 0 additions and 910 deletions
@ -1,91 +0,0 @@ |
|||||||
import { Request, Response, Router } from 'express'; |
|
||||||
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; |
|
||||||
import apiMetrics from '../../meta/helpers/apiMetrics'; |
|
||||||
import { bulkDataService } from '../../services'; |
|
||||||
|
|
||||||
async function bulkDataInsert(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await bulkDataService.bulkDataInsert({ |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function bulkDataUpdate(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await bulkDataService.bulkDataUpdate({ |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
|
||||||
async function bulkDataUpdateAll(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await bulkDataService.bulkDataUpdateAll({ |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function bulkDataDelete(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await bulkDataService.bulkDataDelete({ |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
// todo: Integrate with filterArrJson bulkDataDeleteAll
|
|
||||||
async function bulkDataDeleteAll(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await bulkDataService.bulkDataDeleteAll({ |
|
||||||
// cookie: req,
|
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
const router = Router({ mergeParams: true }); |
|
||||||
|
|
||||||
router.post( |
|
||||||
'/api/v1/db/data/bulk/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(bulkDataInsert, 'bulkDataInsert') |
|
||||||
); |
|
||||||
router.patch( |
|
||||||
'/api/v1/db/data/bulk/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(bulkDataUpdate, 'bulkDataUpdate') |
|
||||||
); |
|
||||||
router.patch( |
|
||||||
'/api/v1/db/data/bulk/:orgs/:projectName/:tableName/all', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(bulkDataUpdateAll, 'bulkDataUpdateAll') |
|
||||||
); |
|
||||||
router.delete( |
|
||||||
'/api/v1/db/data/bulk/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(bulkDataDelete, 'bulkDataDelete') |
|
||||||
); |
|
||||||
router.delete( |
|
||||||
'/api/v1/db/data/bulk/:orgs/:projectName/:tableName/all', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(bulkDataDeleteAll, 'bulkDataDeleteAll') |
|
||||||
); |
|
||||||
|
|
||||||
export default router; |
|
@ -1,291 +0,0 @@ |
|||||||
import { Request, Response, Router } from 'express'; |
|
||||||
import Model from '../../models/Model'; |
|
||||||
import Base from '../../models/Base'; |
|
||||||
import NcConnectionMgrv2 from '../../utils/common/NcConnectionMgrv2'; |
|
||||||
import { PagedResponseImpl } from '../../meta/helpers/PagedResponse'; |
|
||||||
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; |
|
||||||
import { |
|
||||||
getColumnByIdOrName, |
|
||||||
getViewAndModelFromRequestByAliasOrId, |
|
||||||
} from '../dataApis/helpers'; |
|
||||||
import { NcError } from '../../meta/helpers/catchError'; |
|
||||||
import apiMetrics from '../../meta/helpers/apiMetrics'; |
|
||||||
|
|
||||||
// todo: handle case where the given column is not ltar
|
|
||||||
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 { 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.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 { 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.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 { 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.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, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
// todo: handle case where the given column is not ltar
|
|
||||||
export async function hmList(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.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, { |
|
||||||
count, |
|
||||||
...req.query, |
|
||||||
} as any) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//@ts-ignore
|
|
||||||
async function relationDataRemove(req, res) { |
|
||||||
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
||||||
|
|
||||||
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.refRowId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
cookie: req, |
|
||||||
}); |
|
||||||
|
|
||||||
res.json({ msg: 'success' }); |
|
||||||
} |
|
||||||
|
|
||||||
//@ts-ignore
|
|
||||||
// todo: Give proper error message when reference row is already related and handle duplicate ref row id in hm
|
|
||||||
async function relationDataAdd(req, res) { |
|
||||||
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
||||||
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.refRowId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
cookie: req, |
|
||||||
}); |
|
||||||
|
|
||||||
res.json({ msg: 'success' }); |
|
||||||
} |
|
||||||
|
|
||||||
const router = Router({ mergeParams: true }); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/mm/:columnName/exclude', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(mmExcludedList, 'mmExcludedList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/hm/:columnName/exclude', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(hmExcludedList, 'hmExcludedList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/bt/:columnName/exclude', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(btExcludedList, 'btExcludedList') |
|
||||||
); |
|
||||||
|
|
||||||
router.post( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/:relationType/:columnName/:refRowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(relationDataAdd, 'relationDataAdd') |
|
||||||
); |
|
||||||
router.delete( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/:relationType/:columnName/:refRowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(relationDataRemove, 'relationDataRemove') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/mm/:columnName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(mmList, 'mmList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/hm/:columnName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(hmList, 'hmList') |
|
||||||
); |
|
||||||
|
|
||||||
export default router; |
|
@ -1,75 +0,0 @@ |
|||||||
import { Request, Response, Router } from 'express'; |
|
||||||
import * as XLSX from 'xlsx'; |
|
||||||
import { getViewAndModelFromRequestByAliasOrId } from '../../meta/api/dataApis/helpers'; |
|
||||||
import apiMetrics from '../../meta/helpers/apiMetrics'; |
|
||||||
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; |
|
||||||
import { View } from '../../models'; |
|
||||||
import { |
|
||||||
extractCsvData, |
|
||||||
extractXlsxData, |
|
||||||
} from '../../services/dataService/helpers'; |
|
||||||
|
|
||||||
async function excelDataExport(req: Request, res: Response) { |
|
||||||
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
||||||
let targetView = view; |
|
||||||
if (!targetView) { |
|
||||||
targetView = await View.getDefaultView(model.id); |
|
||||||
} |
|
||||||
const { offset, elapsed, data } = await extractXlsxData(targetView, req); |
|
||||||
const wb = XLSX.utils.book_new(); |
|
||||||
XLSX.utils.book_append_sheet(wb, data, targetView.title); |
|
||||||
const buf = XLSX.write(wb, { type: 'base64', bookType: 'xlsx' }); |
|
||||||
res.set({ |
|
||||||
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
||||||
'nc-export-offset': offset, |
|
||||||
'nc-export-elapsed-time': elapsed, |
|
||||||
'Content-Disposition': `attachment; filename="${encodeURI( |
|
||||||
targetView.title |
|
||||||
)}-export.xlsx"`,
|
|
||||||
}); |
|
||||||
res.end(buf); |
|
||||||
} |
|
||||||
|
|
||||||
async function csvDataExport(req: Request, res: Response) { |
|
||||||
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
||||||
let targetView = view; |
|
||||||
if (!targetView) { |
|
||||||
targetView = await View.getDefaultView(model.id); |
|
||||||
} |
|
||||||
const { offset, elapsed, data } = await extractCsvData(targetView, req); |
|
||||||
|
|
||||||
res.set({ |
|
||||||
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
||||||
'nc-export-offset': offset, |
|
||||||
'nc-export-elapsed-time': elapsed, |
|
||||||
'Content-Disposition': `attachment; filename="${encodeURI( |
|
||||||
targetView.title |
|
||||||
)}-export.csv"`,
|
|
||||||
}); |
|
||||||
res.send(data); |
|
||||||
} |
|
||||||
|
|
||||||
const router = Router({ mergeParams: true }); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/export/csv', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(csvDataExport, 'exportCsv') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/export/csv', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(csvDataExport, 'exportCsv') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/export/excel', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(excelDataExport, 'exportExcel') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/export/excel', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(excelDataExport, 'exportExcel') |
|
||||||
); |
|
||||||
|
|
||||||
export default router; |
|
@ -1,261 +0,0 @@ |
|||||||
import { Request, Response, Router } from 'express'; |
|
||||||
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; |
|
||||||
import apiMetrics from '../../meta/helpers/apiMetrics'; |
|
||||||
import { parseHrtimeToSeconds } from '../../meta/api/helpers'; |
|
||||||
|
|
||||||
import { dataService } from '../../services'; |
|
||||||
|
|
||||||
// todo: Handle the error case where view doesnt belong to model
|
|
||||||
async function dataList(req: Request, res: Response) { |
|
||||||
const startTime = process.hrtime(); |
|
||||||
const responseData = await dataService.dataList({ |
|
||||||
query: req.query, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
}); |
|
||||||
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime)); |
|
||||||
res.setHeader('xc-db-response', elapsedSeconds); |
|
||||||
res.json(responseData); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataFindOne(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataFindOne({ |
|
||||||
query: req.query, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataGroupBy(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataGroupBy({ |
|
||||||
query: req.query, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataCount(req: Request, res: Response) { |
|
||||||
const countResult = await dataService.dataCount({ |
|
||||||
query: req.query, |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
}); |
|
||||||
|
|
||||||
res.json(countResult); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataInsert(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataInsert({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataUpdate(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataUpdate({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
rowId: req.params.rowId, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataDelete(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataDelete({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
cookie: req, |
|
||||||
rowId: req.params.rowId, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataRead(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataRead({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataExist(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataExist({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
// todo: Handle the error case where view doesnt belong to model
|
|
||||||
async function groupedDataList(req: Request, res: Response) { |
|
||||||
const startTime = process.hrtime(); |
|
||||||
const groupedData = await dataService.groupedDataList({ |
|
||||||
projectName: req.params.projectName, |
|
||||||
tableName: req.params.tableName, |
|
||||||
viewName: req.params.viewName, |
|
||||||
query: req.query, |
|
||||||
columnId: req.params.columnId, |
|
||||||
}); |
|
||||||
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime)); |
|
||||||
res.setHeader('xc-db-response', elapsedSeconds); |
|
||||||
res.json(groupedData); |
|
||||||
} |
|
||||||
|
|
||||||
const router = Router({ mergeParams: true }); |
|
||||||
|
|
||||||
// table data crud apis
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataList, 'dataList') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/find-one', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataFindOne, 'dataFindOne') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/groupby', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataGroupBy, 'dataGroupBy') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/group/:columnId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(groupedDataList, 'groupedDataList') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/exist', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataExist, 'dataExist') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/count', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataCount, 'dataCount') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/count', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataCount, 'dataCount') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataRead, 'dataRead') |
|
||||||
); |
|
||||||
|
|
||||||
router.patch( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataUpdate, 'dataUpdate') |
|
||||||
); |
|
||||||
|
|
||||||
router.delete( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataDelete, 'dataDelete') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataList, 'dataList') |
|
||||||
); |
|
||||||
|
|
||||||
// table view data crud apis
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataList, 'dataList') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/find-one', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataFindOne, 'dataFindOne') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/groupby', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataGroupBy, 'dataGroupBy') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/group/:columnId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(groupedDataList, 'groupedDataList') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId/exist', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataExist, 'dataExist') |
|
||||||
); |
|
||||||
|
|
||||||
router.post( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataInsert, 'dataInsert') |
|
||||||
); |
|
||||||
|
|
||||||
router.post( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataInsert, 'dataInsert') |
|
||||||
); |
|
||||||
|
|
||||||
router.patch( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataUpdate, 'dataUpdate') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataRead, 'dataRead') |
|
||||||
); |
|
||||||
|
|
||||||
router.delete( |
|
||||||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataDelete, 'dataDelete') |
|
||||||
); |
|
||||||
|
|
||||||
export default router; |
|
@ -1,192 +0,0 @@ |
|||||||
import { Request, Response, Router } from 'express'; |
|
||||||
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; |
|
||||||
import apiMetrics from '../../meta/helpers/apiMetrics'; |
|
||||||
import { dataService } from '../../services'; |
|
||||||
|
|
||||||
export async function dataList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataListByViewId({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export async function mmList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.mmList({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export async function mmExcludedList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.mmExcludedList({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export async function hmExcludedList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.hmExcludedList({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export async function btExcludedList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.btExcludedList({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
export async function hmList(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.hmList({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataRead(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataReadByViewId({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
query: req.query, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataInsert(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataInsertByViewId({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataUpdate(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataUpdateByViewId({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
body: req.body, |
|
||||||
cookie: req, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function dataDelete(req: Request, res: Response) { |
|
||||||
res.json( |
|
||||||
await dataService.dataDeleteByViewId({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
cookie: req, |
|
||||||
}) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
async function relationDataDelete(req, res) { |
|
||||||
await dataService.relationDataDelete({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
childId: req.params.childId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
cookie: req, |
|
||||||
}); |
|
||||||
|
|
||||||
res.json({ msg: 'success' }); |
|
||||||
} |
|
||||||
|
|
||||||
//@ts-ignore
|
|
||||||
async function relationDataAdd(req, res) { |
|
||||||
await dataService.relationDataAdd({ |
|
||||||
viewId: req.params.viewId, |
|
||||||
colId: req.params.colId, |
|
||||||
childId: req.params.childId, |
|
||||||
rowId: req.params.rowId, |
|
||||||
cookie: req, |
|
||||||
}); |
|
||||||
|
|
||||||
res.json({ msg: 'success' }); |
|
||||||
} |
|
||||||
|
|
||||||
const router = Router({ mergeParams: true }); |
|
||||||
|
|
||||||
router.get('/data/:viewId/', apiMetrics, ncMetaAclMw(dataList, 'dataList')); |
|
||||||
router.post( |
|
||||||
'/data/:viewId/', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataInsert, 'dataInsert') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataRead, 'dataRead') |
|
||||||
); |
|
||||||
router.patch( |
|
||||||
'/data/:viewId/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataUpdate, 'dataUpdate') |
|
||||||
); |
|
||||||
router.delete( |
|
||||||
'/data/:viewId/:rowId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(dataDelete, 'dataDelete') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId/mm/:colId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(mmList, 'mmList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId/hm/:colId', |
|
||||||
apiMetrics, |
|
||||||
ncMetaAclMw(hmList, 'hmList') |
|
||||||
); |
|
||||||
|
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId/mm/:colId/exclude', |
|
||||||
ncMetaAclMw(mmExcludedList, 'mmExcludedList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId/hm/:colId/exclude', |
|
||||||
ncMetaAclMw(hmExcludedList, 'hmExcludedList') |
|
||||||
); |
|
||||||
router.get( |
|
||||||
'/data/:viewId/:rowId/bt/:colId/exclude', |
|
||||||
ncMetaAclMw(btExcludedList, 'btExcludedList') |
|
||||||
); |
|
||||||
|
|
||||||
router.post( |
|
||||||
'/data/:viewId/:rowId/:relationType/:colId/:childId', |
|
||||||
ncMetaAclMw(relationDataAdd, 'relationDataAdd') |
|
||||||
); |
|
||||||
router.delete( |
|
||||||
'/data/:viewId/:rowId/:relationType/:colId/:childId', |
|
||||||
ncMetaAclMw(relationDataDelete, 'relationDataDelete') |
|
||||||
); |
|
||||||
export default router; |
|
Loading…
Reference in new issue