Browse Source

fix: exist api correction

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

9
packages/nocodb-nest/src/db/BaseModelSqlv2.ts

@ -181,11 +181,18 @@ class BaseModelSqlv2 {
public async exist(id?: any): Promise<any> { public async exist(id?: any): Promise<any> {
const qb = this.dbDriver(this.tnPath); const qb = this.dbDriver(this.tnPath);
await this.model.getColumns();
const pks = this.model.primaryKeys; const pks = this.model.primaryKeys;
if(!pks.length) return false;
qb.select(pks[0].column_name)
if ((id + '').split('___').length != pks?.length) { if ((id + '').split('___').length != pks?.length) {
return false; return false;
} }
return !!(await qb.where(_wherePk(pks, id)).first()); qb.where(_wherePk(pks, id)).first()
return !!(await qb);
} }
// todo: add support for sortArrJson // todo: add support for sortArrJson

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

@ -2,27 +2,27 @@ import {
Body, Body,
Controller, Controller,
Delete, Delete,
Get, HttpCode, Get,
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);
res.json(groupedData) res.json(groupedData);
} }
} }

Loading…
Cancel
Save