Browse Source

fix: exist api response correction

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

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

@ -181,9 +181,8 @@ 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.selectObject({ qb });
const pks = this.model.primaryKeys; const pks = this.model.primaryKeys;
if ((id + '').split('___').length != pks.length) { if ((id + '').split('___').length != pks?.length) {
return false; return false;
} }
return !!(await qb.where(_wherePk(pks, id)).first()); return !!(await qb.where(_wherePk(pks, id)).first());

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

@ -1,11 +1,13 @@
import { import {
Body, Body,
Controller, Controller,
Delete, HttpCode, Delete,
HttpCode,
Param, Param,
Patch, Patch,
Post, Post,
Request, Request,
Response,
UseGuards, UseGuards,
} from '@nestjs/common' } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@ -25,16 +27,19 @@ export class BulkDataAliasController {
@Acl('bulkDataInsert') @Acl('bulkDataInsert')
async bulkDataInsert( async bulkDataInsert(
@Request() req, @Request() req,
@Response() res,
@Param('projectName') projectName: string, @Param('projectName') projectName: string,
@Param('tableName') tableName: string, @Param('tableName') tableName: string,
@Body() body: any, @Body() body: any,
) { ) {
return await this.bulkDataAliasService.bulkDataInsert({ const exists = await this.bulkDataAliasService.bulkDataInsert({
body: body, body: body,
cookie: req, cookie: req,
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
}); });
res.json(exists);
} }
@Patch('/api/v1/db/data/bulk/:orgs/:projectName/:tableName') @Patch('/api/v1/db/data/bulk/:orgs/:projectName/:tableName')

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

@ -2,14 +2,15 @@ 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 {
@ -201,18 +202,21 @@ export class DataAliasController {
@Acl('dataExist') @Acl('dataExist')
async dataExist( async dataExist(
@Request() req, @Request() req,
@Response() res,
@Param('projectName') projectName: string, @Param('projectName') projectName: string,
@Param('tableName') tableName: string, @Param('tableName') tableName: string,
@Param('viewName') viewName: string, @Param('viewName') viewName: string,
@Param('rowId') rowId: string, @Param('rowId') rowId: string,
) { ) {
return await this.datasService.dataExist({ const exists = await this.datasService.dataExist({
projectName: projectName, projectName: projectName,
tableName: tableName, tableName: tableName,
viewName: viewName, viewName: viewName,
rowId: rowId, rowId: rowId,
query: req.query, query: req.query,
}); });
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

4
packages/nocodb-nest/src/modules/datas/datas.module.ts

@ -12,12 +12,12 @@ import { OldDatasService } from './old-datas/old-datas.service';
@Module({ @Module({
controllers: [ controllers: [
DataAliasController,
DatasController, DatasController,
BulkDataAliasController, BulkDataAliasController,
DataAliasController,
DataAliasNestedController,
DataAliasExportController, DataAliasExportController,
OldDatasController, OldDatasController,
DataAliasNestedController,
], ],
providers: [ providers: [
DatasService, DatasService,

Loading…
Cancel
Save