Browse Source

feat: nestedList api to list

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/350/head
Pranav C 3 years ago
parent
commit
a1ddd5cba8
  1. 2
      packages/nc-gui/components/project/spreadsheet/apis/restApi.js
  2. 39
      packages/nocodb/src/lib/noco/rest/RestCtrl.ts
  3. 25
      packages/nocodb/src/lib/sqlMgr/code/routers/xc-ts/SwaggerXc.ts
  4. 19
      packages/nocodb/src/lib/sqlMgr/code/routes/xc-ts/ExpressXcTsRoutes.ts

2
packages/nc-gui/components/project/spreadsheet/apis/restApi.js

@ -8,7 +8,7 @@ export default class RestApi {
// todo: - get version letter and use table alias
async list(params) {
// const data = await this.get(`/nc/${this.$ctx.$route.params.project_id}/api/v1/${this.table}`, params)
const data = await this.get(`/nc/${this.$ctx.$route.params.project_id}/api/v1/${this.table}/nestedList`, params)
const data = await this.get(`/nc/${this.$ctx.$route.params.project_id}/api/v1/${this.table}`, params)
return data.data;
}

39
packages/nocodb/src/lib/noco/rest/RestCtrl.ts

@ -44,14 +44,14 @@ export class RestCtrl extends RestBaseCtrl {
return this.acls?.[this.table];
}
public async list(req: Request | any, res): Promise<void> {
const startTime = process.hrtime();
const data = await req.model.list(req.query);
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds);
res.xcJson(data);
}
// public async list(req: Request | any, res): Promise<void> {
// const startTime = process.hrtime();
//
// const data = await req.model.list(req.query);
// const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
// res.setHeader('xc-db-response', elapsedSeconds);
// res.xcJson(data);
// }
public async create(req: Request | any, res: Response): Promise<void> {
const data = await req.model.insert(req.body, null, req);
@ -139,6 +139,28 @@ export class RestCtrl extends RestBaseCtrl {
res.json(data);
}
public async list(req: Request | any, res): Promise<void> {
const startTime = process.hrtime();
try {
if (req.query.conditionGraph && typeof req.query.conditionGraph === 'string') {
req.query.conditionGraph = {models: this.models, condition: JSON.parse(req.query.conditionGraph)}
}
if (req.query.condition && typeof req.query.condition === 'string') {
req.query.condition = JSON.parse(req.query.condition)
}
}catch (e){
/* ignore parse error */
}
const data = await req.model.nestedList({
...req.query
} as any);
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds);
res.xcJson(data);
}
public async nestedList(req: Request | any, res): Promise<void> {
const startTime = process.hrtime();
@ -161,6 +183,7 @@ export class RestCtrl extends RestBaseCtrl {
res.xcJson(data);
}
public async m2mNotChildren(req: Request | any, res): Promise<void> {
const startTime = process.hrtime();

25
packages/nocodb/src/lib/sqlMgr/code/routers/xc-ts/SwaggerXc.ts

@ -12,7 +12,7 @@ class SwaggerXc extends BaseRender {
* @param ctx.columns
* @param ctx.relations
*/
constructor({dir, filename, ctx}:any) {
constructor({dir, filename, ctx}: any) {
super({dir, filename, ctx});
}
@ -22,8 +22,7 @@ class SwaggerXc extends BaseRender {
prepare() {
let data :any= {
};
let data: any = {};
/* example of simple variable */
data = this.ctx;
@ -70,7 +69,7 @@ class SwaggerXc extends BaseRender {
const properties = obj[args._tn].properties;
for (let column of args.columns) {
const field:any = {};
const field: any = {};
SwaggerTypes.setSwaggerType(column, field, args.dbType)
@ -149,6 +148,24 @@ class SwaggerXc extends BaseRender {
"type": "String",
"description": "Comma separated fields from the model"
},
{
"in": "query",
"name": "parents",
"type": "String",
"description": "Comma separated parent table names(Belongs To)"
},
{
"in": "query",
"name": "childs",
"type": "String",
"description": "Comma separated child table names(Has Many)"
},
{
"in": "query",
"name": "many",
"type": "String",
"description": "Comma separated child table names(Many to Many)"
},
{
"in": "query",
"name": "where",

19
packages/nocodb/src/lib/sqlMgr/code/routes/xc-ts/ExpressXcTsRoutes.ts

@ -65,23 +65,6 @@ async function(req, res){
}
`]
}, {
path: `/api/${this.ctx.routeVersionLetter}/${ejsData._tn}/nestedList`,
type: 'get',
handler: ['nestedList'],
acl: {
admin: true,
user: true,
guest: true
},
functions: [`
async function(req, res){
const data = await req.parentModel.hasManyList({
...req.query
});
res.json(data);
}
`]
},, {
path: `/api/${this.ctx.routeVersionLetter}/${ejsData._tn}/m2mNotChildren/:assoc/:pid`,
type: 'get',
handler: ['m2mNotChildren'],
@ -327,7 +310,7 @@ async function(req, res){
}
getObjectWithoutFunctions() {
getObjectWithoutFunctions() {
return this.getObject().map(({functions, ...rest}) => rest)
}
}

Loading…
Cancel
Save