Browse Source

feat: corrections and include viewId

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5901/head
Pranav C 2 years ago
parent
commit
a9e49ca909
  1. 5
      packages/nocodb/src/app.module.ts
  2. 6
      packages/nocodb/src/controllers/data-table.controller.ts
  3. 4
      packages/nocodb/src/modules/datas/datas.module.ts
  4. 58
      packages/nocodb/src/services/data-table.service.ts

5
packages/nocodb/src/app.module.ts

@ -19,9 +19,6 @@ import { MetasModule } from './modules/metas/metas.module';
import { JobsModule } from './modules/jobs/jobs.module';
import { AppInitService } from './services/app-init.service';
import type { MiddlewareConsumer } from '@nestjs/common';
import { DataTableController } from './controllers/data-table.controller';
import { DataTableController } from './servicess/data-table.controller';
import { DataTableService } from './services/data-table.service';
@Module({
imports: [
@ -41,7 +38,6 @@ import { DataTableService } from './services/data-table.service';
]
: []),
],
controllers: [DataTableController],
providers: [
AuthService,
{
@ -53,7 +49,6 @@ import { DataTableService } from './services/data-table.service';
BaseViewStrategy,
HookHandlerService,
AppInitService,
DataTableService,
],
})
export class AppModule {

6
packages/nocodb/src/controllers/data-table.controller.ts

@ -41,6 +41,7 @@ export class DataTableController {
query: req.query,
projectId: projectId,
modelId: modelId,
viewId: viewId,
});
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds);
@ -59,6 +60,7 @@ export class DataTableController {
const countResult = await this.dataTableService.dataCount({
query: req.query,
modelId,
viewId,
projectId,
});
@ -79,6 +81,7 @@ export class DataTableController {
projectId: projectId,
modelId: modelId,
body: body,
viewId,
cookie: req,
});
}
@ -97,6 +100,7 @@ export class DataTableController {
modelId: modelId,
body: req.body,
cookie: req,
viewId,
rowId: rowId,
});
}
@ -114,6 +118,7 @@ export class DataTableController {
projectId: projectId,
modelId: modelId,
cookie: req,
viewId,
rowId: rowId,
});
}
@ -132,6 +137,7 @@ export class DataTableController {
projectId,
rowId: rowId,
query: req.query,
viewId
});
}
}

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

@ -3,8 +3,10 @@ import { MulterModule } from '@nestjs/platform-express';
import multer from 'multer';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
import { DataAliasController } from '../../controllers/data-alias.controller';
import { DataTableController } from '../../controllers/data-table.controller';
import { PublicDatasExportController } from '../../controllers/public-datas-export.controller';
import { PublicDatasController } from '../../controllers/public-datas.controller';
import { DataTableService } from '../../services/data-table.service';
import { DatasService } from '../../services/datas.service';
import { DatasController } from '../../controllers/datas.controller';
import { BulkDataAliasController } from '../../controllers/bulk-data-alias.controller';
@ -27,6 +29,7 @@ import { PublicDatasService } from '../../services/public-datas.service';
}),
],
controllers: [
DataTableController,
DatasController,
BulkDataAliasController,
DataAliasController,
@ -37,6 +40,7 @@ import { PublicDatasService } from '../../services/public-datas.service';
PublicDatasExportController,
],
providers: [
DataTableService,
DatasService,
BulkDataAliasService,
DataAliasNestedService,

58
packages/nocodb/src/services/data-table.service.ts

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { NcError } from '../helpers/catchError';
import { Base, Model } from '../models';
import { Base, Model, View } from '../models';
import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2';
import { DatasService } from './datas.service';
@ -8,11 +8,17 @@ import { DatasService } from './datas.service';
export class DataTableService {
constructor(private datasService: DatasService) {}
async dataList(param: { projectId?: string; modelId: string; query: any }) {
const model = await this.getModelAndValidate(param);
async dataList(param: {
projectId?: string;
modelId: string;
query: any;
viewId?: string;
}) {
const { model, view } = await this.getModelAndView(param);
return await this.datasService.getDataList({
model,
view,
query: param.query,
});
}
@ -21,14 +27,16 @@ export class DataTableService {
projectId?: string;
modelId: string;
rowId: string;
viewId?: string;
query: any;
}) {
const model = await this.getModelAndValidate(param);
const { model, view } = await this.getModelAndView(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
@ -43,15 +51,17 @@ export class DataTableService {
async dataInsert(param: {
projectId?: string;
viewId?: string;
modelId: string;
body: any;
cookie: any;
}) {
const model = await this.getModelAndValidate(param);
const { model, view } = await this.getModelAndView(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
@ -61,16 +71,18 @@ export class DataTableService {
async dataUpdate(param: {
projectId?: string;
modelId: string;
viewId?: string;
rowId: string;
body: any;
cookie: any;
}) {
const model = await this.getModelAndValidate(param);
const { model, view } = await this.getModelAndView(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
@ -85,13 +97,15 @@ export class DataTableService {
async dataDelete(param: {
projectId?: string;
modelId: string;
viewId?: string;
rowId: string;
cookie: any;
}) {
const model = await this.getModelAndValidate(param);
const { model, view } = await this.getModelAndView(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
@ -103,27 +117,42 @@ export class DataTableService {
return await baseModel.delByPk(param.rowId, null, param.cookie);
}
private async getModelAndValidate(param: {
private async getModelAndView(param: {
projectId?: string;
viewId?: string;
modelId: string;
query: any;
}) {
const model = await Model.get(param.modelId);
if (model.project_id && model.project_id !== param.projectId) {
throw new Error('Model not found in project');
throw new Error('Model not belong to project');
}
return model;
}
async dataCount(param: { projectId?: string; modelId: string; query: any }) {
let view: View;
const model = await this.getModelAndValidate(param);
if (param.viewId) {
view = await View.get(param.viewId);
if (view.fk_model_id && view.fk_model_id !== param.modelId) {
throw new Error('View not belong to model');
}
}
return { model, view };
}
async dataCount(param: {
projectId?: string;
viewId?: string;
modelId: string;
query: any;
}) {
const { model, view } = await this.getModelAndView(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
@ -135,6 +164,5 @@ export class DataTableService {
const count: number = await baseModel.count(countArgs);
return { count };
}
}

Loading…
Cancel
Save