mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
11 changed files with 314 additions and 2 deletions
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { BulkDataAliasController } from './bulk-data-alias.controller'; |
||||
|
||||
describe('BulkDataAliasController', () => { |
||||
let controller: BulkDataAliasController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [BulkDataAliasController], |
||||
}).compile(); |
||||
|
||||
controller = module.get<BulkDataAliasController>(BulkDataAliasController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,99 @@
|
||||
import { |
||||
Controller, |
||||
Param, |
||||
Post, |
||||
Request, |
||||
Body, |
||||
Patch, |
||||
Delete, |
||||
} from '@nestjs/common'; |
||||
import { Acl } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; |
||||
import { BulkDataAliasService } from './bulk-data-alias.service'; |
||||
|
||||
@Controller('bulk-data-alias') |
||||
export class BulkDataAliasController { |
||||
constructor(private bulkDataAliasService: BulkDataAliasService) {} |
||||
|
||||
@Post('/api/v1/db/data/bulk/:orgs/:projectName/:tableName') |
||||
@Acl('bulkDataInsert') |
||||
async bulkDataInsert( |
||||
@Request() req, |
||||
@Param('projectName') projectName: string, |
||||
@Param('tableName') tableName: string, |
||||
@Body() body: any, |
||||
) { |
||||
return await this.bulkDataAliasService.bulkDataInsert({ |
||||
body: body, |
||||
cookie: req, |
||||
projectName: projectName, |
||||
tableName: tableName, |
||||
}); |
||||
} |
||||
|
||||
@Patch('/api/v1/db/data/bulk/:orgs/:projectName/:tableName') |
||||
@Acl('bulkDataUpdate') |
||||
async bulkDataUpdate( |
||||
@Request() req, |
||||
@Param('projectName') projectName: string, |
||||
@Param('tableName') tableName: string, |
||||
@Body() body: any, |
||||
) { |
||||
return await this.bulkDataAliasService.bulkDataUpdate({ |
||||
body: body, |
||||
cookie: req, |
||||
projectName: projectName, |
||||
tableName: tableName, |
||||
}); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
||||
@Patch('/api/v1/db/data/bulk/:orgs/:projectName/:tableName/all') |
||||
@Acl('bulkDataUpdateAll') |
||||
async bulkDataUpdateAll( |
||||
@Request() req, |
||||
@Param('projectName') projectName: string, |
||||
@Param('tableName') tableName: string, |
||||
@Body() body: any, |
||||
) { |
||||
return await this.bulkDataAliasService.bulkDataUpdateAll({ |
||||
body: body, |
||||
cookie: req, |
||||
projectName: projectName, |
||||
tableName: tableName, |
||||
query: req.query, |
||||
}); |
||||
} |
||||
|
||||
@Delete('/api/v1/db/data/bulk/:orgs/:projectName/:tableName') |
||||
@Acl('bulkDataDelete') |
||||
async bulkDataDelete( |
||||
@Request() req, |
||||
@Param('projectName') projectName: string, |
||||
@Param('tableName') tableName: string, |
||||
@Body() body: any, |
||||
) { |
||||
return await this.bulkDataAliasService.bulkDataDelete({ |
||||
body: body, |
||||
cookie: req, |
||||
projectName: projectName, |
||||
tableName: tableName, |
||||
}); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataDeleteAll
|
||||
|
||||
@Delete('/api/v1/db/data/bulk/:orgs/:projectName/:tableName/all') |
||||
@Acl('bulkDataDeleteAll') |
||||
async bulkDataDeleteAll( |
||||
@Request() req, |
||||
@Param('projectName') projectName: string, |
||||
@Param('tableName') tableName: string, |
||||
) { |
||||
return await this.bulkDataAliasService.bulkDataDeleteAll({ |
||||
// cookie: req,
|
||||
projectName: projectName, |
||||
tableName: tableName, |
||||
query: req.query, |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { BulkDataAliasService } from './bulk-data-alias.service'; |
||||
|
||||
describe('BulkDataAliasService', () => { |
||||
let service: BulkDataAliasService; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
providers: [BulkDataAliasService], |
||||
}).compile(); |
||||
|
||||
service = module.get<BulkDataAliasService>(BulkDataAliasService); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(service).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,106 @@
|
||||
import { Injectable } from '@nestjs/common'; |
||||
import { BaseModelSqlv2 } from '../../../db/BaseModelSqlv2'; |
||||
import { Base, Model } from '../../../models' |
||||
import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2'; |
||||
import { getViewAndModelByAliasOrId, PathParams } from '../helpers'; |
||||
|
||||
type BulkOperation = |
||||
| 'bulkInsert' |
||||
| 'bulkUpdate' |
||||
| 'bulkUpdateAll' |
||||
| 'bulkDelete' |
||||
| 'bulkDeleteAll'; |
||||
|
||||
@Injectable() |
||||
export class BulkDataAliasService { |
||||
async getModelViewBase(param: PathParams) { |
||||
const { model, view } = await getViewAndModelByAliasOrId(param); |
||||
|
||||
const base = await Base.get(model.base_id); |
||||
return { model, view, base }; |
||||
} |
||||
|
||||
async executeBulkOperation<T extends BulkOperation>( |
||||
param: PathParams & { |
||||
operation: T; |
||||
options: Parameters<(typeof BaseModelSqlv2.prototype)[T]>; |
||||
}, |
||||
) { |
||||
const { model, view, base } = await this.getModelViewBase(param); |
||||
const baseModel = await Model.getBaseModelSQL({ |
||||
id: model.id, |
||||
viewId: view?.id, |
||||
dbDriver: await NcConnectionMgrv2.get(base), |
||||
}); |
||||
return await baseModel[param.operation].apply(null, param.options); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
||||
async bulkDataInsert( |
||||
param: PathParams & { |
||||
body: any; |
||||
cookie: any; |
||||
}, |
||||
) { |
||||
return await this.executeBulkOperation({ |
||||
...param, |
||||
operation: 'bulkInsert', |
||||
options: [param.body, { cookie: param.cookie }], |
||||
}); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
||||
async bulkDataUpdate( |
||||
param: PathParams & { |
||||
body: any; |
||||
cookie: any; |
||||
}, |
||||
) { |
||||
return await this.executeBulkOperation({ |
||||
...param, |
||||
operation: 'bulkUpdate', |
||||
options: [param.body, { cookie: param.cookie }], |
||||
}); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataUpdateAll
|
||||
async bulkDataUpdateAll( |
||||
param: PathParams & { |
||||
body: any; |
||||
cookie: any; |
||||
query: any; |
||||
}, |
||||
) { |
||||
return await this.executeBulkOperation({ |
||||
...param, |
||||
operation: 'bulkUpdateAll', |
||||
options: [param.query, param.body, { cookie: param.cookie }], |
||||
}); |
||||
} |
||||
|
||||
async bulkDataDelete( |
||||
param: PathParams & { |
||||
body: any; |
||||
cookie: any; |
||||
}, |
||||
) { |
||||
return await this.executeBulkOperation({ |
||||
...param, |
||||
operation: 'bulkDelete', |
||||
options: [param.body, { cookie: param.cookie }], |
||||
}); |
||||
} |
||||
|
||||
// todo: Integrate with filterArrJson bulkDataDeleteAll
|
||||
async bulkDataDeleteAll( |
||||
param: PathParams & { |
||||
query: any; |
||||
}, |
||||
) { |
||||
return await this.executeBulkOperation({ |
||||
...param, |
||||
operation: 'bulkDeleteAll', |
||||
options: [param.query], |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { DataAliasExportController } from './data-alias-export.controller'; |
||||
|
||||
describe('DataAliasExportController', () => { |
||||
let controller: DataAliasExportController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [DataAliasExportController], |
||||
}).compile(); |
||||
|
||||
controller = module.get<DataAliasExportController>(DataAliasExportController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common'; |
||||
|
||||
@Controller('data-alias-export') |
||||
export class DataAliasExportController {} |
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { DataAliasNestedController } from './data-alias-nested.controller'; |
||||
|
||||
describe('DataAliasNestedController', () => { |
||||
let controller: DataAliasNestedController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [DataAliasNestedController], |
||||
}).compile(); |
||||
|
||||
controller = module.get<DataAliasNestedController>(DataAliasNestedController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
@ -0,0 +1,4 @@
|
||||
import { Controller } from '@nestjs/common'; |
||||
|
||||
@Controller('data-alias-nested') |
||||
export class DataAliasNestedController {} |
@ -1,9 +1,14 @@
|
||||
import { Module } from '@nestjs/common'; |
||||
import { DatasService } from './datas.service'; |
||||
import { DatasController } from './datas.controller'; |
||||
import { BulkDataAliasController } from './bulk-data-alias/bulk-data-alias.controller'; |
||||
import { DataAliasExportController } from './data-alias-export/data-alias-export.controller'; |
||||
import { DataAliasNestedController } from './data-alias-nested/data-alias-nested.controller'; |
||||
import { OldDatasController } from './old-datas/old-datas.controller'; |
||||
import { BulkDataAliasService } from './bulk-data-alias/bulk-data-alias.service'; |
||||
|
||||
@Module({ |
||||
controllers: [DatasController], |
||||
providers: [DatasService] |
||||
controllers: [DatasController, BulkDataAliasController, DataAliasExportController, DataAliasNestedController, OldDatasController], |
||||
providers: [DatasService, BulkDataAliasService] |
||||
}) |
||||
export class DatasModule {} |
||||
|
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'; |
||||
import { OldDatasController } from './old-datas.controller'; |
||||
|
||||
describe('OldDatasController', () => { |
||||
let controller: OldDatasController; |
||||
|
||||
beforeEach(async () => { |
||||
const module: TestingModule = await Test.createTestingModule({ |
||||
controllers: [OldDatasController], |
||||
}).compile(); |
||||
|
||||
controller = module.get<OldDatasController>(OldDatasController); |
||||
}); |
||||
|
||||
it('should be defined', () => { |
||||
expect(controller).toBeDefined(); |
||||
}); |
||||
}); |
Loading…
Reference in new issue