Browse Source

fix: grouped data api response

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
d6438e7f53
  1. 56
      packages/nocodb-nest/src/modules/datas/data-alias.controller.ts

56
packages/nocodb-nest/src/modules/datas/data-alias.controller.ts

@ -2,27 +2,27 @@ import {
Body, Body,
Controller, Controller,
Delete, Delete,
Get, Get, HttpCode,
HttpCode,
Param, Param,
Patch, Patch,
Post, Post,
Request, Request,
Response, Response,
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport'
import { parseHrtimeToSeconds } from '../../helpers'; import { parseHrtimeToSeconds } from '../../helpers'
import { import {
Acl, Acl,
ExtractProjectIdMiddleware, ExtractProjectIdMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware'; } from '../../middlewares/extract-project-id/extract-project-id.middleware'
import { DatasService } from './datas.service'; import { DatasService } from './datas.service'
@Controller() @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class DataAliasController { export class DataAliasController {
constructor(private readonly datasService: DatasService) {} constructor(private readonly datasService: DatasService) {
}
// todo: Handle the error case where view doesnt belong to model // todo: Handle the error case where view doesnt belong to model
@Get([ @Get([
@ -37,16 +37,16 @@ export class DataAliasController {
@Param('tableName') tableName: string, @Param('tableName') tableName: string,
@Param('viewName') viewName: string, @Param('viewName') viewName: string,
) { ) {
const startTime = process.hrtime(); const startTime = process.hrtime()
const responseData = await this.datasService.dataList({ const responseData = await this.datasService.dataList({
query: req.query, query: req.query,
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
}); })
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime)); const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime))
res.setHeader('xc-db-response', elapsedSeconds); res.setHeader('xc-db-response', elapsedSeconds)
res.json(responseData); res.json(responseData)
} }
@Get([ @Get([
@ -65,7 +65,7 @@ export class DataAliasController {
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
}); })
} }
@Get([ @Get([
@ -84,7 +84,7 @@ export class DataAliasController {
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
}); })
} }
@Get([ @Get([
@ -104,9 +104,9 @@ export class DataAliasController {
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
}); })
res.json(countResult); res.json(countResult)
} }
@Post([ @Post([
@ -128,7 +128,7 @@ export class DataAliasController {
viewName: viewName, viewName: viewName,
body: body, body: body,
cookie: req, cookie: req,
}); })
} }
@Patch([ @Patch([
@ -150,7 +150,7 @@ export class DataAliasController {
body: req.body, body: req.body,
cookie: req, cookie: req,
rowId: rowId, rowId: rowId,
}); })
} }
@Delete([ @Delete([
@ -171,7 +171,7 @@ export class DataAliasController {
viewName: viewName, viewName: viewName,
cookie: req, cookie: req,
rowId: rowId, rowId: rowId,
}); })
} }
@Get([ @Get([
@ -192,7 +192,7 @@ export class DataAliasController {
viewName: viewName, viewName: viewName,
rowId: rowId, rowId: rowId,
query: req.query, query: req.query,
}); })
} }
@Get([ @Get([
@ -214,9 +214,9 @@ export class DataAliasController {
viewName: viewName, viewName: viewName,
rowId: rowId, rowId: rowId,
query: req.query, query: req.query,
}); })
res.json(exists); res.json(exists)
} }
// todo: Handle the error case where view doesnt belong to model // todo: Handle the error case where view doesnt belong to model
@ -234,16 +234,16 @@ export class DataAliasController {
@Param('viewName') viewName: string, @Param('viewName') viewName: string,
@Param('columnId') columnId: string, @Param('columnId') columnId: string,
) { ) {
const startTime = process.hrtime(); const startTime = process.hrtime()
const groupedData = await this.datasService.groupedDataList({ const groupedData = await this.datasService.groupedDataList({
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
query: req.query, query: req.query,
columnId: columnId, columnId: columnId,
}); })
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime)); const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime))
res.setHeader('xc-db-response', elapsedSeconds); res.setHeader('xc-db-response', elapsedSeconds)
return groupedData; res.json(groupedData)
} }
} }

Loading…
Cancel
Save